From 8c27d55d55c4e9bf8f1a21667e84f9e1d07d591e Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 23 Mar 2020 14:27:13 -0400 Subject: [PATCH] Add MissingNo. --- assets/json/missingno.json | 26 ++++++++++++++++++++++++++ commands/games-sp/whos-that-pokemon.js | 2 +- package.json | 2 +- structures/pokemon/Pokemon.js | 4 ++++ structures/pokemon/PokemonStore.js | 6 ++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 assets/json/missingno.json diff --git a/assets/json/missingno.json b/assets/json/missingno.json new file mode 100644 index 00000000..410e23bd --- /dev/null +++ b/assets/json/missingno.json @@ -0,0 +1,26 @@ +{ + "names": [ + { + "language": "en", + "name": "MissingNo." + }, + { + "language": "ja", + "name": "けつばん" + } + ], + "flavor_text_entries": [ + { + "language": "en", + "flavor_text": "Comment to be written." + } + ], + "id": 0, + "genera": [ + { + "language": "en", + "genus": "???" + } + ], + "missingno": true +} diff --git a/commands/games-sp/whos-that-pokemon.js b/commands/games-sp/whos-that-pokemon.js index 6ae20b16..4dca65ce 100644 --- a/commands/games-sp/whos-that-pokemon.js +++ b/commands/games-sp/whos-that-pokemon.js @@ -49,7 +49,7 @@ module.exports = class WhosThatPokemonCommand extends Command { } async run(msg, { difficulty }) { - const pokemon = Math.floor(Math.random() * 807) + 1; + const pokemon = Math.floor(Math.random() * 808); try { const data = await this.client.pokemon.fetch(pokemon.toString()); const names = data.names.map(name => name.name.toLowerCase()); diff --git a/package.json b/package.json index 57444ff3..a5270f29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.14.1", + "version": "112.14.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index f58bcadd..62c11fe9 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -9,6 +9,7 @@ module.exports = class Pokemon { .map(entry => entry.flavor_text.replace(/\n|\f|\r/g, ' '))); this.names = data.names.map(entry => ({ name: entry.name, language: entry.language.name })); this.genus = `The ${data.genera.filter(entry => entry.language.name === 'en')[0].genus}`; + this.missingno = data.missingno || false; } get displayID() { @@ -20,14 +21,17 @@ module.exports = class Pokemon { } get spriteImageURL() { + if (this.missingno) return 'https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png'; return `https://www.serebii.net/sunmoon/pokemon/${this.displayID}.png`; } get boxImageURL() { + if (this.missingno) return 'https://cdn.bulbagarden.net/upload/1/1f/AniMS_Missingno_I.png'; return `https://www.serebii.net/pokedex-sm/icon/${this.displayID}.png`; } get serebiiURL() { + if (this.missingno) return 'https://bulbapedia.bulbagarden.net/wiki/MissingNo.'; return `https://www.serebii.net/pokedex-sm/${this.displayID}.shtml`; } }; diff --git a/structures/pokemon/PokemonStore.js b/structures/pokemon/PokemonStore.js index 1d78b23f..335f6f02 100644 --- a/structures/pokemon/PokemonStore.js +++ b/structures/pokemon/PokemonStore.js @@ -1,6 +1,7 @@ const Collection = require('@discordjs/collection'); const request = require('node-superfetch'); const Pokemon = require('./Pokemon'); +const missingno = require('../../assets/json/missingno'); module.exports = class PokemonStore extends Collection { async fetch(query) { @@ -9,6 +10,11 @@ module.exports = class PokemonStore extends Collection { if (this.has(num)) return this.get(num); const found = this.find(pokemon => pokemon.slug === query); if (found) return found; + if (query === 'missingno' || num === 0) { + const pokemon = new Pokemon(missingno); + this.set(pokemon.id, pokemon); + return pokemon; + } const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon-species/${query}/`); const pokemon = new Pokemon(body); this.set(pokemon.id, pokemon);