diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/config/prefix.ts | 1 | ||||
-rw-r--r-- | src/commands/dev/setLevel.ts | 6 | ||||
-rw-r--r-- | src/commands/info/help.ts | 120 | ||||
-rw-r--r-- | src/commands/info/ping.ts | 2 | ||||
-rw-r--r-- | src/commands/moderation/role.ts | 11 |
5 files changed, 90 insertions, 50 deletions
diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts index 9ddf81b..3bb717b 100644 --- a/src/commands/config/prefix.ts +++ b/src/commands/config/prefix.ts @@ -39,6 +39,7 @@ export default class PrefixCommand extends BushCommand { id: guild.id }); } + // this.client.console.debug(row); if (prefix) { row.prefix = prefix; await row.save(); diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts index 5a702e9..58c01dd 100644 --- a/src/commands/dev/setLevel.ts +++ b/src/commands/dev/setLevel.ts @@ -21,15 +21,15 @@ export default class SetLevelCommand extends BushCommand { type: 'user', prompt: { start: 'What user would you like to change the level of?', - retry: 'Invalid user. What user would you like to change the level of?' + retry: '{error} Choose a valid user to change the level of.' } }, { id: 'level', type: 'number', prompt: { - start: 'What level would you like to set?', - retry: 'Invalid user. What level would you like to set?' + start: 'What level would you like to set the user to?', + retry: '{error} Choose a valid level to set the user to.' } } ], 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, diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index 1b82245..f0918f0 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-empty-function */ -import { ApplicationCommandOptionType } from 'discord-api-types'; import { GuildMember, Message, Role } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import AllowedMentions from '../../lib/utils/AllowedMentions'; @@ -56,15 +55,15 @@ export default class RoleCommand extends BushCommand { } } ], - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.USER, + type: 'USER', name: 'user', description: 'The user to add/remove the role on', required: true }, { - type: ApplicationCommandOptionType.ROLE, + type: 'ROLE', name: 'role', description: 'The role to add/remove', required: true @@ -75,7 +74,7 @@ export default class RoleCommand extends BushCommand { public async exec(message: Message, { user, role }: { user: GuildMember; role: Role }): Promise<unknown> { if (!message.member.permissions.has('MANAGE_ROLES') && !this.client.ownerID.includes(message.author.id)) { - const mappedRole = this.client.util.moulberryBushRoleMap.find((m) => m.id === role.id); + const mappedRole = this.client.consts.moulberryBushRoleMap.find((m) => m.id === role.id); if (!mappedRole || !this.roleWhitelist[mappedRole.name]) { return message.util.reply({ content: `${this.client.util.emojis.error} <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`, @@ -83,7 +82,7 @@ export default class RoleCommand extends BushCommand { }); } const allowedRoles = this.roleWhitelist[mappedRole.name].map((r) => { - return this.client.util.moulberryBushRoleMap.find((m) => m.name === r).id; + return this.client.consts.moulberryBushRoleMap.find((m) => m.name === r).id; }); if (!message.member.roles.cache.some((role) => allowedRoles.includes(role.id))) { return message.util.reply({ |