Plugins: preserve Discord command bind targets
This commit is contained in:
parent
38394ab3a8
commit
691677d0b6
@ -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",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user