Revert from PokeAPI

This commit is contained in:
Daniel Odendahl Jr
2017-04-16 17:18:07 +00:00
parent 3d34d042e1
commit 7107a5896c
2 changed files with 1036 additions and 42 deletions
File diff suppressed because it is too large Load Diff
+21 -42
View File
@@ -1,6 +1,5 @@
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 {
@@ -12,59 +11,39 @@ module.exports = class PokedexCommand extends Command {
],
group: 'search',
memberName: 'pokedex',
description: 'Gives the pokedex info for a Pokemon. (;pokedex Pikachu)',
description: 'Gives the pokedex entry for a Pokemon. (;pokedex Pikachu)',
examples: [';pokedex Pikachu'],
args: [{
key: 'pokemon',
prompt: 'What Pokémon would you like to get info on?',
type: 'string'
type: 'string',
validate: pokemon => {
if (pokedex.name[pokemon.toLowerCase()]) {
return true;
}
return 'Please enter a valid Pokémon from either Kanto or Johto.';
}
}]
});
}
async run(message, args) {
run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
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();
try {
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.toString().length);
const type1 = data.types[1] ? data.types[1].type.name : '-';
const type2 = data.types[0] ? data.types[0].type.name : '-';
const embed = new RichEmbed()
.setAuthor(`#${indexZero}${data.id} ${data.name}`, `http://www.serebii.net/pokedex-sm/icon/${indexZero}${data.id}.png`)
.setColor(0xFF0000)
.setDescription(entry)
.setFooter('Pokédex', 'http://cdn.bulbagarden.net/upload/thumb/3/36/479Rotom-Pokédex.png/250px-479Rotom-Pokédex.png')
.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);
}
catch (err) {
console.error(err);
return message.say(':x: Error! Something went wrong!');
}
const embed = new RichEmbed()
.setTitle('Information')
.setAuthor(`#${pokedex.index[pokemon]} ${pokedex.name[pokemon]}`, `http://www.serebii.net/pokedex-sm/icon/${pokedex.index[pokemon]}.png`)
.setColor(0xFF0000)
.setDescription(pokedex.species[pokemon])
.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]);
return message.embed(embed);
}
};