diff --git a/commands/pokedex/pokedex-stats.js b/commands/pokedex/pokedex-stats.js index 2d2b2a71..15ab13ed 100644 --- a/commands/pokedex/pokedex-stats.js +++ b/commands/pokedex/pokedex-stats.js @@ -2,8 +2,14 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); const { list } = require('../../util/Util'); +const genGames = [null, 'rb', 'gs', 'rs', 'dp', 'bw', 'xy', 'sm', 'ss']; const games = { rb: 'Red/Blue', + gs: 'Gold/Silver', + rs: 'Ruby/Sapphire', + dp: 'Diamond/Pearl', + bw: 'Black/White', + xy: 'X/Y', sm: 'Sun/Moon', ss: 'Sword/Shield' }; @@ -59,8 +65,8 @@ module.exports = class PokedexCommand extends Command { 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 game = data.missingno ? 'rb' : data.id > 807 ? 'ss' : 'sm'; - if (!data.smogonTiers[game]) await data.fetchSmogonTiers(game); + const fetchGames = genGames.slice(data.missingno ? 0 : data.generation, data.missingno ? 1 : genGames.length); + if (!data.missingno) await data.fetchSmogonTiers(fetchGames); const displayForms = data.varieties.filter(vrity => vrity.statsDiffer); const variety = displayForms.find(vrity => { if (!form || form === 'normal') return vrity.default; @@ -96,7 +102,11 @@ module.exports = class PokedexCommand extends Command { \`Total: [${'█'.repeat(repeat.total)}${' '.repeat(20 - repeat.total)}]\` **${statTotal}** `) .addField('❯ Abilities', variety.abilities.join('/')) - .addField('❯ Smogon Tiers', `[${data.smogonTiers[game].join('/')}](${data.smogonURL}) (${games[game]})`) + .addField('❯ Smogon Tiers', + games.map(game => { + const smogonData = data.smogonTiers[game]; + return `[${smogonData.join('/')}](${data.smogonURL(game)}) (${games[game]})`; + }).join('\n')) .addField('❯ Other Forms', stripIndents` _Use ${this.usage(`${data.id}
`)} to get stats for another form._ diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index 537fd0b0..51a6bd12 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -77,6 +77,19 @@ module.exports = class Pokemon { return true; } + get generation() { + if (this.id < 898) return null; + if (this.id >= 810) return 8; + if (this.id >= 722) return 7; + if (this.id >= 650) return 6; + if (this.id >= 494) return 5; + if (this.id >= 387) return 4; + if (this.id >= 252) return 3; + if (this.id >= 152) return 2; + if (this.id >= 1) return 1; + return 0; + } + get class() { if (this.legendary) return 'legendary'; if (this.mythical) return 'mythical'; @@ -138,16 +151,18 @@ module.exports = class Pokemon { return `https://www.serebii.net/pokedex-swsh/${this.displayID}.shtml`; } - get smogonURL() { + smogonURL(gen) { if (this.missingno) return missingno.url; - return `https://www.smogon.com/dex/${this.id > 807 ? 'ss' : 'sm'}/pokemon/${this.slug}/`; + return `https://www.smogon.com/dex/${gen.toLowerCase()}/pokemon/${this.slug}/`; } - async fetchSmogonTiers(gen) { - if (!this.store.smogonData[gen.toLowerCase()]) await this.store.fetchSmogonData(gen.toLowerCase()); - const pkmn = this.store.smogonData[gen.toLowerCase()].find(data => data.id === this.id); - this.smogonTiers[gen.toLowerCase()] = pkmn.formats; - return this.smogonTiers[gen.toLowerCase()]; + async fetchSmogonTiers(...gens) { + for (const gen of gens) { + if (!this.store.smogonData[gen.toLowerCase()]) await this.store.fetchSmogonData(gen.toLowerCase()); + const pkmn = this.store.smogonData[gen.toLowerCase()].find(data => data.id === this.id); + this.smogonTiers[gen.toLowerCase()] = pkmn.formats; + } + return this.smogonTiers; } async fetchGameData() { diff --git a/structures/pokemon/PokemonStore.js b/structures/pokemon/PokemonStore.js index e2a53366..99c04495 100644 --- a/structures/pokemon/PokemonStore.js +++ b/structures/pokemon/PokemonStore.js @@ -41,6 +41,7 @@ module.exports = class PokemonStore extends Collection { this.smogonData[gen.toLowerCase()] = JSON.parse(text.match(/dexSettings = ({.+})/i)[1]) .injectRpcs[1][1] .pokemon + .filter(pkmn => pkmn.oob) .map(pkmn => ({ id: pkmn.oob.dex_number, formats: pkmn.formats })); return this.smogonData[gen.toLowerCase()]; }