diff --git a/src/plugins/commands.test.ts b/src/plugins/commands.test.ts index 34d411702a0..de9d92d75c7 100644 --- a/src/plugins/commands.test.ts +++ b/src/plugins/commands.test.ts @@ -1,5 +1,6 @@ import { afterEach, describe, expect, it } from "vitest"; import { + __testing, clearPluginCommands, getPluginCommandSpecs, listPluginCommands, @@ -94,4 +95,33 @@ describe("registerPluginCommand", () => { }, ]); }); + + it("resolves Discord DM command bindings with the user target prefix intact", () => { + expect( + __testing.resolveBindingConversationFromCommand({ + channel: "discord", + from: "discord:1177378744822943744", + to: "slash:1177378744822943744", + accountId: "default", + }), + ).toEqual({ + channel: "discord", + accountId: "default", + conversationId: "user:1177378744822943744", + }); + }); + + it("resolves Discord guild command bindings with the channel target prefix intact", () => { + expect( + __testing.resolveBindingConversationFromCommand({ + channel: "discord", + from: "discord:channel:1480554272859881494", + accountId: "default", + }), + ).toEqual({ + channel: "discord", + accountId: "default", + conversationId: "channel:1480554272859881494", + }); + }); }); diff --git a/src/plugins/commands.ts b/src/plugins/commands.ts index 587aade00d1..a0313fee70b 100644 --- a/src/plugins/commands.ts +++ b/src/plugins/commands.ts @@ -287,11 +287,12 @@ function resolveBindingConversationFromCommand(params: { }; } if (params.channel === "discord") { - const rawTarget = - stripPrefix(params.from, "discord:") ?? - stripPrefix(params.to, "discord:") ?? - params.from ?? - params.to; + const source = params.from ?? params.to; + const rawTarget = source?.startsWith("discord:channel:") + ? stripPrefix(source, "discord:") + : source?.startsWith("discord:user:") + ? stripPrefix(source, "discord:") + : source; if (!rawTarget || rawTarget.startsWith("slash:")) { return null; } @@ -302,7 +303,7 @@ function resolveBindingConversationFromCommand(params: { return { channel: "discord", accountId, - conversationId: target.id, + conversationId: `${target.kind}:${target.id}`, }; } const rawTarget = params.to ?? params.from; @@ -469,3 +470,7 @@ export function getPluginCommandSpecs(provider?: string): Array<{ acceptsArgs: cmd.acceptsArgs ?? false, })); } + +export const __testing = { + resolveBindingConversationFromCommand, +};