Discord: fix DM recipient parsing for bare numeric user IDs (#596)
Co-authored-by: Shadow <shadow@clawd.bot>
This commit is contained in:
@@ -109,6 +109,19 @@ describe("sendMessageDiscord", () => {
|
||||
expect(res.channelId).toBe("chan1");
|
||||
});
|
||||
|
||||
it("rejects bare numeric IDs as ambiguous", async () => {
|
||||
const { rest } = makeRest();
|
||||
await expect(
|
||||
sendMessageDiscord("273512430271856640", "hello", { rest, token: "t" }),
|
||||
).rejects.toThrow(/Ambiguous Discord recipient/);
|
||||
await expect(
|
||||
sendMessageDiscord("273512430271856640", "hello", { rest, token: "t" }),
|
||||
).rejects.toThrow(/user:273512430271856640/);
|
||||
await expect(
|
||||
sendMessageDiscord("273512430271856640", "hello", { rest, token: "t" }),
|
||||
).rejects.toThrow(/channel:273512430271856640/);
|
||||
});
|
||||
|
||||
it("adds missing permission hints on 50013", async () => {
|
||||
const { rest, postMock, getMock } = makeRest();
|
||||
const perms = PermissionFlagsBits.ViewChannel;
|
||||
|
||||
@@ -305,6 +305,11 @@ function parseRecipient(raw: string): DiscordRecipient {
|
||||
}
|
||||
return { kind: "user", id: candidate };
|
||||
}
|
||||
if (/^\d+$/.test(trimmed)) {
|
||||
throw new Error(
|
||||
`Ambiguous Discord recipient "${trimmed}". Use "user:${trimmed}" for DMs or "channel:${trimmed}" for channel messages.`,
|
||||
);
|
||||
}
|
||||
return { kind: "channel", id: trimmed };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user