Add MissingNo.

This commit is contained in:
Dragon Fire
2020-03-23 14:27:13 -04:00
parent 57e590d2dd
commit 8c27d55d55
5 changed files with 38 additions and 2 deletions
+26
View File
@@ -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
}
+1 -1
View File
@@ -49,7 +49,7 @@ module.exports = class WhosThatPokemonCommand extends Command {
} }
async run(msg, { difficulty }) { async run(msg, { difficulty }) {
const pokemon = Math.floor(Math.random() * 807) + 1; const pokemon = Math.floor(Math.random() * 808);
try { try {
const data = await this.client.pokemon.fetch(pokemon.toString()); const data = await this.client.pokemon.fetch(pokemon.toString());
const names = data.names.map(name => name.name.toLowerCase()); const names = data.names.map(name => name.name.toLowerCase());
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "112.14.1", "version": "112.14.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {
+4
View File
@@ -9,6 +9,7 @@ module.exports = class Pokemon {
.map(entry => entry.flavor_text.replace(/\n|\f|\r/g, ' '))); .map(entry => entry.flavor_text.replace(/\n|\f|\r/g, ' ')));
this.names = data.names.map(entry => ({ name: entry.name, language: entry.language.name })); 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.genus = `The ${data.genera.filter(entry => entry.language.name === 'en')[0].genus}`;
this.missingno = data.missingno || false;
} }
get displayID() { get displayID() {
@@ -20,14 +21,17 @@ module.exports = class Pokemon {
} }
get spriteImageURL() { 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`; return `https://www.serebii.net/sunmoon/pokemon/${this.displayID}.png`;
} }
get boxImageURL() { 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`; return `https://www.serebii.net/pokedex-sm/icon/${this.displayID}.png`;
} }
get serebiiURL() { get serebiiURL() {
if (this.missingno) return 'https://bulbapedia.bulbagarden.net/wiki/MissingNo.';
return `https://www.serebii.net/pokedex-sm/${this.displayID}.shtml`; return `https://www.serebii.net/pokedex-sm/${this.displayID}.shtml`;
} }
}; };
+6
View File
@@ -1,6 +1,7 @@
const Collection = require('@discordjs/collection'); const Collection = require('@discordjs/collection');
const request = require('node-superfetch'); const request = require('node-superfetch');
const Pokemon = require('./Pokemon'); const Pokemon = require('./Pokemon');
const missingno = require('../../assets/json/missingno');
module.exports = class PokemonStore extends Collection { module.exports = class PokemonStore extends Collection {
async fetch(query) { async fetch(query) {
@@ -9,6 +10,11 @@ module.exports = class PokemonStore extends Collection {
if (this.has(num)) return this.get(num); if (this.has(num)) return this.get(num);
const found = this.find(pokemon => pokemon.slug === query); const found = this.find(pokemon => pokemon.slug === query);
if (found) return found; 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 { body } = await request.get(`https://pokeapi.co/api/v2/pokemon-species/${query}/`);
const pokemon = new Pokemon(body); const pokemon = new Pokemon(body);
this.set(pokemon.id, pokemon); this.set(pokemon.id, pokemon);