Pokedex Location Command

This commit is contained in:
Dragon Fire
2020-12-10 09:35:56 -05:00
parent e4f0735d59
commit 91ea2e7081
5 changed files with 144 additions and 10 deletions
+5 -1
View File
@@ -503,6 +503,7 @@ Total: 569
* **paladins:** Responds with information on a Paladins player.
* **periodic-table:** Finds an element on the periodic table.
* **poem:** Searches for poems by a specific author.
* **pokedex-location:** Responds with the location data for a Pokémon.
* **pokedex-moveset:** Responds with the moveset for a Pokémon.
* **pokedex:** Searches the Pokédex for a Pokémon.
* **pornhub:** Searches Pornhub for your query. (NSFW)
@@ -1545,7 +1546,8 @@ here.
- [Pokemon Fusion](https://pokemon.alexonsager.net/)
* pokemon-fusion (Images)
- [PokéAPI](https://pokeapi.co/)
* pokemon-moveset (API)
* pokedex-location (API)
* pokedex-moveset (API)
* pokedex (API)
* pokemon-cry (API)
* whos-that-pokemon (API)
@@ -1554,6 +1556,7 @@ here.
* 3000-years (Image, Original Game)
* dexter (Image, Original Anime)
* hat (Ash Hat Original Anime)
* pokedex-location (Images, Original Game)
* pokedex-moveset (Images, Original Game)
* pokedex (Images, Original Game)
* pokemon-cry (Original Game)
@@ -1631,6 +1634,7 @@ here.
- [SEGA](https://www.sega.com/)
* sonic-says ([Image, Original "Sonic the Hedgehog" Game](https://www.sonicthehedgehog.com/))
- [Serebii.net](https://www.serebii.net/index2.shtml)
* pokedex-location (Images)
* pokedex-moveset (Images)
* pokedex (Images)
* whos-that-pokemon (Images)
+32
View File
@@ -0,0 +1,32 @@
{
"red": "Red",
"blue": "Blue",
"yellow": "Yellow",
"gold": "Gold",
"silver": "Silver",
"crystal": "Crystal",
"ruby": "Ruby",
"sapphire": "Sapphire",
"emerald": "Emerald",
"firered": "FireRed",
"leafgreen": "LeafGreen",
"diamond": "Diamond",
"pearl": "Pearl",
"platinum": "Platinum",
"heartgold": "HeartGold",
"soulsilver": "SoulSilver",
"black": "Black",
"white": "White",
"black-2": "Black 2",
"white-2": "White 2",
"x": "X",
"y": "Y",
"alpha-sapphire": "Alpha Sapphire",
"omega-ruby": "Omega Ruby",
"sun": "Sun",
"moon": "Moon",
"ultra-sun": "Ultra Sun",
"ultra-moon": "Ultra Moon",
"sword": "Sword",
"shield": "Shield"
}
+72
View File
@@ -0,0 +1,72 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const versions = require('../../assets/json/pokedex-location');
module.exports = class PokedexLocationCommand extends Command {
constructor(client) {
super(client, {
name: 'pokedex-location',
aliases: [
'pokemon-location',
'pokémon-location',
'pokédex-location',
'pkmn-location',
'pokedex-locate',
'pokémon-locate',
'pokemon-locate',
'pokédex-locate',
'pkmn-locate'
],
group: 'search',
memberName: 'pokedex-location',
description: 'Responds with the location data for a Pokémon.',
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'
},
{
name: 'Serebii.net',
url: 'https://www.serebii.net/index2.shtml',
reason: 'Images'
}
],
args: [
{
key: 'pokemon',
prompt: 'What Pokémon would you like to get information on?',
type: 'string'
}
]
});
}
async run(msg, { pokemon }) {
try {
const data = await this.client.pokemon.fetch(pokemon);
if (!data) return msg.say('Could not find any results.');
if (!data.gameDataCached) await data.fetchGameData();
if (!data.encounters) await data.fetchEncounters();
const desc = data.encounters.length
? data.encounters
.map(location => `${location.name} (${location.versions.map(v => versions[v]).join('/')})`)
.join('\n')
: 'Location Unknown'
const embed = new MessageEmbed()
.setColor(0xED1C24)
.setAuthor(`#${data.displayID} - ${data.name}`, data.boxImageURL, data.serebiiURL)
.setDescription(desc)
.setThumbnail(data.spriteImageURL);
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "123.4.2",
"version": "123.5.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+34 -8
View File
@@ -2,6 +2,7 @@ const request = require('node-superfetch');
const path = require('path');
const { removeDuplicates, firstUpperCase } = require('../../util/Util');
const missingno = require('../../assets/json/missingno');
const versions = require('../../assets/json/pokedex-location');
module.exports = class Pokemon {
constructor(store, data) {
@@ -45,6 +46,8 @@ module.exports = class Pokemon {
url: data.evolution_chain ? data.evolution_chain.url : null,
data: data.missingno ? missingno.chain : data.evolution_chain ? [] : [data.id]
};
this.encountersURL = null;
this.encounters = data.missingno ? data.encounters : null;
this.stats = data.missingno ? data.stats : null;
this.height = data.missingno ? data.height : null;
this.weight = data.missingno ? data.weight : null;
@@ -138,29 +141,30 @@ module.exports = class Pokemon {
this.weight = defaultBody.weight * 0.2205;
this.heldItems = defaultBody.held_items
.filter(item => item.version_details.some(version => {
const inSwordShield = version.version.name === 'sword' || version.version.name === 'shield';
if (inSwordShield) return true;
if (!inSwordShield && (version.version.name === 'ultra-sun' || version.version.name === 'ultra-moon')) {
const inSwordShield2 = version.version.name === 'sword' || version.version.name === 'shield';
if (inSwordShield2) return true;
if (!inSwordShield2 && (version.version.name === 'ultra-sun' || version.version.name === 'ultra-moon')) {
return true;
}
return false;
}))
.map(item => {
const inSwordShield = item.version_details
const inSwordShield2 = item.version_details
.some(version => version.version.name === 'sword' || version.version.name === 'shield');
const rarity = item.version_details
const { rarity } = item.version_details
.find(version => {
if (inSwordShield) return true;
if (inSwordShield2) return true;
const sunMoon = version.version.name === 'ultra-sun' || version.version.name === 'ultra-moon';
if (!inSwordShield && sunMoon) return true;
if (!inSwordShield2 && sunMoon) return true;
return false;
}).rarity;
});
return {
url: item.item.url,
name: null,
rarity
};
});
this.encountersURL = defaultBody.location_area_encounters;
await this.fetchHeldItemNames();
await this.fetchChain();
this.gameDataCached = true;
@@ -200,4 +204,26 @@ module.exports = class Pokemon {
}
return this.heldItems;
}
async fetchEncounters() {
if (!this.encountersURL) return null;
if (this.encounters.length) return this.encounters;
const { body } = await request.get(this.encountersURL);
if (!body.length) {
this.encounters = body;
return body;
}
for (const encounter of body) {
if (!encounter.version_details.some(version => versions[version.version.name])) continue;
const { body: encounterBody } = await request.get(encounter.location_area.url);
const { body: locationBody } = await request.get(encounterBody.location.url);
this.encounters.push({
name: locationBody.names.find(name => name.language.name === 'en').name,
versions: encounter.version_details
.filter(version => versions[version.version.name])
.map(version => version.version.name)
});
}
return this.encounters;
}
};