New ygo api

This commit is contained in:
Daniel Odendahl Jr
2019-04-29 23:37:39 +00:00
parent 74dc5d38d0
commit f171082ca1
2 changed files with 23 additions and 16 deletions
+22 -15
View File
@@ -1,7 +1,7 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch'); const request = require('node-superfetch');
const { shorten, formatNumber, firstUpperCase } = require('../../util/Util'); const { shorten, formatNumber } = require('../../util/Util');
module.exports = class YuGiOhCommand extends Command { module.exports = class YuGiOhCommand extends Command {
constructor(client) { constructor(client) {
@@ -18,8 +18,8 @@ module.exports = class YuGiOhCommand extends Command {
url: 'https://www.yugioh-card.com/en/' url: 'https://www.yugioh-card.com/en/'
}, },
{ {
name: 'Yugioh Prices API', name: 'YGOPRODeck API',
url: 'https://yugiohprices.docs.apiary.io/' url: 'https://db.ygoprodeck.com/api-guide/'
} }
], ],
args: [ args: [
@@ -35,25 +35,32 @@ module.exports = class YuGiOhCommand extends Command {
async run(msg, { card }) { async run(msg, { card }) {
try { try {
const { body } = await request.get(`https://yugiohprices.com/api/card_data/${card}`); const { body } = await request
if (body.status === 'fail') return msg.say('Could not find any results.'); .get('https://db.ygoprodeck.com/api/v4/cardinfo.php')
const image = await request.get(`https://yugiohprices.com/api/card_image/${card}`); .query({
const { data } = body; name: card,
la: 'english'
});
const data = body[0][0];
const embed = new MessageEmbed() const embed = new MessageEmbed()
.attachFiles([{ attachment: image.body, name: 'thumbnail.jpg' }])
.setColor(0xBE5F1F) .setColor(0xBE5F1F)
.setTitle(data.name) .setTitle(data.name)
.setDescription(shorten(data.text)) .setDescription(shorten(data.desc))
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/AJNBflD.png', 'http://www.yugioh-card.com/') .setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/AJNBflD.png', 'http://www.yugioh-card.com/')
.setThumbnail('attachment://thumbnail.jpg') .setThumbnail(data.image_url)
.addField(' Card Type', firstUpperCase(data.card_type), true); .setFooter(data.id)
if (data.card_type === 'monster') { .addField(' Type', data.type, true);
if (data.type.includes('Monster')) {
embed embed
.addField(' Species', data.type, true) .addField(' Race', data.race, true)
.addField(' Attribute', firstUpperCase(data.family), true) .addField(' Attribute', data.attribute, true)
.addField(' Level', data.level, true) .addField(' Level', data.level, true)
.addField(' ATK', formatNumber(data.atk), true) .addField(' ATK', formatNumber(data.atk), true)
.addField(' DEF', formatNumber(data.def), true); .addField(
data.type === 'Link Monster' ? ' Link Value' : ' DEF',
formatNumber(data.type === 'Link Monster' ? data.linkval : data.def),
true
);
} }
return msg.embed(embed); return msg.embed(embed);
} catch (err) { } catch (err) {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "103.0.1", "version": "103.0.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {