mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 13:44:11 +00:00
fix(discord): guard timeout expiry dates
This commit is contained in:
@@ -121,6 +121,7 @@ beforeEach(() => {
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
@@ -322,6 +323,18 @@ describe("sendMessageDiscord", () => {
|
||||
).toBeTypeOf("string");
|
||||
});
|
||||
|
||||
it("rejects timeout durations outside Date range", async () => {
|
||||
const { rest, patchMock } = makeDiscordRest();
|
||||
|
||||
await expect(
|
||||
timeoutMemberDiscord(
|
||||
{ guildId: "g1", userId: "u1", durationMinutes: 8_640_000_000_000_001 },
|
||||
discordClientOpts(rest),
|
||||
),
|
||||
).rejects.toThrow("Discord timeout duration is outside the supported Date range");
|
||||
expect(patchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("adds and removes roles", async () => {
|
||||
const { rest, putMock, deleteMock } = makeDiscordRest();
|
||||
putMock.mockResolvedValue({});
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
APIVoiceState,
|
||||
RESTPostAPIGuildScheduledEventJSONBody,
|
||||
} from "discord-api-types/v10";
|
||||
import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
|
||||
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import { loadWebMediaRaw } from "openclaw/plugin-sdk/web-media";
|
||||
import {
|
||||
@@ -139,7 +140,10 @@ export async function timeoutMemberDiscord(
|
||||
let until = payload.until;
|
||||
if (!until && payload.durationMinutes) {
|
||||
const ms = payload.durationMinutes * 60 * 1000;
|
||||
until = new Date(Date.now() + ms).toISOString();
|
||||
until = timestampMsToIsoString(Date.now() + ms);
|
||||
if (!until) {
|
||||
throw new Error("Discord timeout duration is outside the supported Date range");
|
||||
}
|
||||
}
|
||||
return await timeoutGuildMember(rest, payload.guildId, payload.userId, {
|
||||
body: { communication_disabled_until: until ?? null },
|
||||
|
||||
Reference in New Issue
Block a user