mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add Base Stats to Pokemon Data
This commit is contained in:
@@ -56,6 +56,14 @@
|
||||
"evolution_chain": {
|
||||
"url": null
|
||||
},
|
||||
"stats": {
|
||||
"hp": 33,
|
||||
"atk": 136,
|
||||
"def": 0,
|
||||
"sAtk": 6,
|
||||
"sDef": 6,
|
||||
"spd": 29
|
||||
},
|
||||
"chain": [0],
|
||||
"missingno": true,
|
||||
"sprite": "https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png",
|
||||
|
||||
@@ -61,9 +61,17 @@ module.exports = class PokedexCommand extends Command {
|
||||
try {
|
||||
const data = await this.client.pokemon.fetch(pokemon);
|
||||
if (!data) return msg.say('Could not find any results.');
|
||||
if (!data.typesCached) await data.fetchTypes();
|
||||
if (!data.gameDataCached) await data.fetchGameData();
|
||||
if (!data.chain.data.length) await data.fetchChain();
|
||||
const typesShown = data.varieties.filter(variety => variety.display);
|
||||
const repeat = {
|
||||
hp: Math.round((data.stats.hp / 255) * 5),
|
||||
atk: Math.round((data.stats.atk / 255) * 5),
|
||||
def: Math.round((data.stats.def / 255) * 5),
|
||||
sAtk: Math.round((data.stats.sAtk / 255) * 5),
|
||||
sDef: Math.round((data.stats.sDef / 255) * 5),
|
||||
spd: Math.round((data.stats.spd / 255) * 5)
|
||||
};
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xED1C24)
|
||||
.setAuthor(`#${data.displayID} - ${data.name}`, data.boxImageURL, data.serebiiURL)
|
||||
@@ -87,7 +95,15 @@ module.exports = class PokedexCommand extends Command {
|
||||
const found = this.client.pokemon.get(pkmn);
|
||||
if (found.id === data.id) return `**${found.name}**`;
|
||||
return found.name;
|
||||
}).join(' -> '));
|
||||
}).join(' -> '))
|
||||
.addField('❯ Base Stats (Base Form)', stripIndents`
|
||||
\`HP: [${'█'.repeat(repeat.hp)}${' '.repeat(20 - repeat.hp)}]\` **${data.stats.hp}**
|
||||
\`Attack: [${'█'.repeat(repeat.atk)}${' '.repeat(20 - repeat.atk)}]\` **${data.stats.atk}**
|
||||
\`Defense: [${'█'.repeat(repeat.def)}${' '.repeat(20 - repeat.def)}]\` **${data.stats.def}**
|
||||
\`Sp. Attack: [${'█'.repeat(repeat.sAtk)}${' '.repeat(20 - repeat.sAtk)}]\` **${data.stats.sAtk}**
|
||||
\`Sp. Defense: [${'█'.repeat(repeat.sDef)}${' '.repeat(20 - repeat.sDef)}]\` **${data.stats.sDef}**
|
||||
\`Speed: [${'█'.repeat(repeat.spd)}${' '.repeat(20 - repeat.spd)}]\` **${data.stats.spd}**
|
||||
`);
|
||||
if (data.cry) {
|
||||
const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null;
|
||||
if (connection) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "123.2.0",
|
||||
"version": "123.2.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -36,7 +36,8 @@ module.exports = class Pokemon {
|
||||
url: data.evolution_chain ? data.evolution_chain.url : null,
|
||||
data: data.missingno ? missingno.chain : data.evolution_chain ? [] : [data.id]
|
||||
};
|
||||
this.typesCached = data.missingno || false;
|
||||
this.stats = data.missingno.stats || null;
|
||||
this.gameDataCached = data.missingno || false;
|
||||
this.missingno = data.missingno || false;
|
||||
this.cry = data.id > store.pokemonCountWithCry
|
||||
? null
|
||||
@@ -67,12 +68,20 @@ module.exports = class Pokemon {
|
||||
return `https://www.serebii.net/pokedex-swsh/${this.displayID}.shtml`;
|
||||
}
|
||||
|
||||
async fetchTypes() {
|
||||
if (this.typesCached) return this;
|
||||
async fetchGameData() {
|
||||
if (this.gameDataCached) return this;
|
||||
const defaultVariety = this.varieties.find(variety => variety.default);
|
||||
const { body: defaultBody } = await request.get(`https://pokeapi.co/api/v2/pokemon/${defaultVariety.id}`);
|
||||
defaultVariety.types.push(...defaultBody.types.map(type => firstUpperCase(type.type.name)));
|
||||
defaultVariety.display = true;
|
||||
this.stats = {
|
||||
hp: defaultBody.stats.find(stat => stat.stat.name === 'hp').base_stat,
|
||||
atk: defaultBody.stats.find(stat => stat.stat.name === 'attack').base_stat,
|
||||
def: defaultBody.stats.find(stat => stat.stat.name === 'defense').base_stat,
|
||||
sAtk: defaultBody.stats.find(stat => stat.stat.name === 'special-attack').base_stat,
|
||||
sDef: defaultBody.stats.find(stat => stat.stat.name === 'special-defense').base_stat,
|
||||
spd: defaultBody.stats.find(stat => stat.stat.name === 'speed').base_stat
|
||||
};
|
||||
for (const variety of this.varieties) {
|
||||
if (variety.id === defaultVariety.id) continue;
|
||||
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`);
|
||||
@@ -83,7 +92,7 @@ module.exports = class Pokemon {
|
||||
variety.display = true;
|
||||
}
|
||||
}
|
||||
this.typesCached = true;
|
||||
this.gameDataCached = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user