Skip to content

Commit 9d7bd32

Browse files
committed
fix(bots/discord): fix timeout overflow check for role presets
1 parent 27e06db commit 9d7bd32

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

bots/discord/src/commands/moderation/mute.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CommandError, { CommandErrorType } from '$/classes/CommandError'
33
import { createModerationActionEmbed } from '$/utils/discord/embeds'
44
import { sendModerationReplyAndLogs } from '$/utils/discord/moderation'
55
import { applyRolePreset, removeRolePreset } from '$/utils/discord/rolePresets'
6-
import { parseDuration } from '$/utils/duration'
6+
import { isSafeTimeoutDuration, parseDuration } from '$/utils/duration'
77

88
export default new ModerationCommand({
99
name: 'mute',
@@ -63,7 +63,7 @@ export default new ModerationCommand({
6363
createModerationActionEmbed('Muted', user, executor.user, reason, Math.ceil(expires / 1000)),
6464
)
6565

66-
if (Number.isSafeInteger(expires))
66+
if (isSafeTimeoutDuration(duration))
6767
setTimeout(() => {
6868
removeRolePreset(member, 'mute')
6969
}, duration)

bots/discord/src/commands/moderation/role-preset.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ModerationCommand } from '$/classes/Command'
22
import CommandError, { CommandErrorType } from '$/classes/CommandError'
33
import { sendPresetReplyAndLogs } from '$/utils/discord/moderation'
44
import { applyRolePreset, removeRolePreset } from '$/utils/discord/rolePresets'
5-
import { parseDuration } from '$/utils/duration'
5+
import { isSafeTimeoutDuration, parseDuration } from '$/utils/duration'
66

77
const SubcommandOptions = {
88
member: {
@@ -78,7 +78,7 @@ export default new ModerationCommand({
7878
)
7979
}
8080

81-
if (Number.isSafeInteger(expires))
81+
if (expires && isSafeTimeoutDuration(expires))
8282
setTimeout(() => {
8383
removeRolePreset(member, preset)
8484
}, expires)

bots/discord/src/utils/duration.ts

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ export const durationToString = (duration: number) => {
2323
seconds ? `${seconds}s` : ''
2424
}`
2525
}
26+
27+
export function isSafeTimeoutDuration(duration: number) {
28+
return duration > 0 && duration < 2 ** 31 - 1
29+
}

0 commit comments

Comments
 (0)