diff options
| author | Fuwn <[email protected]> | 2026-04-05 09:31:26 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-04-05 09:31:26 +0000 |
| commit | 8ead117715728f5eaa388457c37ffd79dcbba8f8 (patch) | |
| tree | 222fd34d49484749bcf9edd5a5d6368753b3104c /packages/gateway/src/commands/parseCommandDuration.ts | |
| parent | feat(interactions:server): Add additional allowed role IDs (diff) | |
| download | umabotdiscord-8ead117715728f5eaa388457c37ffd79dcbba8f8.tar.xz umabotdiscord-8ead117715728f5eaa388457c37ffd79dcbba8f8.zip | |
feat(gateway:commands): Add sayd command
Diffstat (limited to 'packages/gateway/src/commands/parseCommandDuration.ts')
| -rw-r--r-- | packages/gateway/src/commands/parseCommandDuration.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/gateway/src/commands/parseCommandDuration.ts b/packages/gateway/src/commands/parseCommandDuration.ts new file mode 100644 index 0000000..946e3cb --- /dev/null +++ b/packages/gateway/src/commands/parseCommandDuration.ts @@ -0,0 +1,25 @@ +export const parseCommandDurationToMilliseconds = ( + duration: string, +): number | null => { + const durationMatch = duration.match(/^(\d+)([smhd])$/); + + if (!durationMatch) return null; + + const durationValue = Number.parseInt(durationMatch[1], 10); + const durationUnit = durationMatch[2]; + + if (durationValue < 1) return null; + + switch (durationUnit) { + case "s": + return durationValue * 1000; + case "m": + return durationValue * 60 * 1000; + case "h": + return durationValue * 60 * 60 * 1000; + case "d": + return durationValue * 24 * 60 * 60 * 1000; + default: + return null; + } +}; |