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

82 lines
3 KiB
JavaScript
Raw Normal View History

2020-11-09 06:29:51 +00:00
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 = [],
this.userPerms = [],
this.botPerms = [],
this.cooldown = 2000,
this.help = {
description: 'Gets information on a held item.',
arguments: '<item>',
details: '',
examples: 'item life orb\nitem griseous orb'
};
}
run (client, message, args, data) { //eslint-disable-line no-unused-vars
if (!args[0]) return message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} You didn't give me an item to look up!`
2020-11-09 06:29:51 +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-09 06:29:51 +00:00
},
body: JSON.stringify({ query: `
{
getItemDetailsByFuzzy(item: "${query}") {
name
desc
shortDesc
sprite
generationIntroduced
bulbapediaPage
serebiiPage
smogonPage
}
}
`})
})
.then((res) => res.json())
.then((json) => {
if (json.errors) {
json.errors.forEach(error => {
if (error.message.startsWith('Failed to get data for item')) {
message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} I couldn't find any items with names similar to ${query}. Check your spelling, maybe?`
2020-11-09 06:29:51 +00:00
);
} else {
client.logger.error('POKEMON_API_ERROR', error.message);
2020-11-09 06:29:51 +00:00
}
});
return;
}
const item = json.data.getItemDetailsByFuzzy;
2020-11-10 03:31:49 +00:00
const embed = new client.RichEmbed()
2021-07-15 02:53:57 +00:00
.setColour(client.functions.displayHexColour(message.guild))
2020-11-09 06:29:51 +00:00
.setTitle(item.name)
.setThumbnail(item.sprite)
.addField('External Resources:', `[Bulbapedia](${item.bulbapediaPage}) • [Serebii](${item.serebiiPage}) • [Smogon](${item.smogonPage})`);
if (item.desc) {
embed.setDescription(`${item.desc} Added in Generation ${item.generationIntroduced}.`);
} else {
embed.setDescription(`${item.shortDesc} Added in Generation ${item.generationIntroduced}.`);
}
message.channel.send({ embed: embed });
2020-11-09 06:29:51 +00:00
});
}
};