mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +02:00
Clean-up
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const { createCanvas, loadImage } = require('canvas');
|
const { createCanvas, loadImage } = require('canvas');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
const { filterPkmn } = require('../../util/Util');
|
|
||||||
const { silhouette } = require('../../util/Canvas');
|
const { silhouette } = require('../../util/Canvas');
|
||||||
|
|
||||||
module.exports = class WhosThatPokemonCommand extends Command {
|
module.exports = class WhosThatPokemonCommand extends Command {
|
||||||
@@ -35,7 +34,7 @@ module.exports = class WhosThatPokemonCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const data = await this.fetchPokemon(pokemon);
|
const data = await this.fetchPokemon(pokemon);
|
||||||
const names = data.names.map(name => name.name.toLowerCase());
|
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 id = data.id.toString().padStart(3, '0');
|
||||||
const attachment = await this.fetchImage(id, hide);
|
const attachment = await this.fetchImage(id, hide);
|
||||||
await msg.say('**You have 15 seconds, who\'s that Pokémon?**', { files: [{ attachment, name: `${id}.png` }] });
|
await msg.say('**You have 15 seconds, who\'s that Pokémon?**', { files: [{ attachment, name: `${id}.png` }] });
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const { Command } = require('discord.js-commando');
|
|||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
const { filterPkmn } = require('../../util/Util');
|
|
||||||
|
|
||||||
module.exports = class PokedexCommand extends Command {
|
module.exports = class PokedexCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -31,13 +30,13 @@ module.exports = class PokedexCommand extends Command {
|
|||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor(0xED1C24)
|
.setColor(0xED1C24)
|
||||||
.setAuthor(
|
.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/icon/${id}.png`,
|
||||||
`https://www.serebii.net/pokedex-sm/${id}.shtml`
|
`https://www.serebii.net/pokedex-sm/${id}.shtml`
|
||||||
)
|
)
|
||||||
.setDescription(stripIndents`
|
.setDescription(stripIndents`
|
||||||
**The ${filterPkmn(body.genera).genus}**
|
**The ${this.filterPokemonData(body.genera, false).genus}**
|
||||||
${filterPkmn(body.flavor_text_entries).flavor_text.replace(/\n|\f|\r/g, ' ')}
|
${this.filterPokemonData(body.flavor_text_entries).flavor_text.replace(/\n|\f|\r/g, ' ')}
|
||||||
`)
|
`)
|
||||||
.setThumbnail(`https://www.serebii.net/sunmoon/pokemon/${id}.png`);
|
.setThumbnail(`https://www.serebii.net/sunmoon/pokemon/${id}.png`);
|
||||||
return msg.embed(embed);
|
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!`);
|
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];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ class Util {
|
|||||||
return text.length > maxLen ? `${text.substr(0, maxLen - 3)}...` : text;
|
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) {
|
static duration(ms) {
|
||||||
const sec = Math.floor((ms / 1000) % 60).toString();
|
const sec = Math.floor((ms / 1000) % 60).toString();
|
||||||
const min = Math.floor((ms / (1000 * 60)) % 60).toString();
|
const min = Math.floor((ms / (1000 * 60)) % 60).toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user