Skip to content

Commit 495f686

Browse files
committed
fix(bots/discord): fix timeout overflow check for role presets
1 parent 71eb11b commit 495f686

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
@@ -38,3 +38,7 @@ export const durationToString = (duration: number) => {
3838
left: '',
3939
})
4040
}
41+
42+
export function isSafeTimeoutDuration(duration: number) {
43+
return duration > 0 && duration < 2 ** 31 - 1
44+
}

0 commit comments

Comments
 (0)