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
+1 -2
View File
@@ -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` }] });
+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];
}
};
-5
View File
@@ -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();