From 0fd1e26ac9d9dba7ad68cbe109a4229f5467d50b Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 9 Dec 2020 17:10:42 -0500 Subject: [PATCH] Pokemon Moveset Command --- README.md | 6 ++- assets/json/missingno.json | 14 +++++++ commands/search/pokedex-moveset.js | 66 ++++++++++++++++++++++++++++++ commands/search/pokedex.js | 7 +++- package.json | 2 +- structures/pokemon/Pokemon.js | 9 ++++ 6 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 commands/search/pokedex-moveset.js diff --git a/README.md b/README.md index 128a36c2..98b9c351 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 568 +Total: 569 ### Utility: @@ -503,6 +503,7 @@ Total: 568 * **paladins:** Responds with information on a Paladins player. * **periodic-table:** Finds an element on the periodic table. * **poem:** Searches for poems by a specific author. +* **pokedex-moveset:** Responds with the moveset for a Pokémon. * **pokedex:** Searches the Pokédex for a Pokémon. * **pornhub:** Searches Pornhub for your query. (NSFW) * **recipe:** Searches for recipes based on your query. @@ -1544,6 +1545,7 @@ here. - [Pokemon Fusion](https://pokemon.alexonsager.net/) * pokemon-fusion (Images) - [PokéAPI](https://pokeapi.co/) + * pokemon-moveset (API) * pokedex (API) * pokemon-cry (API) * whos-that-pokemon (API) @@ -1552,6 +1554,7 @@ here. * 3000-years (Image, Original Game) * dexter (Image, Original Anime) * hat (Ash Hat Original Anime) + * pokedex-moveset (Images, Original Game) * pokedex (Images, Original Game) * pokemon-cry (Original Game) * pokemon-fusion (Original Game) @@ -1628,6 +1631,7 @@ here. - [SEGA](https://www.sega.com/) * sonic-says ([Image, Original "Sonic the Hedgehog" Game](https://www.sonicthehedgehog.com/)) - [Serebii.net](https://www.serebii.net/index2.shtml) + * pokedex-moveset (Images) * pokedex (Images) * whos-that-pokemon (Images) * whos-that-pokemon-cry (Images) diff --git a/assets/json/missingno.json b/assets/json/missingno.json index bad51f11..69b5f8d1 100644 --- a/assets/json/missingno.json +++ b/assets/json/missingno.json @@ -72,6 +72,20 @@ }, "height": 120, "weight": 3507.2, + "moveSet": [ + { + "name": "Water Gun", + "level": 1 + }, + { + "name": "Water Gun", + "level": 1 + }, + { + "name": "Sky Attack", + "level": 1 + } + ], "chain": [0], "missingno": true, "sprite": "https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png", diff --git a/commands/search/pokedex-moveset.js b/commands/search/pokedex-moveset.js new file mode 100644 index 00000000..a93eb53e --- /dev/null +++ b/commands/search/pokedex-moveset.js @@ -0,0 +1,66 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); + +module.exports = class PokedexMovesetCommand extends Command { + constructor(client) { + super(client, { + name: 'pokedex-moveset', + aliases: [ + 'pokemon-moveset', + 'pokémon-moveset', + 'pokédex-moveset', + 'pkmn-moveset', + 'pokedex-moves', + 'pokémon-moves', + 'pokemon-moves', + 'pokédex-moves', + 'pkmn-moves' + ], + group: 'search', + memberName: 'pokedex-moveset', + description: 'Responds with the moveset for a Pokémon.', + clientPermissions: ['EMBED_LINKS'], + credit: [ + { + name: 'Pokémon', + url: 'https://www.pokemon.com/us/', + reason: 'Images, Original Game' + }, + { + name: 'PokéAPI', + url: 'https://pokeapi.co/', + reason: 'API' + }, + { + name: 'Serebii.net', + url: 'https://www.serebii.net/index2.shtml', + reason: 'Images' + } + ], + args: [ + { + key: 'pokemon', + prompt: 'What Pokémon would you like to get information on?', + type: 'string' + } + ] + }); + } + + async run(msg, { pokemon }) { + try { + const data = await this.client.pokemon.fetch(pokemon); + if (!data) return msg.say('Could not find any results.'); + if (!data.gameDataCached) await data.fetchGameData(); + const embed = new MessageEmbed() + .setColor(0xED1C24) + .setAuthor(`#${data.displayID} - ${data.name}`, data.boxImageURL, data.serebiiURL) + .setDescription(data.moveSet.map(move => `**Level ${move.level}:** ${move.name}`).join('\n')) + .setThumbnail(data.spriteImageURL); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index bd1f4671..f29141ff 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -126,12 +126,17 @@ module.exports = class PokedexCommand extends Command { data.genderRate.genderless ? 'Genderless' : `♂️ ${data.genderRate.male}% ♀️ ${data.genderRate.female}%`); if (data.cry) { const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null; + const moveUsage = this.client.registry.commands.get('pokedex-moveset').usage(); if (connection) { + embed.setFooter(`Use ${moveUsage} to get the Pokémon's moveset.`); 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.`); + embed.setFooter(stripIndents` + Join a voice channel and use ${usage} to hear the Pokémon's cry. + Use ${moveUsage} to get the Pokémon's moveset. + `); } } return msg.embed(embed); diff --git a/package.json b/package.json index cffe5c79..10d4afd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "123.3.2", + "version": "123.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index 14359600..954fccd4 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -47,6 +47,7 @@ module.exports = class Pokemon { this.stats = data.missingno ? data.stats : null; this.height = data.missingno ? data.height : null; this.weight = data.missingno ? data.weight : null; + this.moveSet = data.missingno ? data.moveSet : []; this.gameDataCached = data.missingno || false; this.missingno = data.missingno || false; this.cry = data.id > store.pokemonCountWithCry @@ -109,6 +110,14 @@ module.exports = class Pokemon { sDef: defaultBody.stats.find(stat => stat.stat.name === 'special-defense').base_stat, spd: defaultBody.stats.find(stat => stat.stat.name === 'speed').base_stat }; + for (const move of defaultBody.moves) { + if (!move.version_group_details.some(mve => mve.move_learn_method.name === 'level-up')) continue; + const { body: moveBody } = await request.get(move.url); + this.moveSet.push({ + name: moveBody.names.find(name => name.language.name === 'en').name, + level: move.version_group_details[move.version_group_details.length - 1].level_learned_at + }); + } for (const variety of this.varieties) { if (variety.id === defaultVariety.id) continue; const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`);