diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 17:17:39 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 17:17:39 -0500 |
commit | 602329510e11165aef42b3c6071bb1118e4d95c3 (patch) | |
tree | 3bd85f7808cc1aca2dee6ff879432d4ba5d35bf7 /src/commands | |
parent | 825d0299e1e155ff63e040cc9f1ffc2a4f00c4a4 (diff) | |
download | tanzanite-602329510e11165aef42b3c6071bb1118e4d95c3.tar.gz tanzanite-602329510e11165aef42b3c6071bb1118e4d95c3.tar.bz2 tanzanite-602329510e11165aef42b3c6071bb1118e4d95c3.zip |
lockdown and unlockdown command
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/moderation/_lockdown.ts | 44 | ||||
-rw-r--r-- | src/commands/moderation/lockdown.ts | 144 | ||||
-rw-r--r-- | src/commands/moderation/unlockdown.ts | 58 |
3 files changed, 202 insertions, 44 deletions
diff --git a/src/commands/moderation/_lockdown.ts b/src/commands/moderation/_lockdown.ts deleted file mode 100644 index 08d4011..0000000 --- a/src/commands/moderation/_lockdown.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { BushCommand, type BushMessage, type BushNewsChannel, type BushSlashMessage, type BushTextChannel } from '#lib'; - -export default class LockdownCommand extends BushCommand { - public constructor() { - super('lockdown', { - aliases: ['lockdown', 'unlockdown'], - category: 'moderation', - description: 'Allows you to lockdown a channel or all configured channels..', - usage: ['lockdown [--all]'], - examples: ['lockdown', 'lockdown --all'], - args: [ - { - id: 'all', - description: 'Whether or not to lock all channels', - match: 'flag', - flag: '--all', - prompt: 'Would you like to lockdown all channels?', - slashType: 'BOOLEAN', - optional: true - } - ], - slash: true, - channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: [], - hidden: true - }); - } - - public override async exec(message: BushMessage | BushSlashMessage, args: { all: boolean }) { - // todo stop being lazy - return await message.util.reply('Unfortunately my developer is too lazy to implement this command.'); - if (!args.all) { - if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(message.channel!.type)) - return message.util.reply(`${util.emojis.error} You can only lock down text and announcement channels.`); - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const lockdownSuccess = await util.lockdownChannel({ - channel: message.channel as BushTextChannel | BushNewsChannel, - moderator: message.author - }); - } - } -} diff --git a/src/commands/moderation/lockdown.ts b/src/commands/moderation/lockdown.ts new file mode 100644 index 0000000..7a0b9d8 --- /dev/null +++ b/src/commands/moderation/lockdown.ts @@ -0,0 +1,144 @@ +import { + AllowedMentions, + BushCommand, + BushNewsChannel, + BushTextChannel, + BushThreadChannel, + ConfirmationPrompt, + type ArgType, + type BushMessage, + type BushSlashMessage, + type OptionalArgType +} from '#lib'; +import assert from 'assert'; +import { Collection } from 'discord.js'; + +export default class LockdownCommand extends BushCommand { + public constructor() { + super('lockdown', { + aliases: ['lockdown'], + category: 'moderation', + description: 'Allows you to lockdown a channel or all configured channels.', + usage: ['lockdown [channel] [reason] [--all]'], + examples: ['lockdown', 'lockdown --all'], + args: [ + { + id: 'channel', + description: 'Specify a different channel to lockdown instead of the one you trigger the command in.', + type: util.arg.union('textChannel', 'newsChannel', 'threadChannel'), + prompt: 'What channel would you like to lockdown?', + slashType: 'CHANNEL', + channelTypes: ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'], + optional: true + }, + { + id: 'all', + description: 'Whether or not to lock all configured channels.', + match: 'flag', + flag: '--all', + prompt: 'Would you like to lockdown all configured channels?', + slashType: 'BOOLEAN', + optional: true + }, + { + id: 'reason', + description: 'The reason for the lockdown.', + type: 'string', + match: 'rest', + prompt: 'What is the reason for the lockdown?', + slashType: 'STRING', + optional: true + } + ], + slash: true, + channel: 'guild', + clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_CHANNELS']), + userPermissions: ['MANAGE_CHANNELS'] + }); + } + + public override async exec( + message: BushMessage | BushSlashMessage, + args: { + channel: OptionalArgType<'textChannel'> | OptionalArgType<'newsChannel'> | OptionalArgType<'threadChannel'>; + reason: OptionalArgType<'string'>; + all: ArgType<'boolean'>; + } + ) { + client.console.debug('lockdown command'); + return await LockdownCommand.lockdownOrUnlockdown(message, args, 'lockdown'); + } + + public static async lockdownOrUnlockdown( + message: BushMessage | BushSlashMessage, + args: { + channel: OptionalArgType<'textChannel'> | OptionalArgType<'newsChannel'> | OptionalArgType<'threadChannel'>; + reason: OptionalArgType<'string'>; + all: ArgType<'boolean'>; + }, + action: 'lockdown' | 'unlockdown' + ) { + assert(message.inGuild()); + + if (args.channel && args.all) + return await message.util.reply(`${util.emojis.error} You can't specify a channel and set all to true at the same time.`); + + const channel = args.channel ?? message.channel; + + if (!(channel instanceof BushTextChannel || channel instanceof BushNewsChannel || channel instanceof BushThreadChannel)) + return await message.util.reply( + `${util.emojis.error} You can only ${action} text channels, news channels, and thread channels.` + ); + + if (args.all) { + const confirmation = await ConfirmationPrompt.send(message, { + content: `Are you sure you want to ${action} all channels?` + }); + if (!confirmation) return message.util.send(`${util.emojis.error} Lockdown cancelled.`); + } + + client.console.debug('right before lockdown'); + const response = await message.guild.lockdown({ + moderator: message.author, + channel: channel ?? undefined, + reason: args.reason ?? undefined, + all: args.all ?? false, + unlock: action === 'unlockdown' + }); + + if (response instanceof Collection) { + return await message.util.send({ + content: `${util.emojis.error} The following channels failed to ${action}:`, + embeds: [ + { + description: response.map((e, c) => `<#${c}> : ${e.message}`).join('\n'), + color: util.colors.warn + } + ] + }); + } else { + let messageResponse; + if (response === 'all not chosen and no channel specified') { + messageResponse = `${util.emojis.error} You must specify a channel to ${action}.`; + } else if (response.startsWith('invalid channel configured: ')) { + const channels = response.replace('invalid channel configured: ', ''); + const actionFormatted = `${action.replace('down', '')}ed`; + messageResponse = `${util.emojis.error} Some of the channels configured to be ${actionFormatted} cannot be resolved: ${channels}}`; + } else if (response === 'no channels configured') { + messageResponse = `${util.emojis.error} The all option is selected but there are no channels configured to be locked down.`; + } else if (response === 'moderator not found') { + messageResponse = `${util.emojis.error} For some reason I could not resolve you?`; + } else if (response.startsWith('success: ')) { + const num = Number.parseInt(response.replace('success: ', '')); + messageResponse = `${util.emojis.success} Successfully ${ + action === 'lockdown' ? 'locked down' : 'unlocked' + } **${num}** channel${num > 0 ? 's' : ''}.`; + } else { + throw new Error(`Unknown response: ${response}`); + } + + assert(messageResponse); + return await message.util.send({ content: messageResponse, allowedMentions: AllowedMentions.none() }); + } + } +} diff --git a/src/commands/moderation/unlockdown.ts b/src/commands/moderation/unlockdown.ts new file mode 100644 index 0000000..87b27eb --- /dev/null +++ b/src/commands/moderation/unlockdown.ts @@ -0,0 +1,58 @@ +import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptionalArgType } from '#lib'; +import LockdownCommand from './lockdown.js'; + +export default class UnlockdownCommand extends BushCommand { + public constructor() { + super('unlockdown', { + aliases: ['unlockdown'], + category: 'moderation', + description: 'Allows you to unlockdown a channel or all configured channels.', + usage: ['unlockdown [channel] [reason] [--all]'], + examples: ['unlockdown', 'unlockdown --all'], + args: [ + { + id: 'channel', + description: 'Specify a different channel to unlockdown instead of the one you trigger the command in.', + type: util.arg.union('textChannel', 'newsChannel', 'threadChannel'), + prompt: 'What channel would you like to unlockdown?', + slashType: 'CHANNEL', + channelTypes: ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'], + optional: true + }, + { + id: 'all', + description: 'Whether or not to unlock all configured channels.', + match: 'flag', + flag: '--all', + prompt: 'Would you like to unlockdown all configured channels?', + slashType: 'BOOLEAN', + optional: true + }, + { + id: 'reason', + description: 'The reason for the unlock.', + type: 'string', + match: 'rest', + prompt: 'What is the reason for the unlock?', + slashType: 'STRING', + optional: true + } + ], + slash: true, + channel: 'guild', + clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_CHANNELS']), + userPermissions: ['MANAGE_CHANNELS'] + }); + } + + public override async exec( + message: BushMessage | BushSlashMessage, + args: { + channel: OptionalArgType<'textChannel'> | OptionalArgType<'newsChannel'> | OptionalArgType<'threadChannel'>; + reason: OptionalArgType<'string'>; + all: ArgType<'boolean'>; + } + ) { + return await LockdownCommand.lockdownOrUnlockdown(message, args, 'unlockdown'); + } +} |