This commit is contained in:
Daniel Odendahl Jr
2018-04-17 13:13:07 +00:00
parent 4e121af3e3
commit 13a2ea85c0
3 changed files with 9 additions and 11 deletions
+8 -4
View File
@@ -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];
}
};