diff options
Diffstat (limited to 'packages/gateway/src/commands/timeout.ts')
| -rw-r--r-- | packages/gateway/src/commands/timeout.ts | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/packages/gateway/src/commands/timeout.ts b/packages/gateway/src/commands/timeout.ts index d43d6bd..88aa194 100644 --- a/packages/gateway/src/commands/timeout.ts +++ b/packages/gateway/src/commands/timeout.ts @@ -1,28 +1,7 @@ import { Message } from "discord.js"; import { CENTRAL_GUILD_ID, ROLEPLAY_GUILD_ID } from "../constants"; import { logUnexpectedDiscordAPIError, replyWithCleanup } from "../utilities"; - -const parseDuration = (duration: string): number | null => { - const match = duration.match(/^(\d+)([smhd])$/); - - if (!match) return null; - - const value = parseInt(match[1]); - const unit = match[2]; - - switch (unit) { - case "s": - return value * 1000; - case "m": - return value * 60 * 1000; - case "h": - return value * 60 * 60 * 1000; - case "d": - return value * 24 * 60 * 60 * 1000; - default: - return null; - } -}; +import { parseCommandDurationToMilliseconds } from "./parseCommandDuration"; const getUserId = (input: string): string | null => { const mentionMatch = input.match(/^<@(\d+)>$/); @@ -68,9 +47,10 @@ export const handleTimeoutCommand = async (message: Message) => { const [serverInput, userInput, durationInput, ...reasonParts] = parameters; const reason = reasonParts.join(" ") || undefined; - const durationMs = parseDuration(durationInput); + const durationMilliseconds = + parseCommandDurationToMilliseconds(durationInput); - if (!durationMs) { + if (!durationMilliseconds) { await replyWithCleanup( message, "❌ Invalid duration format. Use: `<number><s|m|h|d>`\nExamples: `1m`, `6h`, `1d`", @@ -104,7 +84,7 @@ export const handleTimeoutCommand = async (message: Message) => { try { const member = await guild.members.fetch(userId); - await member.timeout(durationMs, reason); + await member.timeout(durationMilliseconds, reason); await replyWithCleanup( message, `✅ Successfully timed out ${member.user.tag} in ${guild.name} for ${durationInput}${reason ? ` - ${reason}` : ""}`, |