Skip to content

Commit e18ca11

Browse files
committed
fix(cli): allow zero Discord timeout duration
1 parent c1219d1 commit e18ca11

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/cli/program/message/helpers.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ vi.mock("../../deps.js", () => ({
6060

6161
const { createMessageCliHelpers } = await import("./helpers.js");
6262

63+
const NON_NEGATIVE_INTEGER_FLAGS = new Set(["--delete-days", "--duration-min"]);
64+
6365
const baseSendOptions = {
6466
channel: "discord",
6567
target: "123",
@@ -365,7 +367,7 @@ describe("runMessageAction", () => {
365367

366368
await expect(runMessageAction(action, opts)).rejects.toThrow("exit");
367369

368-
const kind = flag === "--delete-days" ? "non-negative" : "positive";
370+
const kind = NON_NEGATIVE_INTEGER_FLAGS.has(flag) ? "non-negative" : "positive";
369371
expect(errorMock).toHaveBeenCalledWith(`Error: ${flag} must be a ${kind} integer.`);
370372
expect(ensurePluginRegistryLoaded).not.toHaveBeenCalled();
371373
expect(messageCommandMock).not.toHaveBeenCalled();
@@ -390,7 +392,7 @@ describe("runMessageAction", () => {
390392
}),
391393
).rejects.toThrow("exit");
392394

393-
const kind = flag === "--delete-days" ? "non-negative" : "positive";
395+
const kind = NON_NEGATIVE_INTEGER_FLAGS.has(flag) ? "non-negative" : "positive";
394396
expect(errorMock).toHaveBeenCalledWith(`Error: ${flag} must be a ${kind} integer.`);
395397
expect(messageCommandMock).not.toHaveBeenCalled();
396398
expect(exitMock).toHaveBeenCalledWith(1);
@@ -417,6 +419,27 @@ describe("runMessageAction", () => {
417419
expect(exitMock).toHaveBeenCalledWith(0);
418420
});
419421

422+
it("allows zero duration-min for clearing Discord timeouts", async () => {
423+
const runMessageAction = createRunMessageAction();
424+
425+
await expect(
426+
runMessageAction("timeout", {
427+
guildId: "g",
428+
userId: "u",
429+
durationMin: "0",
430+
}),
431+
).rejects.toThrow("exit");
432+
433+
expect(errorMock).not.toHaveBeenCalled();
434+
expectMessageCommandOptions({
435+
action: "timeout",
436+
guildId: "g",
437+
userId: "u",
438+
durationMin: "0",
439+
});
440+
expect(exitMock).toHaveBeenCalledWith(0);
441+
});
442+
420443
it("runs gateway_stop hooks before exit when registered", async () => {
421444
hasHooksMock.mockReturnValueOnce(true);
422445
await runSendAction();

src/cli/program/message/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ const CHANNEL_MESSAGE_ACTION_NAME_SET = new Set<string>(CHANNEL_MESSAGE_ACTION_N
3434
const STRICT_POSITIVE_INTEGER_OPTIONS = new Map([
3535
["pollDurationHours", "--poll-duration-hours"],
3636
["pollDurationSeconds", "--poll-duration-seconds"],
37-
["durationMin", "--duration-min"],
3837
["limit", "--limit"],
3938
["autoArchiveMin", "--auto-archive-min"],
4039
]);
41-
const STRICT_NON_NEGATIVE_INTEGER_OPTIONS = new Map([["deleteDays", "--delete-days"]]);
40+
const STRICT_NON_NEGATIVE_INTEGER_OPTIONS = new Map([
41+
["durationMin", "--duration-min"],
42+
["deleteDays", "--delete-days"],
43+
]);
4244

4345
type MessagePluginLoadOptions = { scope: PluginRegistryScope; onlyChannelIds?: string[] };
4446
type MessagePluginPreloadPlan =

0 commit comments

Comments
 (0)