mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Make magic command search
This commit is contained in:
@@ -10,5 +10,6 @@
|
||||
"urban": "https://i.imgur.com/Fo0nRTe.png",
|
||||
"wikipedia": "https://i.imgur.com/Z7NJBK2.png",
|
||||
"yugioh": "https://i.imgur.com/AJNBflD.png",
|
||||
"youtube": "https://i.imgur.com/kKHJg9Q.png"
|
||||
"youtube": "https://i.imgur.com/kKHJg9Q.png",
|
||||
"scryfall": "https://i.imgur.com/DyuauFS.png"
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const request = require('node-superfetch');
|
||||
|
||||
module.exports = class MtgCardCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'mtg-card',
|
||||
aliases: ['mtg', 'discord', 'discord-card', 'mtg-discord', 'mtg-discord-card'],
|
||||
group: 'random-res',
|
||||
memberName: 'github-zen',
|
||||
description: 'Responds with a random castable Magic: The Gathering card for Discord, Lord of Disharmony.',
|
||||
credit: [
|
||||
{
|
||||
name: 'Scryfall',
|
||||
url: 'https://scryfall.com/',
|
||||
reason: 'Random Results',
|
||||
reasonURL: 'https://scryfall.com/random?q=is%3Aspell+game%3Apaper'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
const { url } = await request.get('https://scryfall.com/random?q=is%3Aspell+game%3Apaper');
|
||||
return msg.say(url);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,91 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const logos = require('../../assets/json/logos');
|
||||
const funny = [
|
||||
'cheatyface',
|
||||
'rainbow dash',
|
||||
'pinkie pie',
|
||||
'twilight sparkle',
|
||||
'applejack',
|
||||
'fluttershy',
|
||||
'rarity',
|
||||
'nightmare moon',
|
||||
'princess luna',
|
||||
'discord',
|
||||
'discord, lord of disharmony'
|
||||
];
|
||||
|
||||
module.exports = class MagicCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'magic',
|
||||
aliases: ['mtg', 'mtg-card', 'magic-the-gathering', 'magic-the-gathering-card'],
|
||||
group: 'random-res',
|
||||
memberName: 'magic',
|
||||
description: 'Responds with info on a Magic: The Gathering card.',
|
||||
credit: [
|
||||
{
|
||||
name: 'Wizards of the Coast',
|
||||
url: 'https://company.wizards.com/en',
|
||||
reason: 'Original Game',
|
||||
reasonURL: 'https://magic.wizards.com/en'
|
||||
},
|
||||
{
|
||||
name: 'Scryfall',
|
||||
url: 'https://scryfall.com/',
|
||||
reason: 'API',
|
||||
reasonURL: 'https://scryfall.com/docs/api'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
type: 'string',
|
||||
max: 500,
|
||||
default: ''
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
const card = query ? await this.search(query) : await this.random();
|
||||
const isMDFC = Boolean(card.card_faces);
|
||||
const oracleText = isMDFC ? card.card_faces.map(c => c.oracle_text).join('\n\n//\n\n') : card.oracle_text;
|
||||
const manaCost = isMDFC ? card.card_faces.map(c => c.mana_cost).join(' // ') : card.mana_cost;
|
||||
const embed = new MessageEmbed()
|
||||
.setURL(card.scryfall_uri)
|
||||
.setThumbnail(card.card_faces ? card.card_faces[0].image_uris.art_crop : card.image_uris.art_crop)
|
||||
.setDescription(`${manaCost}\n\n${oracleText}`)
|
||||
.setAuthor('Scryfall', logos.scryfall, 'https://scryfall.com/')
|
||||
.setTitle(card.name)
|
||||
.setFooter(card.type_line)
|
||||
.addField('❯ Price', stripIndents`
|
||||
**Non-Foil:** [${card.prices.usd ? `$${card.prices.usd}` : '???'}](${card.purchase_uris.tcgplayer})
|
||||
**Foil:** [${card.prices.usd_foil ? `$${card.prices.usd_foil}` : '???'}](${card.purchase_uris.tcgplayer})
|
||||
`);
|
||||
return msg.embed(embed);
|
||||
}
|
||||
|
||||
async search(query) {
|
||||
try {
|
||||
const isFunny = funny.includes(query);
|
||||
const { body } = await request
|
||||
.get('https://api.scryfall.com/cards/search')
|
||||
.query({ q: `${query}${isFunny ? ' is:funny' : ''}` });
|
||||
return body.data[0];
|
||||
} catch (err) {
|
||||
if (err.status === 404) return null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async random() {
|
||||
const { body } = await request
|
||||
.get('https://api.scryfall.com/cards/random')
|
||||
.query({ q: 'is:spell game:paper' });
|
||||
return body;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user