mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-19 21:40:51 +02:00
Add Smogon Tiers to pokedex-stats
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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, ''));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user