Add Smogon Tiers to pokedex-stats

This commit is contained in:
Dragon Fire
2021-01-20 17:37:31 -05:00
parent e4073837b8
commit 1dca3ae20b
4 changed files with 27 additions and 1 deletions
+3
View File
@@ -54,6 +54,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.id > 807 ? 'ss' : 'sm';
if (!data.smogonTiers[game]) await data.fetchSmogonTiers(game);
const displayForms = data.varieties.filter(vrity => vrity.statsDiffer);
const variety = displayForms.find(vrity => {
if (!form || form === 'normal') return vrity.default;
@@ -89,6 +91,7 @@ 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})`)
.addField(' Other Forms', stripIndents`
_Use ${this.usage(`${data.id} <form>`)} to get stats for another form._
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "126.8.1",
"version": "126.8.2",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+13
View File
@@ -60,6 +60,7 @@ module.exports = class Pokemon {
this.cry = data.id > store.pokemonCountWithCry
? null
: path.join(__dirname, '..', '..', 'assets', 'sounds', 'pokedex', `${data.id}.wav`);
this.smogonTiers = data.missingno ? data.smogonTiers : {};
}
baseStatTotal(variety) {
@@ -137,6 +138,18 @@ module.exports = class Pokemon {
return `https://www.serebii.net/pokedex-swsh/${this.displayID}.shtml`;
}
get smogonURL() {
if (this.missingno) return null;
return `https://www.smogon.com/dex/${this.id > 807 ? 'ss' : 'sm'}/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(pkmn => pkmn.id === this.id);
this.smogonTiers[gen.toLowerCase()] = pkmn.formats;
return this.smogonTiers[gen.toLowerCase()];
}
async fetchGameData() {
if (this.gameDataCached) return this;
await this.fetchDefaultVariety();
+10
View File
@@ -9,6 +9,7 @@ module.exports = class PokemonStore extends Collection {
this.pokemonCount = 898;
this.pokemonCountWithCry = 893;
this.smogonData = {};
}
async fetch(query) {
@@ -34,6 +35,15 @@ module.exports = class PokemonStore extends Collection {
}
}
async fetchSmogonData(gen) {
if (this.smogonData[gen.toLowerCase()]) return this.smogonData[gen.toLowerCase()];
const { text } = await request.get(`https://www.smogon.com/dex/${gen}/pokemon/`);
this.smogonData[gen.toLowerCase()] = JSON.parse(text.match(/dexSettings = ({.+})/i)[1])
.injectRpcs[1][1]
.pokemon
.map(pkmn => ({ id: pkmn.oob.dex_number, formats: pkmn.formats }));
}
makeSlug(query) {
return encodeURIComponent(query.toLowerCase().replaceAll(' ', '-').replace(/[^a-zA-Z0-9-]/g, ''));
}