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'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-17 05:55:18 +00:00
|
|
|
async run (client, message, args, data) { //eslint-disable-line no-unused-vars
|
2021-07-15 02:39:19 +00:00
|
|
|
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
|
|
|
);
|
|
|
|
|
2021-07-17 05:55:18 +00:00
|
|
|
const editMessage = await message.channel.send(`${client.config.emojis.loading} Please wait...`);
|
2020-11-09 06:29:51 +00:00
|
|
|
|
|
|
|
const query = args.join(' ').toLowerCase();
|
|
|
|
|
|
|
|
fetch('https://graphqlpokemon.favware.tech/', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
2021-02-26 02:16:47 +00:00
|
|
|
'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')) {
|
2021-07-15 02:39:19 +00:00
|
|
|
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 {
|
2020-11-11 23:55:35 +00:00
|
|
|
client.logger.error('POKEMON_API_ERROR', error.message);
|
2020-11-09 06:29:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const item = json.data.getItemDetailsByFuzzy;
|
|
|
|
|
2021-07-17 05:55:18 +00:00
|
|
|
const embed = new client.MessageEmbed()
|
|
|
|
.setColor(client.functions.embedColor(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}.`);
|
|
|
|
}
|
2021-07-17 05:55:18 +00:00
|
|
|
editMessage.edit({ content: null, embeds: [embed] });
|
2020-11-09 06:29:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|