Lorcana command

This commit is contained in:
Dragon Fire
2024-04-07 01:10:08 -04:00
parent 5f5a47d20f
commit ffd098c7b9
2 changed files with 73 additions and 1 deletions
+2 -1
View File
@@ -10,5 +10,6 @@
"wikipedia": "https://i.imgur.com/Z7NJBK2.png",
"yugioh": "https://i.imgur.com/AJNBflD.png",
"youtube": "https://i.imgur.com/kKHJg9Q.png",
"scryfall": "https://i.imgur.com/DyuauFS.png"
"scryfall": "https://i.imgur.com/DyuauFS.png",
"lorcana": "https://i.imgur.com/rqatpU3.png"
}
+71
View File
@@ -0,0 +1,71 @@
const Command = require('../../framework/Command');
const request = require('node-superfetch');
const { MessageEmbed } = require('discord.js');
const logos = require('../../assets/json/logos');
module.exports = class LorcanaCommand extends Command {
constructor(client) {
super(client, {
name: 'lorcana',
aliases: ['lorcana-card'],
group: 'search',
memberName: 'lorcana',
description: 'Responds with info on a Lorcana card.',
credit: [
{
name: 'Ravensburger',
url: 'https://www.disneylorcana.com/en-US',
reason: 'Original Game'
},
{
name: 'Lorcana API',
url: 'https://lorcana-api.com/Home.html',
reason: 'API'
}
],
args: [
{
key: 'query',
type: 'string',
max: 500
}
]
});
this.cache = null;
}
async run(msg, { query }) {
const card = await this.search(query);
if (!card) return msg.say('Could not find any results.');
const oracleText = card.Body_Text ? card.Body_Text.replace(/{i}/g, 'Ink') : `_${card.Flavor_Text}_`;
const classifications = card.Classifications ? `- ${card.Classifications}` : '';
const embed = new MessageEmbed()
.setURL(card.Image)
.setColor(0xD3B078)
.setThumbnail(card.Image)
.setDescription(`{${card.Cost}} ${card.Type}${classifications}\n\n${oracleText}`)
.setAuthor('Lorcana', logos.lorcana, 'https://www.disneylorcana.com/en-US')
.setTitle(card.Name)
.addField(' Color', card.Color, true)
.addField(' Inkable?', card.Inkable ? 'Yes' : 'No', true)
.addField(' Lore', card.Lore || 0, true);
return msg.embed(embed);
}
async search(query) {
if (!this.cache) await this.fetchCards();
const results = this.cache.filter(card => {
const q = query.replace(/( - )|,/g, '');
return card.Name.toLowerCase().replace(/( - )|,/g, '').includes(q.toLowerCase());
});
if (!results.length) return null;
return results[0];
}
async fetchCards() {
const { body } = await request.get('https://api.lorcana-api.com/cards/all');
this.cache = body;
return this.cache;
}
};