Add funny flag

This commit is contained in:
Dragon Fire
2024-04-07 01:41:33 -04:00
parent b2de7200f0
commit 01657ed209
+17 -20
View File
@@ -3,19 +3,6 @@ const request = require('node-superfetch');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const logos = require('../../assets/json/logos'); 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 { module.exports = class MagicCommand extends Command {
constructor(client) { constructor(client) {
@@ -39,6 +26,16 @@ module.exports = class MagicCommand extends Command {
reasonURL: 'https://scryfall.com/docs/api' reasonURL: 'https://scryfall.com/docs/api'
} }
], ],
flags: [
{
key: 'funny',
description: 'Searches for silver-border and acorn cards.'
},
{
key: 'f',
description: 'Alias for funny.'
}
],
args: [ args: [
{ {
key: 'query', key: 'query',
@@ -50,8 +47,9 @@ module.exports = class MagicCommand extends Command {
}); });
} }
async run(msg, { query }) { async run(msg, { query, flags }) {
const card = query ? await this.search(query) : await this.random(); const funny = Boolean(flags.funny || flags.f);
const card = query ? await this.search(query, funny) : await this.random();
if (!card) return msg.say('Could not find any results.'); if (!card) return msg.say('Could not find any results.');
const isMDFC = Boolean(card.card_faces); 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 oracleText = isMDFC ? card.card_faces.map(c => c.oracle_text).join('\n\n//\n\n') : card.oracle_text;
@@ -78,12 +76,11 @@ module.exports = class MagicCommand extends Command {
return msg.embed(embed); return msg.embed(embed);
} }
async search(query) { async search(query, funny = false) {
try { try {
const isFunny = funny.includes(query);
const { body } = await request const { body } = await request
.get('https://api.scryfall.com/cards/search') .get('https://api.scryfall.com/cards/search')
.query({ q: `${query} game:paper ${isFunny ? ' is:funny' : ''}` }); .query({ q: `${query} game:paper${funny ? ' is:funny' : ''}` });
return body.data[0]; return body.data[0];
} catch (err) { } catch (err) {
if (err.status === 404) return null; if (err.status === 404) return null;
@@ -91,10 +88,10 @@ module.exports = class MagicCommand extends Command {
} }
} }
async random() { async random(funny) {
const { body } = await request const { body } = await request
.get('https://api.scryfall.com/cards/random') .get('https://api.scryfall.com/cards/random')
.query({ q: 'is:spell game:paper' }); .query({ q: `is:spell game:paper${funny ? ' is:funny' : ''}` });
return body; return body;
} }
}; };