From 30d79e2522c4244dec8f413fbb0f4d23380b3f93 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 20 Jun 2020 09:15:47 -0400 Subject: [PATCH] Allow searching credit by name --- commands/util-public/credit.js | 31 +++++++++++++++++++++++-------- package.json | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/commands/util-public/credit.js b/commands/util-public/credit.js index bbb39e87..3fb32ef5 100644 --- a/commands/util-public/credit.js +++ b/commands/util-public/credit.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); +const { Command: CommandoCommand } = require('discord.js-commando'); const { MessageEmbed } = require('discord.js'); -const { embedURL } = require('../../util/Util'); +const { trimArray, embedURL } = require('../../util/Util'); module.exports = class CreditCommand extends Command { constructor(client) { @@ -14,21 +15,35 @@ module.exports = class CreditCommand extends Command { { key: 'command', prompt: 'Which command would you like to view the credits list of?', - type: 'command' + type: 'command|string' } ] }); } run(msg, { command }) { - if (!command.credit) return msg.say('This command is credited to no one. It just appeared.'); - const embed = new MessageEmbed() - .setTitle(command.name) - .setColor(0x7289DA) - .setDescription(command.credit.map(credit => { + if (command instanceof CommandoCommand) { + if (!command.credit) return msg.say('This command is credited to no one. It just appeared.'); + const embed = new MessageEmbed() + .setTitle(command.name) + .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})`; 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); } }; diff --git a/package.json b/package.json index 7f5024e7..2c12fdbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "116.34.1", + "version": "116.34.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {