This commit is contained in:
Dragon Fire
2021-01-20 18:24:05 -05:00
parent dd29572bb1
commit 2be66ffb63
3 changed files with 36 additions and 10 deletions
+13 -3
View File
@@ -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} <form>`)} to get stats for another form._
+22 -7
View File
@@ -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() {
+1
View File
@@ -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()];
}