Show abilities of all forms

This commit is contained in:
Dragon Fire
2020-12-03 13:06:26 -05:00
parent 091e5da53e
commit 299ed8cd5f
5 changed files with 28 additions and 18 deletions
+4 -3
View File
@@ -40,7 +40,8 @@
"types": [ "types": [
"Bird", "Bird",
"Normal" "Normal"
] ],
"abilities": ["N/A"]
}, },
{ {
"is_default": false, "is_default": false,
@@ -50,7 +51,8 @@
"types": [ "types": [
"Normal", "Normal",
"999" "999"
] ],
"abilities": ["N/A"]
} }
], ],
"evolution_chain": { "evolution_chain": {
@@ -70,7 +72,6 @@
}, },
"height": 120, "height": 120,
"weight": 3507.2, "weight": 3507.2,
"abilities": ["N/A"],
"chain": [0], "chain": [0],
"missingno": true, "missingno": true,
"sprite": "https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png", "sprite": "https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png",
+14 -3
View File
@@ -1,7 +1,7 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const { firstUpperCase, reactIfAble } = require('../../util/Util'); const { arrayEquals, firstUpperCase, reactIfAble } = require('../../util/Util');
module.exports = class PokedexCommand extends Command { module.exports = class PokedexCommand extends Command {
constructor(client) { constructor(client) {
@@ -62,7 +62,15 @@ module.exports = class PokedexCommand extends Command {
const data = await this.client.pokemon.fetch(pokemon); const data = await this.client.pokemon.fetch(pokemon);
if (!data) return msg.say('Could not find any results.'); if (!data) return msg.say('Could not find any results.');
if (!data.gameDataCached) await data.fetchGameData(); if (!data.gameDataCached) await data.fetchGameData();
const typesShown = data.varieties.filter(variety => variety.display); const defaultVariety = data.varieties.find(variety => variety.default);
const typesShown = data.varieties.filter(variety => {
if (variety.default) return true;
return !arrayEquals(defaultVariety.types, variety.types);
});
const abilitiesShown = data.varieties.filter(variety => {
if (variety.default) return true;
return !arrayEquals(defaultVariety.abilities, variety.abilities);
});
const repeat = { const repeat = {
hp: Math.round((data.stats.hp / 255) * 10) * 2, hp: Math.round((data.stats.hp / 255) * 10) * 2,
atk: Math.round((data.stats.atk / 255) * 10) * 2, atk: Math.round((data.stats.atk / 255) * 10) * 2,
@@ -110,7 +118,10 @@ module.exports = class PokedexCommand extends Command {
\`-----------------------------------\` \`-----------------------------------\`
\`Total: [${'█'.repeat(repeat.total)}${' '.repeat(20 - repeat.total)}]\` **${data.baseStatTotal}** \`Total: [${'█'.repeat(repeat.total)}${' '.repeat(20 - repeat.total)}]\` **${data.baseStatTotal}**
`) `)
.addField(' Abilities', data.abilities.join(' / ')) .addField(' Abilities', abilitiesShown.map(variety => {
const showParens = variety.name && abilitiesShown.length > 1;
return `${variety.abilities.join('/')}${showParens ? ` (${variety.name})` : ''}`;
}).join('\n'))
.addField(' Gender Rate', .addField(' Gender Rate',
data.genderRate.genderless ? 'Genderless' : `♂️ ${data.genderRate.male}% ♀️ ${data.genderRate.female}%`); data.genderRate.genderless ? 'Genderless' : `♂️ ${data.genderRate.male}% ♀️ ${data.genderRate.female}%`);
if (data.cry) { if (data.cry) {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "123.2.3", "version": "123.2.4",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {
+5 -11
View File
@@ -36,8 +36,8 @@ module.exports = class Pokemon {
id: variety.pokemon.name, id: variety.pokemon.name,
name: name || null, name: name || null,
default: variety.is_default, default: variety.is_default,
display: data.missingno ? true : null, types: data.missingno ? variety.types : [],
types: data.missingno ? variety.types : [] abilities: data.missingno ? variety.abilities : []
}; };
}); });
this.chain = { this.chain = {
@@ -45,7 +45,6 @@ module.exports = class Pokemon {
data: data.missingno ? missingno.chain : data.evolution_chain ? [] : [data.id] data: data.missingno ? missingno.chain : data.evolution_chain ? [] : [data.id]
}; };
this.stats = data.missingno ? data.stats : null; this.stats = data.missingno ? data.stats : null;
this.abilities = data.missingno ? data.abilities : [];
this.height = data.missingno ? data.height : null; this.height = data.missingno ? data.height : null;
this.weight = data.missingno ? data.weight : null; this.weight = data.missingno ? data.weight : null;
this.gameDataCached = data.missingno || false; this.gameDataCached = data.missingno || false;
@@ -111,16 +110,11 @@ module.exports = class Pokemon {
if (variety.id === defaultVariety.id) continue; if (variety.id === defaultVariety.id) continue;
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`); const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`);
variety.types.push(...body.types.map(type => firstUpperCase(type.type.name))); variety.types.push(...body.types.map(type => firstUpperCase(type.type.name)));
if (variety.types[0] === defaultVariety.types[0] && variety.types[1] === defaultVariety.types[1]) { for (const ability of body.abilities) {
variety.display = false; const { body } = await request.get(ability.ability.url);
} else { variety.abilities.push(body.names.find(name => name.language.name === 'en').name);
variety.display = true;
} }
} }
for (const ability of defaultBody.abilities) {
const { body } = await request.get(ability.ability.url);
this.abilities.push(body.names.find(name => name.language.name === 'en').name);
}
this.height = defaultBody.height * 3.94; this.height = defaultBody.height * 3.94;
this.weight = defaultBody.weight * 0.2205; this.weight = defaultBody.weight * 0.2205;
await this.fetchChain(); await this.fetchChain();
+4
View File
@@ -64,6 +64,10 @@ module.exports = class Util {
return newArr; return newArr;
} }
static arrayEquals(a, b) {
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((val, i) => val === b[i]);
}
static sortByName(arr, prop) { static sortByName(arr, prop) {
return arr.sort((a, b) => { return arr.sort((a, b) => {
if (prop) return a[prop].toLowerCase() > b[prop].toLowerCase() ? 1 : -1; if (prop) return a[prop].toLowerCase() > b[prop].toLowerCase() ? 1 : -1;