From 5e98cb6c1234c66eafaa93ed36087d9304fd2c12 Mon Sep 17 00:00:00 2001 From: Emily J Date: Wed, 4 Nov 2020 18:17:31 +1100 Subject: [PATCH] STUFF --- .../Fun/{ability.js => pokeability.js} | 9 +- bot/commands/Fun/pokeitem.js | 0 bot/commands/Fun/pokemove.js | 0 bot/commands/Fun/typematchup.js | 131 ++++++++++++++++++ 4 files changed, 137 insertions(+), 3 deletions(-) rename bot/commands/Fun/{ability.js => pokeability.js} (87%) create mode 100644 bot/commands/Fun/pokeitem.js create mode 100644 bot/commands/Fun/pokemove.js create mode 100644 bot/commands/Fun/typematchup.js diff --git a/bot/commands/Fun/ability.js b/bot/commands/Fun/pokeability.js similarity index 87% rename from bot/commands/Fun/ability.js rename to bot/commands/Fun/pokeability.js index 9754595..357c2dd 100644 --- a/bot/commands/Fun/ability.js +++ b/bot/commands/Fun/pokeability.js @@ -12,10 +12,10 @@ module.exports = class { this.botPerms = [], this.cooldown = 2000, this.help = { - description: '', - arguments: '', + description: 'Get data on a Pokemon ability.', + arguments: '', details: '', - examples: '' + examples: '`ability intimidate`\n`ability moxie`' }; } @@ -62,6 +62,9 @@ module.exports = class { } const ability = json.data.getAbilityDetailsByFuzzy; + if (!ability.desc) return message.channel.createMessage( + `${client.constants.emojis.botError} I'm missing data for this ability so I can't show it to you, sorry! ;w;` + ) const embed = new Embed() .setColour(client.functions.displayHexColour(message.channel.guild, client.user.id)) .setTitle(ability.name.toProperCase()) diff --git a/bot/commands/Fun/pokeitem.js b/bot/commands/Fun/pokeitem.js new file mode 100644 index 0000000..e69de29 diff --git a/bot/commands/Fun/pokemove.js b/bot/commands/Fun/pokemove.js new file mode 100644 index 0000000..e69de29 diff --git a/bot/commands/Fun/typematchup.js b/bot/commands/Fun/typematchup.js new file mode 100644 index 0000000..0028562 --- /dev/null +++ b/bot/commands/Fun/typematchup.js @@ -0,0 +1,131 @@ +const Embed = require('../../util/embed'); +const colours = require('../../assets/constants/typeColours.json'); +const fetch = require('node-fetch'); + +module.exports = class { + constructor (name, category) { + this.name = name, + this.category = category, + this.enabled = true, + this.devOnly = false, + this.aliases = ['pokedex', 'dex'], + this.userPerms = [], + this.botPerms = [], + this.cooldown = 5000, + this.help = { + description: 'Get useful data on any pokemon you ask me to!', + arguments: '', + details: '', + examples: '`pokemon mudkip`\n`pokemon giratina-origin`' + }; + } + + 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!` + ); + + message.channel.sendTyping(); + + const query = args.join(' ').toLowerCase(); + + fetch('https://graphqlpokemon.favware.tech/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ query: ` + { + getPokemonDetailsByFuzzy(pokemon: "${query}") { + num + species + types + sprite + shinySprite + bulbapediaPage + serebiiPage + smogonPage + } + } + `}) + }) + .then(res => res.json()) + .then(json => { + if (json.errors) { + json.errors.forEach(error => { + if (error.message.startsWith('No Pokémon found')) { + message.channel.createMessage( + `${client.constants.emojis.userError} I couldn't find any Pokemon with names similar to ${query}. Check your spelling, maybe?` + ); + } else { + client.logger.error('POKEMON_FETCH_ERROR', error.message); + } + }); + + return; + } + + const pokemon = json.data.getPokemonDetailsByFuzzy; + + fetch('https://graphqlpokemon.favware.tech/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ query: ` + { + getPokemonDetailsByFuzzy(pokemon: "${query}") { + num + species + types + sprite + shinySprite + bulbapediaPage + serebiiPage + smogonPage + } + } + `}) + }) + .then(res => res.json()) + .then(json => { + if (json.errors) { + json.errors.forEach(error => { + client.logger.error('POKEMON_FETCH_ERROR', error.message); + }); + + return; + } + + console.log(json.data) + const typeMatchup = json.data.getTypeMatchup.attacking; + + let doubleEffective = ''; + if (typeMatchup.doubleEffectiveTypes.length > 0) { + doubleEffective = '**' + typeMatchup.doubleEffectiveTypes.join('** **') + '**'; + doubleEffective = doubleEffective.split(' '); + } + + let doubleResists = ''; + if (typeMatchup.doubleResistedTypes.length > 0) { + doubleResists = '**' + typeMatchup.doubleResistedTypes.join('** **') + '**'; + doubleResists = doubleResists.split(' '); + } + + + const embed = new Embed() + .setColour(colours[pokemon.types[0]]) + .setTitle(`${pokemon.species.toProperCase()} (No. ${pokemon.num})`) + .setThumbnail(pokemon.sprite) + .addField('**Types:**', pokemon.types.join(', '), true) + .addField('**Weak to:**', doubleEffective.concat(typeMatchup.effectiveTypes).join(', ')) + .addField('**Strong against:**', doubleResists.concat(typeMatchup.resistedTypes).join(', ')) + .addField('**Immune to:**', typeMatchup.effectlessTypes.join(' ')) + .addField('**External Resources:**', `[Bulbapedia](${pokemon.bulbapediaPage}) | [Serebii](${pokemon.serebiiPage}) | [Smogon](${pokemon.smogonPage})`); + message.channel.createMessage({ embed: embed }); + }) + .catch(err => client.logger.error('TYPEMATCHUP_CMD_ERROR', err)); + }) + .catch(err => client.logger.error('TYPEMATCHUP_CMD_ERROR', err)); + } +}; \ No newline at end of file