mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
PokeAPI Test
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+31
-16
@@ -1,5 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const pokedex = require('./pkdex.json');
|
||||
|
||||
module.exports = class PokedexCommand extends Command {
|
||||
@@ -11,18 +12,12 @@ module.exports = class PokedexCommand extends Command {
|
||||
],
|
||||
group: 'search',
|
||||
memberName: 'pokedex',
|
||||
description: 'Gives the pokedex entry for a Pokemon. (;pokedex Pikachu)',
|
||||
description: 'Gives the pokedex info for a Pokemon. (;pokedex Pikachu)',
|
||||
examples: [';pokedex Pikachu'],
|
||||
args: [{
|
||||
key: 'pokemon',
|
||||
prompt: 'What Pokémon would you like to get info on?',
|
||||
type: 'string',
|
||||
validate: pokemon => {
|
||||
if (pokedex.name[pokemon.toLowerCase()]) {
|
||||
return true;
|
||||
}
|
||||
return 'Please enter a valid Pokémon from either Kanto or Johto.';
|
||||
}
|
||||
type: 'string'
|
||||
}]
|
||||
});
|
||||
}
|
||||
@@ -33,17 +28,37 @@ module.exports = class PokedexCommand extends Command {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
|
||||
}
|
||||
const pokemon = args.pokemon.toLowerCase();
|
||||
const response = await snekfetch
|
||||
.get(`http://pokeapi.co/api/v2/pokemon/${pokemon}`);
|
||||
const data = response.body;
|
||||
const entry = pokedex.entry[pokemon] || 'Not Yet Implemented';
|
||||
const indexZero = '000'.slice(data.id.length);
|
||||
const type1 = data.types[1].type.name || '-';
|
||||
const type2 = data.types[0].type.name || '-';
|
||||
const embed = new RichEmbed()
|
||||
.setTitle('Information')
|
||||
.setAuthor(`#${pokedex.index[pokemon]} ${pokedex.name[pokemon]}`, `http://www.serebii.net/pokedex-sm/icon/${pokedex.index[pokemon]}.png`)
|
||||
.setAuthor(`#${indexZero}${data.id} ${data.name}`, `http://www.serebii.net/pokedex-sm/icon/${indexZero}${data.id}.png`)
|
||||
.setColor(0xFF0000)
|
||||
.setDescription(pokedex.species[pokemon])
|
||||
.setDescription(entry)
|
||||
.setFooter('Pokédex', 'http://cdn.bulbagarden.net/upload/thumb/3/36/479Rotom-Pokédex.png/250px-479Rotom-Pokédex.png')
|
||||
.setThumbnail(`http://www.serebii.net/sunmoon/pokemon/${pokedex.index[pokemon]}.png`)
|
||||
.addField('Entry',
|
||||
pokedex.entry[pokemon])
|
||||
.addField('Type',
|
||||
pokedex.type[pokemon]);
|
||||
.setThumbnail(data.sprites.front_default)
|
||||
.addField('**Types:**',
|
||||
`${type1} / ${type2}`)
|
||||
.addField('**Weight:**',
|
||||
`${data.weight / 10}kg`, true)
|
||||
.addField('**Height:**',
|
||||
`${data.height / 10}m`, true)
|
||||
.addField('**Base HP:**',
|
||||
data.stats[5].base_stat, true)
|
||||
.addField('**Base ATK:**',
|
||||
data.stats[4].base_stat, true)
|
||||
.addField('**Base DEF:**',
|
||||
data.stats[3].base_stat, true)
|
||||
.addField('**Base SPATK:**',
|
||||
data.stats[2].base_stat, true)
|
||||
.addField('**Base SPDEF:**',
|
||||
data.stats[1].base_stat, true)
|
||||
.addField('**Base SPD:**',
|
||||
data.stats[0].base_stat, true);
|
||||
return message.embed(embed);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user