From adbb5e939cebcf4c0479d66162377957f2a845af Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 6 Jul 2022 22:10:58 +0200 Subject: feat(automod): unmute button --- src/commands/moderation/timeout.ts | 49 +++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/commands/moderation/timeout.ts') diff --git a/src/commands/moderation/timeout.ts b/src/commands/moderation/timeout.ts index 7be8ecb..1ceedf9 100644 --- a/src/commands/moderation/timeout.ts +++ b/src/commands/moderation/timeout.ts @@ -9,10 +9,11 @@ import { timeoutResponse, type ArgType, type CommandMessage, - type SlashMessage + type SlashMessage, + type TimeoutResponse } from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; +import { ApplicationCommandOptionType, PermissionFlagsBits, type GuildMember } from 'discord.js'; export default class TimeoutCommand extends BushCommand { public constructor() { @@ -85,25 +86,29 @@ export default class TimeoutCommand extends BushCommand { duration: duration }); - const responseMessage = (): string => { - const victim = format.input(member.user.tag); - switch (responseCode) { - case timeoutResponse.MISSING_PERMISSIONS: - return `${emojis.error} Could not timeout ${victim} because I am missing the **Timeout Members** permission.`; - case timeoutResponse.INVALID_DURATION: - return `${emojis.error} The duration you specified is too long, the longest you can timeout someone for is 28 days.`; - case timeoutResponse.ACTION_ERROR: - return `${emojis.error} An unknown error occurred while trying to timeout ${victim}.`; - case timeoutResponse.MODLOG_ERROR: - return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; - case timeoutResponse.DM_ERROR: - return `${emojis.warn} Timed out ${victim} however I could not send them a dm.`; - case timeoutResponse.SUCCESS: - return `${emojis.success} Successfully timed out ${victim}.`; - default: - return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; - } - }; - return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); + return await message.util.reply({ + content: TimeoutCommand.formatCode(member, responseCode), + allowedMentions: AllowedMentions.none() + }); + } + + public static formatCode(member: GuildMember, code: TimeoutResponse): string { + const victim = format.input(member.user.tag); + switch (code) { + case timeoutResponse.MISSING_PERMISSIONS: + return `${emojis.error} Could not timeout ${victim} because I am missing the **Timeout Members** permission.`; + case timeoutResponse.INVALID_DURATION: + return `${emojis.error} The duration you specified is too long, the longest you can timeout someone for is 28 days.`; + case timeoutResponse.ACTION_ERROR: + return `${emojis.error} An unknown error occurred while trying to timeout ${victim}.`; + case timeoutResponse.MODLOG_ERROR: + return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; + case timeoutResponse.DM_ERROR: + return `${emojis.warn} Timed out ${victim} however I could not send them a dm.`; + case timeoutResponse.SUCCESS: + return `${emojis.success} Successfully timed out ${victim}.`; + default: + return `${emojis.error} An error occurred: ${format.input(code)}}`; + } } } -- cgit