Allow searching credit by name

This commit is contained in:
Dragon Fire
2020-06-20 09:15:47 -04:00
parent 953a8234b9
commit 30d79e2522
2 changed files with 24 additions and 9 deletions
+23 -8
View File
@@ -1,6 +1,7 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { Command: CommandoCommand } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const { embedURL } = require('../../util/Util'); const { trimArray, embedURL } = require('../../util/Util');
module.exports = class CreditCommand extends Command { module.exports = class CreditCommand extends Command {
constructor(client) { constructor(client) {
@@ -14,21 +15,35 @@ module.exports = class CreditCommand extends Command {
{ {
key: 'command', key: 'command',
prompt: 'Which command would you like to view the credits list of?', prompt: 'Which command would you like to view the credits list of?',
type: 'command' type: 'command|string'
} }
] ]
}); });
} }
run(msg, { command }) { run(msg, { command }) {
if (!command.credit) return msg.say('This command is credited to no one. It just appeared.'); if (command instanceof CommandoCommand) {
const embed = new MessageEmbed() if (!command.credit) return msg.say('This command is credited to no one. It just appeared.');
.setTitle(command.name) const embed = new MessageEmbed()
.setColor(0x7289DA) .setTitle(command.name)
.setDescription(command.credit.map(credit => { .setColor(0x7289DA)
.setDescription(command.credit.map(credit => {
if (!credit.reasonURL) return `${embedURL(credit.name, credit.url)} (${credit.reason})`;
return `${embedURL(credit.name, credit.url)} (${embedURL(credit.reason, credit.reasonURL)})`;
}).join('\n'));
return msg.embed(embed);
}
const commands = this.client.registry.commands
.filter(c => c.credit && c.credit.length && c.credit.find(cred => cred.name.includes(command.toLowerCase())))
.map(credit => {
if (!credit.reasonURL) return `${embedURL(credit.name, credit.url)} (${credit.reason})`; if (!credit.reasonURL) return `${embedURL(credit.name, credit.url)} (${credit.reason})`;
return `${embedURL(credit.name, credit.url)} (${embedURL(credit.reason, credit.reasonURL)})`; return `${embedURL(credit.name, credit.url)} (${embedURL(credit.reason, credit.reasonURL)})`;
}).join('\n')); });
if (!commands.length) return msg.say('Could not find any results.');
const embed = new MessageEmbed()
.setTitle(command.toLowerCase())
.setColor(0x7289DA)
.setDescription(trimArray(commands, 15).join(', '));
return msg.embed(embed); return msg.embed(embed);
} }
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "116.34.1", "version": "116.34.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {