mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 23:05:04 +02:00
Pokedex Item Command
This commit is contained in:
@@ -261,7 +261,7 @@ in the appropriate channel's topic to use it.
|
||||
|
||||
## Commands
|
||||
|
||||
Total: 587
|
||||
Total: 588
|
||||
|
||||
### Utility:
|
||||
|
||||
@@ -535,6 +535,7 @@ Total: 587
|
||||
* **pokedex-ability:** Searches the Pokédex for a Pokémon ability.
|
||||
* **pokedex-cry:** Plays a Pokémon's cry.
|
||||
* **pokedex-image:** Responds with the image of a Pokémon.
|
||||
* **pokedex-item:** Searches the Pokédex for a Pokémon item.
|
||||
* **pokedex-location:** Responds with the location data for a Pokémon.
|
||||
* **pokedex-move:** Searches the Pokédex for a Pokémon move.
|
||||
* **pokedex-moveset:** Responds with the moveset for a Pokémon.
|
||||
@@ -1621,6 +1622,7 @@ here.
|
||||
* pokedex-ability (API)
|
||||
* pokedex-cry (API)
|
||||
* pokedex-image (API)
|
||||
* pokedex-item (API)
|
||||
* pokedex-location (API)
|
||||
* pokedex-move (API)
|
||||
* pokedex-moveset (API)
|
||||
@@ -1637,6 +1639,7 @@ here.
|
||||
* pokedex-ability (Original Game)
|
||||
* pokedex-cry (Original Game)
|
||||
* pokedex-image (Images, Original Game)
|
||||
* pokedex-item (Images, Original Game)
|
||||
* pokedex-location (Images, Original Game)
|
||||
* pokedex-move (Original Game)
|
||||
* pokedex-moveset (Images, Original Game)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = class PokedexItemCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'pokedex-item',
|
||||
aliases: ['pokemon-item', 'pokémon-item', 'pokédex-item', 'pkmn-item'],
|
||||
group: 'pokedex',
|
||||
memberName: 'pokedex-item',
|
||||
description: 'Searches the Pokédex for a Pokémon item.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
credit: [
|
||||
{
|
||||
name: 'Pokémon',
|
||||
url: 'https://www.pokemon.com/us/',
|
||||
reason: 'Images, Original Game'
|
||||
},
|
||||
{
|
||||
name: 'PokéAPI',
|
||||
url: 'https://pokeapi.co/',
|
||||
reason: 'API'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'item',
|
||||
prompt: 'What item would you like to get information on?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { item }) {
|
||||
try {
|
||||
const data = await this.client.pokemon.items.fetch(item);
|
||||
if (!data) return msg.say('Could not find any results.');
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xED1C24)
|
||||
.setTitle(data.name)
|
||||
.setDescription(data.description || 'No description available.')
|
||||
.setThumbnail(data.spriteURL)
|
||||
.addField('❯ Cost', `${data.cost} ¥`, true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -108,8 +108,9 @@ module.exports = class PokedexCommand extends Command {
|
||||
return `${variety.types.join('/')}${showParens ? ` (${variety.name})` : ''}`;
|
||||
}).join('\n'))
|
||||
.addField('❯ Evolution Chain', `${evoChain}${data.mega ? ` -> ${this.megaEvolveEmoji}` : ''}`)
|
||||
.addField('❯ Held Items',
|
||||
data.heldItems.length ? data.heldItems.map(item => `${item.name} (${item.rarity}%)`).join('\n') : 'None')
|
||||
.addField('❯ Held Items', data.heldItems.length
|
||||
? data.heldItems.map(item => `${item.data.name} (${item.rarity}%)`).join('\n')
|
||||
: 'None')
|
||||
.addField('❯ Gender Rate',
|
||||
data.genderRate.genderless ? 'Genderless' : `♂️ ${data.genderRate.male}% ♀️ ${data.genderRate.female}%`);
|
||||
if (data.cry) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "128.2.1",
|
||||
"version": "128.3.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
const { firstUpperCase } = require('../../util/Util');
|
||||
|
||||
module.exports = class Item {
|
||||
constructor(store, data) {
|
||||
this.store = store;
|
||||
this.id = data.id;
|
||||
const slugName = firstUpperCase(data.name).replaceAll('-', ' ');
|
||||
this.name = data.names.length
|
||||
? data.names.find(entry => entry.language.name === 'en').name
|
||||
: slugName;
|
||||
this.description = data.effect_entries.length
|
||||
? data.effect_entries.find(entry => entry.language.name === 'en').effect
|
||||
: data.flavor_text_entries.length
|
||||
? data.flavor_text_entries.find(entry => entry.language.name === 'en').flavor_text
|
||||
: null;
|
||||
this.spriteURL = data.sprites.default || null;
|
||||
this.cost = data.cost || 0;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
const Collection = require('@discordjs/collection');
|
||||
const request = require('node-superfetch');
|
||||
const Item = require('./Item');
|
||||
|
||||
module.exports = class ItemStore extends Collection {
|
||||
async fetch(query) {
|
||||
if (this.has(query)) return this.get(query);
|
||||
query = this.makeSlug(query.toString());
|
||||
if (!query) return null;
|
||||
const found = this.find(pokemon => pokemon.slug === query);
|
||||
if (found) return found;
|
||||
try {
|
||||
const { body } = await request.get(`https://pokeapi.co/api/v2/item/${query}/`);
|
||||
const item = new Item(this, body);
|
||||
this.set(item.id, item);
|
||||
return item;
|
||||
} catch (err) {
|
||||
if (err.status === 404) return null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
makeSlug(query) {
|
||||
return encodeURIComponent(query.toLowerCase().replaceAll(' ', '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
}
|
||||
};
|
||||
@@ -269,8 +269,8 @@ module.exports = class Pokemon {
|
||||
return false;
|
||||
});
|
||||
return {
|
||||
url: item.item.url,
|
||||
name: null,
|
||||
data: null,
|
||||
slug: item.item.name,
|
||||
rarity
|
||||
};
|
||||
});
|
||||
@@ -306,8 +306,8 @@ module.exports = class Pokemon {
|
||||
|
||||
async fetchHeldItemNames() {
|
||||
for (const item of this.heldItems) {
|
||||
const { body } = await request.get(item.url);
|
||||
item.name = body.names.find(name => name.language.name === 'en').name;
|
||||
const data = await this.store.items.fetch(item.slug);
|
||||
item.data = data;
|
||||
}
|
||||
return this.heldItems;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ const request = require('node-superfetch');
|
||||
const Pokemon = require('./Pokemon');
|
||||
const MoveStore = require('./MoveStore');
|
||||
const AbilityStore = require('./AbilityStore');
|
||||
const ItemStore = require('./ItemStore');
|
||||
const missingno = require('../../assets/json/missingno');
|
||||
|
||||
module.exports = class PokemonStore extends Collection {
|
||||
@@ -14,6 +15,7 @@ module.exports = class PokemonStore extends Collection {
|
||||
this.smogonData = {};
|
||||
this.moves = new MoveStore();
|
||||
this.abilities = new AbilityStore();
|
||||
this.items = new ItemStore();
|
||||
}
|
||||
|
||||
async fetch(query) {
|
||||
|
||||
Reference in New Issue
Block a user