diff --git a/assets/json/logos.json b/assets/json/logos.json index 126072d7..eff9721b 100644 --- a/assets/json/logos.json +++ b/assets/json/logos.json @@ -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" } diff --git a/commands/random-res/mtg-card.js b/commands/random-res/mtg-card.js deleted file mode 100644 index 78890d3e..00000000 --- a/commands/random-res/mtg-card.js +++ /dev/null @@ -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); - } -}; diff --git a/commands/search/magic.js b/commands/search/magic.js new file mode 100644 index 00000000..6f801b4c --- /dev/null +++ b/commands/search/magic.js @@ -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; + } +};