diff --git a/assets/json/missingno.json b/assets/json/missingno.json index 3b378e87..bad51f11 100644 --- a/assets/json/missingno.json +++ b/assets/json/missingno.json @@ -40,7 +40,8 @@ "types": [ "Bird", "Normal" - ] + ], + "abilities": ["N/A"] }, { "is_default": false, @@ -50,7 +51,8 @@ "types": [ "Normal", "999" - ] + ], + "abilities": ["N/A"] } ], "evolution_chain": { @@ -70,7 +72,6 @@ }, "height": 120, "weight": 3507.2, - "abilities": ["N/A"], "chain": [0], "missingno": true, "sprite": "https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png", diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index 7f3af5a1..bd1f4671 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { firstUpperCase, reactIfAble } = require('../../util/Util'); +const { arrayEquals, firstUpperCase, reactIfAble } = require('../../util/Util'); module.exports = class PokedexCommand extends Command { constructor(client) { @@ -62,7 +62,15 @@ 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 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 = { hp: Math.round((data.stats.hp / 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}** `) - .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', data.genderRate.genderless ? 'Genderless' : `♂️ ${data.genderRate.male}% ♀️ ${data.genderRate.female}%`); if (data.cry) { diff --git a/package.json b/package.json index 16b7b3ca..f1498563 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "123.2.3", + "version": "123.2.4", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index 0e9509cc..1cf55dfe 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -36,8 +36,8 @@ module.exports = class Pokemon { id: variety.pokemon.name, name: name || null, 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 = { @@ -45,7 +45,6 @@ module.exports = class Pokemon { data: data.missingno ? missingno.chain : data.evolution_chain ? [] : [data.id] }; this.stats = data.missingno ? data.stats : null; - this.abilities = data.missingno ? data.abilities : []; this.height = data.missingno ? data.height : null; this.weight = data.missingno ? data.weight : null; this.gameDataCached = data.missingno || false; @@ -111,16 +110,11 @@ module.exports = class Pokemon { if (variety.id === defaultVariety.id) continue; const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`); variety.types.push(...body.types.map(type => firstUpperCase(type.type.name))); - if (variety.types[0] === defaultVariety.types[0] && variety.types[1] === defaultVariety.types[1]) { - variety.display = false; - } else { - variety.display = true; + for (const ability of body.abilities) { + const { body } = await request.get(ability.ability.url); + variety.abilities.push(body.names.find(name => name.language.name === 'en').name); } } - 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.weight = defaultBody.weight * 0.2205; await this.fetchChain(); diff --git a/util/Util.js b/util/Util.js index be4997a7..d2742534 100644 --- a/util/Util.js +++ b/util/Util.js @@ -64,6 +64,10 @@ module.exports = class Util { 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) { return arr.sort((a, b) => { if (prop) return a[prop].toLowerCase() > b[prop].toLowerCase() ? 1 : -1;