mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 14:55:40 +02:00
Add Types to Pokedex
This commit is contained in:
@@ -30,6 +30,18 @@
|
||||
"genus": "??? Pokémon"
|
||||
}
|
||||
],
|
||||
"varieties": [
|
||||
{
|
||||
"is_default": true,
|
||||
"pokemon": {
|
||||
"name": "missingno"
|
||||
}
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
"Bird",
|
||||
"Normal"
|
||||
],
|
||||
"missingno": true,
|
||||
"sprite": "https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png",
|
||||
"box": "https://cdn.bulbagarden.net/upload/1/1f/AniMS_Missingno_I.png",
|
||||
|
||||
@@ -42,6 +42,7 @@ 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();
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xED1C24)
|
||||
.setAuthor(`#${data.displayID} - ${data.name}`, data.boxImageURL, data.serebiiURL)
|
||||
@@ -49,7 +50,10 @@ module.exports = class PokedexCommand extends Command {
|
||||
**${data.genus}**
|
||||
${data.entries[Math.floor(Math.random() * data.entries.length)]}
|
||||
`)
|
||||
.setThumbnail(data.spriteImageURL);
|
||||
.setThumbnail(data.spriteImageURL)
|
||||
.addField('❯ Types', data.varieties.map(
|
||||
variety => `${variety.types.join('/')}${variety.name ? ` (${variety.name})` : ''}`
|
||||
).join('\n'));
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "112.14.3",
|
||||
"version": "112.14.4",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { removeDuplicates } = require('../../util/Util');
|
||||
const request = require('node-superfetch');
|
||||
const { removeDuplicates, firstUpperCase } = require('../../util/Util');
|
||||
const missingno = require('../../assets/json/missingno');
|
||||
|
||||
module.exports = class Pokemon {
|
||||
@@ -10,6 +11,11 @@ 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.varieties = data.varieties.map(variety => {
|
||||
const name = firstUpperCase(variety.pokemon.name.replace(new RegExp(`${this.slug}-?`, 'i'), ''));
|
||||
return { id: variety.pokemon.name, name: name || null, default: variety.is_default, types: [] };
|
||||
});
|
||||
this.typesCached = false;
|
||||
this.missingno = data.missingno || false;
|
||||
}
|
||||
|
||||
@@ -35,4 +41,18 @@ module.exports = class Pokemon {
|
||||
if (this.missingno) return missingno.url;
|
||||
return `https://www.serebii.net/pokedex-sm/${this.displayID}.shtml`;
|
||||
}
|
||||
|
||||
async fetchTypes() {
|
||||
if (this.typesCached) return this;
|
||||
if (this.missingno) {
|
||||
this.varieties[0].types.push(...missingno.types);
|
||||
} else {
|
||||
for (const variety of this.varieties) {
|
||||
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`);
|
||||
variety.types.push(...body.types.map(type => firstUpperCase(type.type.name)));
|
||||
}
|
||||
}
|
||||
this.typesCached = true;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user