From 4df75d669a6db3fc13c916fe5f53e05150cb0baf Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 26 Nov 2020 08:40:44 -0500 Subject: [PATCH] Support More Pokemon --- commands/games-sp/whos-that-pokemon-cry.js | 5 ++--- commands/games-sp/whos-that-pokemon.js | 8 +++----- commands/search/pokedex.js | 16 +++++++++------- package.json | 2 +- structures/pokemon/Pokemon.js | 6 ++++-- structures/pokemon/PokemonStore.js | 7 +++++++ 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/commands/games-sp/whos-that-pokemon-cry.js b/commands/games-sp/whos-that-pokemon-cry.js index ac419d46..baadac3d 100644 --- a/commands/games-sp/whos-that-pokemon-cry.js +++ b/commands/games-sp/whos-that-pokemon-cry.js @@ -1,6 +1,5 @@ const Command = require('../../structures/Command'); const { reactIfAble } = require('../../util/Util'); -const pokemonCount = 893; module.exports = class WhosThatPokemonCryCommand extends Command { constructor(client) { @@ -70,9 +69,9 @@ module.exports = class WhosThatPokemonCryCommand extends Command { key: 'pokemon', prompt: 'What Pokémon do you want to use?', type: 'integer', - max: pokemonCount, + max: client.pokemon.pokemonCountWithCry, min: 0, - default: () => Math.floor(Math.random() * (pokemonCount + 1)) + default: () => Math.floor(Math.random() * (client.pokemon.pokemonCountWithCry + 1)) } ] }); diff --git a/commands/games-sp/whos-that-pokemon.js b/commands/games-sp/whos-that-pokemon.js index 1e7a464a..491dd023 100644 --- a/commands/games-sp/whos-that-pokemon.js +++ b/commands/games-sp/whos-that-pokemon.js @@ -5,7 +5,6 @@ const { reactIfAble } = require('../../util/Util'); const { silhouette } = require('../../util/Canvas'); const path = require('path'); registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Pokemon Solid.ttf'), { family: 'Pokemon' }); -const pokemonCount = 893; module.exports = class WhosThatPokemonCommand extends Command { constructor(client) { @@ -73,9 +72,9 @@ module.exports = class WhosThatPokemonCommand extends Command { key: 'pokemon', prompt: 'What Pokémon do you want to use?', type: 'integer', - max: pokemonCount, + max: client.pokemon.pokemonCount, min: 0, - default: () => Math.floor(Math.random() * (pokemonCount + 1)) + default: () => Math.floor(Math.random() * (client.pokemon.pokemonCount + 1)) } ] }); @@ -100,10 +99,9 @@ module.exports = class WhosThatPokemonCommand extends Command { max: 1, time: 15000 }); - if (connection) { + if (connection && data.cry) { if (connection.dispatcher) connection.dispatcher.end(); connection.play(data.cry); - await reactIfAble(msg, this.client.user, '🔉'); } this.client.games.delete(msg.channel.id); if (!msgs.size) return msg.reply(`Time! It's **${data.name}**!`, { files: [answerAttachment] }); diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index 1b1a38b7..42c004d5 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -88,13 +88,15 @@ module.exports = class PokedexCommand extends Command { if (found.id === data.id) return `**${found.name}**`; return found.name; }).join(' -> ')); - const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null; - if (connection) { - connection.play(data.cry); - await reactIfAble(msg, this.client.user, '🔉'); - } else { - const usage = this.client.registry.commands.get('join').usage(); - embed.setFooter(`Join a voice channel and use ${usage} to hear the Pokémon's cry.`); + if (data.cry) { + const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null; + if (connection) { + connection.play(data.cry); + await reactIfAble(msg, this.client.user, '🔉'); + } else { + const usage = this.client.registry.commands.get('join').usage(); + embed.setFooter(`Join a voice channel and use ${usage} to hear the Pokémon's cry.`); + } } return msg.embed(embed); } catch (err) { diff --git a/package.json b/package.json index f272f2b9..04760a2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "121.2.1", + "version": "121.2.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index 4d54ea6e..c4fdb86b 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -19,7 +19,7 @@ module.exports = class Pokemon { : [{ name: slugName, language: 'en' }]; this.genus = data.genera.length ? `The ${data.genera.filter(entry => entry.language.name === 'en')[0].genus}` - : 'Galar Native'; + : 'Undiscovered Pokémon'; this.varieties = data.varieties.map(variety => { const name = firstUpperCase(variety.pokemon.name .replace(new RegExp(`${this.slug}-?`, 'i'), '') @@ -38,7 +38,9 @@ module.exports = class Pokemon { }; this.typesCached = data.missingno || false; this.missingno = data.missingno || false; - this.cry = path.join(__dirname, '..', '..', 'assets', 'sounds', 'pokedex', `${data.id}.wav`); + this.cry = data.id > store.pokemonCountWithCry + ? null + : path.join(__dirname, '..', '..', 'assets', 'sounds', 'pokedex', `${data.id}.wav`); } get displayID() { diff --git a/structures/pokemon/PokemonStore.js b/structures/pokemon/PokemonStore.js index 5fffe8de..6eba70aa 100644 --- a/structures/pokemon/PokemonStore.js +++ b/structures/pokemon/PokemonStore.js @@ -4,6 +4,13 @@ const Pokemon = require('./Pokemon'); const missingno = require('../../assets/json/missingno'); module.exports = class PokemonStore extends Collection { + constructor(options) { + super(options); + + this.pokemonCount = 897; + this.pokemonCountWithCry = 893; + } + async fetch(query) { query = this.makeSlug(query); if (!query) return null;