woomy-v2/bot/commands/Pokemon/move.js

119 lines
4.8 KiB
JavaScript
Raw Normal View History

2020-11-08 09:09:03 +00:00
const fetch = require('node-fetch');
2020-11-10 03:31:49 +00:00
const { colours } = require('../../assets/pokemon.json');
2020-11-08 09:09:03 +00:00
2020-11-06 23:47:45 +00:00
module.exports = class {
constructor (name, category) {
this.name = name,
this.category = category,
this.enabled = true,
this.devOnly = false,
this.aliases = [],
this.userPerms = [],
this.botPerms = [],
this.cooldown = 2000,
this.help = {
2020-11-08 09:09:03 +00:00
description: 'Gets information on a pokemon move.',
arguments: '<move>',
2020-11-06 23:47:45 +00:00
details: '',
2020-11-08 09:09:03 +00:00
examples: `${this.name} roar of time\n${this.name} shadow ball`
2020-11-06 23:47:45 +00:00
};
}
run (client, message, args, data) { //eslint-disable-line no-unused-vars
2020-11-08 09:09:03 +00:00
if (!args[0]) return message.channel.createMessage(
2020-11-10 03:31:49 +00:00
`${client.emojis.userError} You didn't give me a pokemon move to look up!`
2020-11-08 09:09:03 +00:00
);
message.channel.sendTyping();
const query = args.join(' ').toLowerCase();
fetch('https://graphqlpokemon.favware.tech/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': client.config.userAgent
2020-11-08 09:09:03 +00:00
},
body: JSON.stringify({ query: `
{
getMoveDetailsByFuzzy(move: "${query}") {
name
desc
shortDesc
type
basePower
zMovePower
maxMovePower
pp
category
accuracy
priority
target
isZ
isGMax
2020-11-09 06:03:29 +00:00
contestType
2020-11-08 09:09:03 +00:00
bulbapediaPage
serebiiPage
smogonPage
2020-11-10 00:50:06 +00:00
isFieldMove
2020-11-08 09:09:03 +00:00
}
}
`})
})
.then((res) => res.json())
.then((json) => {
if (json.errors) {
json.errors.forEach(error => {
2020-11-09 06:03:29 +00:00
if (error.message.startsWith('Failed to get data for move')) {
2020-11-08 09:09:03 +00:00
message.channel.createMessage(
2020-11-10 03:31:49 +00:00
`${client.emojis.userError} I couldn't find any moves with names similar to ${query}. Check your spelling, maybe?`
2020-11-08 09:09:03 +00:00
);
} else {
client.logger.error('POKEMON_API_ERROR', error.message);
2020-11-08 09:09:03 +00:00
}
});
return;
}
2020-11-09 06:03:29 +00:00
const move = json.data.getMoveDetailsByFuzzy;
let suffix = '';
if (move.isZ) {
suffix = ' (Z-Move)';
2020-11-10 00:50:06 +00:00
} else if (!move.maxMovePower && move.basePower > 0) {
2020-11-09 06:03:29 +00:00
suffix = ' (Max Move)';
} else if (move.isGMax) {
suffix = ' (G-Max Move)';
}
2020-11-10 00:50:06 +00:00
let fieldEffects = '';
if (move.isFieldMove) fieldEffects = ' Outside of battle, ' + move.isFieldMove;
2020-11-10 03:31:49 +00:00
const embed = new client.RichEmbed()
2020-11-09 06:03:29 +00:00
.setColour(colours[move.type])
.setTitle(move.name.toProperCase() + suffix);
if (move.desc) {
2020-11-10 00:50:06 +00:00
embed.setDescription(move.desc + fieldEffects);
2020-11-08 09:09:03 +00:00
} else {
2020-11-10 00:50:06 +00:00
embed.setDescription(move.shortDesc + fieldEffects);
2020-11-08 09:09:03 +00:00
}
2020-11-09 06:03:29 +00:00
embed.addField('Type:', move.type, true);
embed.addField('Category:', move.category, true);
embed.addField('Target:', move.target, true);
if (!move.isZ || move.maxMovePower) embed.addField('Base Power:', move.basePower.toString(), true);
if (!move.isZ || move.maxMovePower) embed.addField('Z Power:', move.zMovePower.toString(), true);
if (move.maxMovePower) embed.addField('Max Power:', move.maxMovePower.toString(), true);
if (!move.isZ) embed.addField('Base PP:', move.pp.toString(), true);
embed.addField('Accuracy:', move.accuracy.toString(), true);
embed.addField('Priority:', move.priority.toString(), true);
if (move.isZ) embed.addField('Z-Crystal:', move.isZ, true);
if (move.isGMax) embed.addField('G-Max Pokemon:', move.isGMax, true);
if (move.contestType !== null) embed.addField('Contest Type', move.contestType, true);
embed.addField('External Resources:', `[Bulbapedia](${move.bulbapediaPage}) • [Serebii](${move.serebiiPage}) • [Smogon](${move.smogonPage})`);
2020-11-08 09:09:03 +00:00
message.channel.createMessage({ embed: embed });
});
2020-11-06 23:47:45 +00:00
}
};