From 0c8133c6d5b33ace651bb7de5ac8e1090f5d9f5c Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 10 Dec 2020 08:30:54 -0500 Subject: [PATCH] Pokemon Held Item Data --- assets/json/missingno.json | 1 + commands/search/pokedex.js | 3 ++- package.json | 2 +- structures/pokemon/Pokemon.js | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/assets/json/missingno.json b/assets/json/missingno.json index 8725ee1b..b57fa631 100644 --- a/assets/json/missingno.json +++ b/assets/json/missingno.json @@ -31,6 +31,7 @@ "genus": "??? Pokémon" } ], + "held_items": [], "varieties": [ { "is_default": true, diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index a3345511..91bce186 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -122,6 +122,7 @@ module.exports = class PokedexCommand extends Command { const showParens = variety.name && abilitiesShown.length > 1; return `${variety.abilities.join('/')}${showParens ? ` (${variety.name})` : ''}`; }).join('\n')) + .addField('❯ Held Items', data.heldItems.length ? data.heldItems.map(item => item.name).join('/') : 'None') .addField('❯ Gender Rate', data.genderRate.genderless ? 'Genderless' : `♂️ ${data.genderRate.male}% ♀️ ${data.genderRate.female}%`); if (data.cry) { @@ -134,8 +135,8 @@ module.exports = class PokedexCommand extends Command { } else { const usage = this.client.registry.commands.get('join').usage(); 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. + Join a voice channel and use ${usage} to hear the Pokémon's cry. `); } } diff --git a/package.json b/package.json index 8d02d4ae..fc247805 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "123.4.1", + "version": "123.4.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index ccea61fc..cfc830be 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -28,6 +28,16 @@ module.exports = class Pokemon { this.legendary = data.is_legendary; this.mythical = data.is_mythical; this.baby = data.is_baby; + this.heldItems = data.held_items + .filter(item => item.version_details.some(version => { + const inSwordShield = version.version.name === 'sword' || version.version.name === 'shield'; + if (inSwordShield) return true; + if (!inSwordShield && (version.version.name === 'ultra-sun' || version.version.name === 'ultra-moon')) { + return true; + } + return false; + })) + .map(item => ({ url: item.item.url, name: null })); this.varieties = data.varieties.map(variety => { const name = firstUpperCase(variety.pokemon.name .replace(new RegExp(`${this.slug}-?`, 'i'), '') @@ -135,6 +145,7 @@ module.exports = class Pokemon { } this.height = defaultBody.height * 3.94; this.weight = defaultBody.weight * 0.2205; + await this.fetchHeldItemNames(); await this.fetchChain(); this.gameDataCached = true; return this; @@ -165,4 +176,12 @@ module.exports = class Pokemon { } return this.chain.data; } + + async fetchHeldItemNames() { + for (const item of this.heldItems) { + const { body } = await request.get(item.url); + item.name = body.names.find(name => name.language.name === 'en').name; + } + return this.heldItems; + } };