unfinished

This commit is contained in:
Emily 2020-11-03 21:56:59 +11:00
parent 79a2c9a89b
commit 4e4ab100ec

View file

@ -21,8 +21,11 @@ module.exports = class {
} }
async run (client, message, args, data) { //eslint-disable-line no-unused-vars async run (client, message, args, data) { //eslint-disable-line no-unused-vars
if (!args[0]) return message.channel.createMessage(
`${client.constants.emojis.userError} You didn't give me a pokemon to look up!`
);
const query = args.join(' '); const query = args.join(' ').toLowerCase();
fetch('https://graphqlpokemon.favware.tech/', { fetch('https://graphqlpokemon.favware.tech/', {
method: 'POST', method: 'POST',
@ -60,6 +63,21 @@ module.exports = class {
}) })
.then((res) => res.json()) .then((res) => res.json())
.then((json) => { .then((json) => {
if (json.errors) {
console.log(json.errors)
for (const error in json.errors) {
console.log(error);
if (error.message.startsWith('No Pokémon found')) {
message.channel.createMessage(
`${client.constants.emojis.userError} I tried really hard, but I couldn't find any Pokemon called \`${query}\``
);
} else {
client.logger.error('POKEMON_FETCH_ERROR', error.message);
}
}
return;
}
const pokemon = json.data.getPokemonDetailsByFuzzy; const pokemon = json.data.getPokemonDetailsByFuzzy;
const evoChain = this.parseEvoChain(pokemon); const evoChain = this.parseEvoChain(pokemon);
const genderRatio = this.parseGenderRatio(pokemon.gender); const genderRatio = this.parseGenderRatio(pokemon.gender);