From 13a2ea85c065215a50c87362f310c7618d25f730 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 17 Apr 2018 13:13:07 +0000 Subject: [PATCH] Clean-up --- commands/games/whos-that-pokemon.js | 3 +-- commands/search/pokedex.js | 12 ++++++++---- util/Util.js | 5 ----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/commands/games/whos-that-pokemon.js b/commands/games/whos-that-pokemon.js index fa3d3bee..0bf2804c 100644 --- a/commands/games/whos-that-pokemon.js +++ b/commands/games/whos-that-pokemon.js @@ -1,7 +1,6 @@ const { Command } = require('discord.js-commando'); const { createCanvas, loadImage } = require('canvas'); const snekfetch = require('snekfetch'); -const { filterPkmn } = require('../../util/Util'); const { silhouette } = require('../../util/Canvas'); module.exports = class WhosThatPokemonCommand extends Command { @@ -35,7 +34,7 @@ module.exports = class WhosThatPokemonCommand extends Command { try { const data = await this.fetchPokemon(pokemon); const names = data.names.map(name => name.name.toLowerCase()); - const displayName = filterPkmn(data.names).name; + const displayName = data.names.filter(name => name.language.name === 'en')[0].name; const id = data.id.toString().padStart(3, '0'); const attachment = await this.fetchImage(id, hide); await msg.say('**You have 15 seconds, who\'s that Pokémon?**', { files: [{ attachment, name: `${id}.png` }] }); diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index ffd558c1..31d714d8 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -2,7 +2,6 @@ const { Command } = require('discord.js-commando'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { stripIndents } = require('common-tags'); -const { filterPkmn } = require('../../util/Util'); module.exports = class PokedexCommand extends Command { constructor(client) { @@ -31,13 +30,13 @@ module.exports = class PokedexCommand extends Command { const embed = new MessageEmbed() .setColor(0xED1C24) .setAuthor( - `#${id} - ${filterPkmn(body.names).name}`, + `#${id} - ${this.filterPokemonData(body.names, false).name}`, `https://www.serebii.net/pokedex-sm/icon/${id}.png`, `https://www.serebii.net/pokedex-sm/${id}.shtml` ) .setDescription(stripIndents` - **The ${filterPkmn(body.genera).genus}** - ${filterPkmn(body.flavor_text_entries).flavor_text.replace(/\n|\f|\r/g, ' ')} + **The ${this.filterPokemonData(body.genera, false).genus}** + ${this.filterPokemonData(body.flavor_text_entries).flavor_text.replace(/\n|\f|\r/g, ' ')} `) .setThumbnail(`https://www.serebii.net/sunmoon/pokemon/${id}.png`); return msg.embed(embed); @@ -46,4 +45,9 @@ module.exports = class PokedexCommand extends Command { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } + + filterPokemonData(arr, random = true) { + const filtered = arr.filter(entry => entry.language.name === 'en'); + return filtered[random ? Math.floor(Math.random() * filtered.length) : 0]; + } }; diff --git a/util/Util.js b/util/Util.js index 4a5178a8..942f1554 100644 --- a/util/Util.js +++ b/util/Util.js @@ -29,11 +29,6 @@ class Util { return text.length > maxLen ? `${text.substr(0, maxLen - 3)}...` : text; } - static filterPkmn(arr) { - const filtered = arr.filter(entry => entry.language.name === 'en'); - return filtered[Math.floor(Math.random() * filtered.length)]; - } - static duration(ms) { const sec = Math.floor((ms / 1000) % 60).toString(); const min = Math.floor((ms / (1000 * 60)) % 60).toString();