Skip to content

Commit 6399b6a

Browse files
committed
fix(discord): bound timeout member expiry
1 parent 472606d commit 6399b6a

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎extensions/discord/src/send.creates-thread.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,20 @@ describe("sendMessageDiscord", () => {
335335
expect(patchMock).not.toHaveBeenCalled();
336336
});
337337

338+
it("rejects timeout durations that overflow from the current clock", async () => {
339+
vi.useFakeTimers();
340+
vi.setSystemTime(new Date(8_640_000_000_000_000));
341+
const { rest, patchMock } = makeDiscordRest();
342+
343+
await expect(
344+
timeoutMemberDiscord(
345+
{ guildId: "g1", userId: "u1", durationMinutes: 1 },
346+
discordClientOpts(rest),
347+
),
348+
).rejects.toThrow("Discord timeout duration is outside the supported Date range");
349+
expect(patchMock).not.toHaveBeenCalled();
350+
});
351+
338352
it("adds and removes roles", async () => {
339353
const { rest, putMock, deleteMock } = makeDiscordRest();
340354
putMock.mockResolvedValue({});

‎extensions/discord/src/send.guild.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import type {
66
APIVoiceState,
77
RESTPostAPIGuildScheduledEventJSONBody,
88
} from "discord-api-types/v10";
9-
import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
9+
import {
10+
resolveExpiresAtMsFromDurationMs,
11+
timestampMsToIsoString,
12+
} from "openclaw/plugin-sdk/number-runtime";
1013
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
1114
import { loadWebMediaRaw } from "openclaw/plugin-sdk/web-media";
1215
import {
@@ -140,7 +143,7 @@ export async function timeoutMemberDiscord(
140143
let until = payload.until;
141144
if (!until && payload.durationMinutes) {
142145
const ms = payload.durationMinutes * 60 * 1000;
143-
until = timestampMsToIsoString(Date.now() + ms);
146+
until = timestampMsToIsoString(resolveExpiresAtMsFromDurationMs(ms));
144147
if (!until) {
145148
throw new Error("Discord timeout duration is outside the supported Date range");
146149
}

0 commit comments

Comments
 (0)