diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-09-05 17:36:42 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-09-05 17:36:42 -0400 |
commit | 048f99752550c6e03d1990a03cad78f3ac7d73aa (patch) | |
tree | c238ac29b1b526e86bcbc4989036df981c860187 /src/commands/info/help.ts | |
parent | 6f8a4d13a490eda7a195d14833c83810f7b5a789 (diff) | |
download | tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.tar.gz tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.tar.bz2 tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.zip |
revamp command permissions, fix permission exploit for some command when used in forum channels, use enums more
Diffstat (limited to 'src/commands/info/help.ts')
-rw-r--r-- | src/commands/info/help.ts | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 6460b99..1680b75 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,9 +1,10 @@ import { BotCommand, - clientSendAndPermCheck, colors, format, + formatPerms, invite, + permissionCheck, type ArgType, type CommandMessage, type OptArgType, @@ -17,8 +18,7 @@ import { AutocompleteInteraction, ButtonBuilder, ButtonStyle, - EmbedBuilder, - PermissionFlagsBits + EmbedBuilder } from 'discord.js'; import { default as Fuse } from 'fuse.js'; import packageDotJSON from '../../../package.json' assert { type: 'json' }; @@ -58,7 +58,8 @@ export default class HelpCommand extends BotCommand { } ], slash: true, - clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), + clientPermissions: ['EmbedLinks'], + clientCheckChannel: true, userPermissions: [] }); } @@ -88,14 +89,24 @@ export default class HelpCommand extends BotCommand { .setFooter({ text: `For more information about a command use ${prefix_}help <command>` }); for (const [, category] of this.handler.categories.sort((a, b) => a.id.localeCompare(b.id))) { const categoryFilter = category.filter((command) => { + const inGuild = message.inGuild(); + if (command.pseudo) return false; if (command.hidden && !args.showHidden) return false; - if (command.channel == 'guild' && !message.guild && !args.showHidden) return false; + if (command.channel == 'guild' && !inGuild && !args.showHidden) return false; if (command.ownerOnly && !message.author.isOwner()) return false; if (command.superUserOnly && !message.author.isSuperUser()) return false; if (command.restrictedGuilds?.includes(message.guild?.id ?? '') === false && !args.showHidden) return false; if (command.aliases.length === 0) return false; + permissions: { + if (!inGuild || !message.member) break permissions; + + const canUse = permissionCheck(message, message.member, command.userPermissions, false); + + if (!canUse) return false; + } + return true; }); const categoryNice = category.id @@ -121,7 +132,7 @@ export default class HelpCommand extends BotCommand { this.addCommandAliases(embed, command); this.addCommandArguments(embed, command, message.author.isOwner(), message.author.isSuperUser()); this.addCommandRestrictions(embed, command); - // todo: permissions + this.addCommandPermissions(embed, command); const params = { embeds: [embed], components: row.components.length ? [row] : undefined }; return message.util.reply(params); @@ -178,6 +189,7 @@ export default class HelpCommand extends BotCommand { return ret; }) .join('\n') + .slice(0, 1024) }); } } @@ -209,6 +221,14 @@ export default class HelpCommand extends BotCommand { } } + private addCommandPermissions(embed: EmbedBuilder, command: BotCommand): void { + if (command.userPermissions.length < 1 && command.clientPermissions.length < 1) return; + const permissions: string[] = []; + if (command.userPermissions.length > 0) permissions.push(`__User__: ${formatPerms(command.userPermissions)}`); + if (command.clientPermissions.length > 0) permissions.push(`__Client__: ${formatPerms(command.clientPermissions)}`); + embed.addFields({ name: 'ยป Required Permissions', value: permissions.join('\n') }); + } + private addLinks(message: CommandMessage | SlashMessage): ActionRowBuilder<ButtonBuilder> { const row = new ActionRowBuilder<ButtonBuilder>(); const config = this.client.config; |