diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-20 22:52:50 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-20 22:52:50 -0400 |
commit | 5c3da90f441c321f55ae735d6002f4da91f2481e (patch) | |
tree | ac6a993595eebe38fd5e7bd79ade4c5ec71be373 /src/commands/info | |
parent | 87e77ae8cc69d0d7f1e3d6f614b03c9297e85ab3 (diff) | |
download | tanzanite-5c3da90f441c321f55ae735d6002f4da91f2481e.tar.gz tanzanite-5c3da90f441c321f55ae735d6002f4da91f2481e.tar.bz2 tanzanite-5c3da90f441c321f55ae735d6002f4da91f2481e.zip |
feat(*): aaaaa
Diffstat (limited to 'src/commands/info')
-rw-r--r-- | src/commands/info/help.ts | 120 | ||||
-rw-r--r-- | src/commands/info/ping.ts | 2 |
2 files changed, 81 insertions, 41 deletions
diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 9caae24..2ffac1b 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,4 +1,4 @@ -import { MessageEmbed } from 'discord.js'; +import { MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { BushMessage } from '../../lib/extensions/BushMessage'; @@ -9,22 +9,33 @@ export default class HelpCommand extends BushCommand { aliases: ['help'], category: 'info', description: { - content: 'Shows the commands of the bot', - usage: 'help', - examples: ['help'] + content: 'Displays a list of commands, or detailed information for a specific command.', + usage: 'help [command]', + examples: ['help prefix'] }, clientPermissions: ['EMBED_LINKS'], args: [ { id: 'command', - type: 'commandAlias' + type: 'commandAlias', + match: 'content', + prompt: { + start: 'What command do you need help with?', + retry: '{error} Choose a valid command to find help for.', + optional: true + } + }, + { + id: 'showHidden', + match: 'flag', + flag: '--hidden' } ], slashOptions: [ { type: 'STRING', name: 'command', - description: 'The command to get help for', + description: `The command you would like to find information about.`, required: false } ], @@ -32,46 +43,73 @@ export default class HelpCommand extends BushCommand { }); } - private generateEmbed(command?: BushCommand, message?: BushInteractionMessage | BushMessage): MessageEmbed { + public async exec( + message: BushMessage | BushInteractionMessage, + args: { command: BushCommand | string; showHidden?: boolean } + ): Promise<unknown> { const prefix = this.client.config.dev ? 'dev ' : message.util.parsed.prefix; + let ButtonRow: MessageActionRow; + if (!this.client.config.dev) { + ButtonRow = new MessageActionRow().addComponents( + new MessageButton({ + style: 'LINK', + label: 'Invite Me', + url: `https://discord.com/api/oauth2/authorize?client_id=${this.client.user.id}&permissions=2147483647&scope=bot%20applications.commands` + }) + ); + } + const isOwner = this.client.isOwner(message.author); + const isSuperUser = this.client.isSuperUser(message.author); + const command = args.command + ? typeof args.command === 'string' + ? this.client.commandHandler.modules.get(args.command) || null + : args.command + : null; + if (!isOwner) args.showHidden = false; if (!command) { - const embed = new MessageEmbed() - .setFooter(`For more information about a command use '${prefix}help <command>'`) - .setTimestamp() - .setColor(this.client.util.colors.default); - for (const category of this.handler.categories.values()) { - embed.addField( - `${category.id.replace(/(\b\w)/gi, (lc): string => lc.toUpperCase())}`, - `${category - .filter((cmd): boolean => cmd.aliases.length > 0) - .map((cmd): string => `\`${cmd.aliases[0]}\``) - .join(' ')}` - ); + const embed = new MessageEmbed().setColor(this.client.util.colors.default).setTimestamp(); + if (message.guild) { + embed.setFooter(`For more information about a command use '${prefix}help <command>'`); + } + for (const [, category] of this.handler.categories) { + const categoryFilter = category.filter((command) => { + if (command.hidden && !args.showHidden) return false; + if (command.channel == 'guild' && !message.guild && !args.showHidden) return false; + if (command.ownerOnly && !isOwner) return false; + if (command.superUserOnly && !isSuperUser) { + return false; + } + if (command.restrictedGuilds?.includes(message.guild.id) == !true && !args.showHidden) return false; + return true; + }); + const categoryNice = category.id + .replace(/(\b\w)/gi, (lc): string => lc.toUpperCase()) + .replace(/'(S)/g, (letter): string => letter.toLowerCase()); + const categoryCommands = categoryFilter + .filter((cmd): boolean => cmd.aliases.length > 0) + .map((cmd): string => `\`${cmd.aliases[0]}\``); + if (categoryCommands.length > 0) { + embed.addField(`${categoryNice}`, `${categoryCommands.join(' ')}`); + } } - return embed; - } else { - const embed = new MessageEmbed() - .setColor([155, 200, 200]) - .setTitle(`\`${command.description.usage ? command.description.usage : ''}\``) - .addField( - 'Description', - `${command.description.content ? command.description.content : ''} ${command.ownerOnly ? '\n__Owner Only__' : ''}` - ); + return await message.util.reply({ embeds: [embed], components: ButtonRow ? [ButtonRow] : undefined }); + } + + const embed = new MessageEmbed() + .setColor(this.client.util.colors.default) + .setTitle(`\`${command.description?.usage ? command.description.usage : 'This command does not have usages.'}\``) + .addField( + 'Description', + `${command.description?.content ? command.description.content : '*This command does not have a description.*'} ${ + command.ownerOnly ? '\n__Dev Only__' : '' + } ${command.superUserOnly ? '\n__Super User Only__' : ''}` + ); - if (command.aliases.length > 1) embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); - if (command.description.examples && command.description.examples.length) - embed.addField('Examples', `\`${command.description.examples.join('`\n`')}\``, true); - return embed; + if (command.aliases?.length > 1) embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); + if (command.description?.examples && command.description.examples.length) { + embed.addField('Examples', `\`${command.description.examples.join('`\n`')}\``, true); } - } - public async exec( - message: BushMessage | BushInteractionMessage, - { command }: { command: BushCommand | string } - ): Promise<void> { - const parsedCommand = message.util.isSlash - ? (this.handler.findCommand(command as string) as BushCommand) - : (command as BushCommand); - await message.util.send({ embeds: [this.generateEmbed(parsedCommand, message)] }); + return await message.util.reply({ embeds: [embed], components: ButtonRow ? [ButtonRow] : undefined }); } } diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index 5552573..fb93c50 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -26,6 +26,7 @@ export default class PingCommand extends BushCommand { .addField('Bot Latency', botLatency, true) .addField('API Latency', apiLatency, true) .setFooter(message.author.username, message.author.displayAvatarURL({ dynamic: true })) + .setColor(this.client.util.colors.default) .setTimestamp(); await sentMessage.edit({ content: null, @@ -44,6 +45,7 @@ export default class PingCommand extends BushCommand { .addField('Bot Latency', botLatency, true) .addField('API Latency', apiLatency, true) .setFooter(message.interaction.user.username, message.interaction.user.displayAvatarURL({ dynamic: true })) + .setColor(this.client.util.colors.default) .setTimestamp(); await message.interaction.editReply({ content: null, |