mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 14:00:22 +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 { Command } = require('discord.js-commando');
|
||||||
const { RichEmbed } = require('discord.js');
|
const { RichEmbed } = require('discord.js');
|
||||||
|
const snekfetch = require('snekfetch');
|
||||||
const pokedex = require('./pkdex.json');
|
const pokedex = require('./pkdex.json');
|
||||||
|
|
||||||
module.exports = class PokedexCommand extends Command {
|
module.exports = class PokedexCommand extends Command {
|
||||||
@@ -11,18 +12,12 @@ module.exports = class PokedexCommand extends Command {
|
|||||||
],
|
],
|
||||||
group: 'search',
|
group: 'search',
|
||||||
memberName: 'pokedex',
|
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'],
|
examples: [';pokedex Pikachu'],
|
||||||
args: [{
|
args: [{
|
||||||
key: 'pokemon',
|
key: 'pokemon',
|
||||||
prompt: 'What Pokémon would you like to get info on?',
|
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.';
|
|
||||||
}
|
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -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!');
|
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 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()
|
const embed = new RichEmbed()
|
||||||
.setTitle('Information')
|
.setAuthor(`#${indexZero}${data.id} ${data.name}`, `http://www.serebii.net/pokedex-sm/icon/${indexZero}${data.id}.png`)
|
||||||
.setAuthor(`#${pokedex.index[pokemon]} ${pokedex.name[pokemon]}`, `http://www.serebii.net/pokedex-sm/icon/${pokedex.index[pokemon]}.png`)
|
|
||||||
.setColor(0xFF0000)
|
.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')
|
.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`)
|
.setThumbnail(data.sprites.front_default)
|
||||||
.addField('Entry',
|
.addField('**Types:**',
|
||||||
pokedex.entry[pokemon])
|
`${type1} / ${type2}`)
|
||||||
.addField('Type',
|
.addField('**Weight:**',
|
||||||
pokedex.type[pokemon]);
|
`${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);
|
return message.embed(embed);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user