fix(discord): guard timeout expiry dates · openclaw/openclaw@3c41e17
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -121,6 +121,7 @@ beforeEach(() => {
|
121 | 121 | |
122 | 122 | afterEach(() => { |
123 | 123 | vi.useRealTimers(); |
| 124 | +vi.restoreAllMocks(); |
124 | 125 | }); |
125 | 126 | |
126 | 127 | afterAll(() => { |
@@ -322,6 +323,18 @@ describe("sendMessageDiscord", () => {
|
322 | 323 | ).toBeTypeOf("string"); |
323 | 324 | }); |
324 | 325 | |
| 326 | +it("rejects timeout durations outside Date range", async () => { |
| 327 | +const { rest, patchMock } = makeDiscordRest(); |
| 328 | + |
| 329 | +await expect( |
| 330 | +timeoutMemberDiscord( |
| 331 | +{ guildId: "g1", userId: "u1", durationMinutes: 8_640_000_000_000_001 }, |
| 332 | +discordClientOpts(rest), |
| 333 | +), |
| 334 | +).rejects.toThrow("Discord timeout duration is outside the supported Date range"); |
| 335 | +expect(patchMock).not.toHaveBeenCalled(); |
| 336 | +}); |
| 337 | + |
325 | 338 | it("adds and removes roles", async () => { |
326 | 339 | const { rest, putMock, deleteMock } = makeDiscordRest(); |
327 | 340 | putMock.mockResolvedValue({}); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import type {
|
6 | 6 | APIVoiceState, |
7 | 7 | RESTPostAPIGuildScheduledEventJSONBody, |
8 | 8 | } from "discord-api-types/v10"; |
| 9 | +import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime"; |
9 | 10 | import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime"; |
10 | 11 | import { loadWebMediaRaw } from "openclaw/plugin-sdk/web-media"; |
11 | 12 | import { |
@@ -139,7 +140,10 @@ export async function timeoutMemberDiscord(
|
139 | 140 | let until = payload.until; |
140 | 141 | if (!until && payload.durationMinutes) { |
141 | 142 | const ms = payload.durationMinutes * 60 * 1000; |
142 | | -until = new Date(Date.now() + ms).toISOString(); |
| 143 | +until = timestampMsToIsoString(Date.now() + ms); |
| 144 | +if (!until) { |
| 145 | +throw new Error("Discord timeout duration is outside the supported Date range"); |
| 146 | +} |
143 | 147 | } |
144 | 148 | return await timeoutGuildMember(rest, payload.guildId, payload.userId, { |
145 | 149 | body: { communication_disabled_until: until ?? null }, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。