summaryrefslogtreecommitdiff
path: root/packages/gateway/src/commands/timeout.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-04-05 09:31:26 +0000
committerFuwn <[email protected]>2026-04-05 09:31:26 +0000
commit8ead117715728f5eaa388457c37ffd79dcbba8f8 (patch)
tree222fd34d49484749bcf9edd5a5d6368753b3104c /packages/gateway/src/commands/timeout.ts
parentfeat(interactions:server): Add additional allowed role IDs (diff)
downloadumabotdiscord-8ead117715728f5eaa388457c37ffd79dcbba8f8.tar.xz
umabotdiscord-8ead117715728f5eaa388457c37ffd79dcbba8f8.zip
feat(gateway:commands): Add sayd command
Diffstat (limited to 'packages/gateway/src/commands/timeout.ts')
-rw-r--r--packages/gateway/src/commands/timeout.ts30
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}` : ""}`,