diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-26 20:07:19 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-26 20:07:19 -0400 |
commit | ed59b7f1827ab93573b079144c3eeaa01ce40492 (patch) | |
tree | 7ceac6d61a8a25586ab9bbaf7acfbade91c97132 /src/commands/admin/channelPermissions.ts | |
parent | c0a81b014a56e4d44c826f78391a930361aab122 (diff) | |
download | tanzanite-ed59b7f1827ab93573b079144c3eeaa01ce40492.tar.gz tanzanite-ed59b7f1827ab93573b079144c3eeaa01ce40492.tar.bz2 tanzanite-ed59b7f1827ab93573b079144c3eeaa01ce40492.zip |
clean up, bug fixes
Diffstat (limited to 'src/commands/admin/channelPermissions.ts')
-rw-r--r-- | src/commands/admin/channelPermissions.ts | 80 |
1 files changed, 60 insertions, 20 deletions
diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index bae1133..dc35c87 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,5 +1,5 @@ -import { BushCommand, BushMessage, ButtonPaginator } from '@lib'; -import { GuildMember, MessageEmbed, Role } from 'discord.js'; +import { BushCommand, BushMessage, BushSlashMessage, ButtonPaginator } from '@lib'; +import { GuildMember, MessageEmbed, PermissionString, Role } from 'discord.js'; export default class ChannelPermissionsCommand extends BushCommand { public constructor() { @@ -8,9 +8,9 @@ export default class ChannelPermissionsCommand extends BushCommand { category: 'admin', typing: true, description: { - content: 'Use to mass change the channel ', - usage: 'ChannelPerms <role_id> <perm> <state>', - examples: ['ChannelPerms 783794633129197589 read_messages deny'] + content: 'Use to mass change the channel permissions.', + usage: ['channel-perms <role_id> <perm> <state>'], + examples: ['channel-perms 783794633129197589 read_messages deny'] }, args: [ { @@ -18,7 +18,7 @@ export default class ChannelPermissionsCommand extends BushCommand { customType: util.arg.union('member', 'member'), prompt: { start: 'What user/role would you like to change?', - retry: 'Invalid response. What user/role would you like to change?' + retry: '{error} Choose a valid user/role to change.' } }, { @@ -44,39 +44,79 @@ export default class ChannelPermissionsCommand extends BushCommand { ], clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_CHANNELS']), userPermissions: ['ADMINISTRATOR'], - channel: 'guild' + channel: 'guild', + slash: true, + slashOptions: [ + { + name: 'target', + description: 'What user/role would you like to change?', + type: 'MENTIONABLE', + required: true + }, + { + name: 'permission', + description: 'What permission would you like to change?', + type: 'STRING', + required: true + }, + { + name: 'state', + description: 'What should that permission be set to?', + type: 'STRING', + choices: [ + { + name: 'Enabled', + value: 'true' + }, + { + name: 'Disabled', + value: 'false' + }, + { + name: 'Neutral', + value: 'neutral' + } + ], + required: true + } + ] }); } public override async exec( - message: BushMessage, - { - target, - permission, - state - }: { + message: BushMessage | BushSlashMessage, + args: { target: Role | GuildMember; - permission: string; + permission: PermissionString | string; state: 'true' | 'false' | 'neutral'; } - ): Promise<unknown> { + ) { + if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); + if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) + return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); + if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); + + const permission: PermissionString = message.util.isSlashMessage(message) + ? await util.arg.cast('permission', message, args.permission) + : args.permission; + if (!permission) return await message.util.reply(`${util.emojis.error} Invalid permission.`); const failedChannels = []; - for (const channel of message.guild!.channels.cache.values()) { + for (const [, channel] of message.guild!.channels.cache) { try { if (channel.isThread()) return; if (channel.permissionsLocked) return; - const permissionState = state === 'true' ? true : state === 'false' ? false : null; + const permissionState = args.state === 'true' ? true : args.state === 'false' ? false : null; await channel.permissionOverwrites.create( - target.id, + args.target.id, { [permission]: permissionState }, { reason: 'Changing overwrites for mass channel perms command' } ); } catch (e) { - client.console.debug(e.stack); + void client.console.error('channelPermissions', e.stack); failedChannels.push(channel); } } - const failure = failedChannels.map((e) => `<#${e.id}>`).join(' '); + const failure = failedChannels.map((c) => `<#${c.id}>`).join(' '); if (failure.length > 2000) { const paginate: MessageEmbed[] = []; for (let i = 0; i < failure.length; i += 4000) { |