mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:07:41 +00:00
Discord: add reusable component option
This commit is contained in:
@@ -935,7 +935,10 @@ async function handleDiscordComponentEvent(params: {
|
||||
return;
|
||||
}
|
||||
|
||||
const consumed = resolveDiscordComponentEntry({ id: parsed.componentId });
|
||||
const consumed = resolveDiscordComponentEntry({
|
||||
id: parsed.componentId,
|
||||
consume: !entry.reusable,
|
||||
});
|
||||
if (!consumed) {
|
||||
try {
|
||||
await params.interaction.reply({
|
||||
@@ -1069,7 +1072,10 @@ async function handleDiscordModalTrigger(params: {
|
||||
return;
|
||||
}
|
||||
|
||||
const consumed = resolveDiscordComponentEntry({ id: parsed.componentId });
|
||||
const consumed = resolveDiscordComponentEntry({
|
||||
id: parsed.componentId,
|
||||
consume: !entry.reusable,
|
||||
});
|
||||
if (!consumed) {
|
||||
try {
|
||||
await params.interaction.reply({
|
||||
@@ -1501,7 +1507,10 @@ class DiscordComponentModal extends Modal {
|
||||
return;
|
||||
}
|
||||
|
||||
const consumed = resolveDiscordModalEntry({ id: modalId });
|
||||
const consumed = resolveDiscordModalEntry({
|
||||
id: modalId,
|
||||
consume: !modalEntry.reusable,
|
||||
});
|
||||
if (!consumed) {
|
||||
try {
|
||||
await interaction.reply({
|
||||
|
||||
@@ -291,6 +291,36 @@ describe("discord component interactions", () => {
|
||||
expect(resolveDiscordComponentEntry({ id: "btn_1" })).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps reusable buttons active after use", async () => {
|
||||
registerDiscordComponentEntries({
|
||||
entries: [
|
||||
{
|
||||
id: "btn_1",
|
||||
kind: "button",
|
||||
label: "Approve",
|
||||
messageId: "msg-1",
|
||||
sessionKey: "session-1",
|
||||
agentId: "agent-1",
|
||||
accountId: "default",
|
||||
reusable: true,
|
||||
},
|
||||
],
|
||||
modals: [],
|
||||
});
|
||||
|
||||
const button = createDiscordComponentButton(createComponentContext());
|
||||
const { interaction } = createComponentButtonInteraction();
|
||||
await button.run(interaction, { cid: "btn_1" } as ComponentData);
|
||||
|
||||
const { interaction: secondInteraction } = createComponentButtonInteraction({
|
||||
rawData: { channel_id: "dm-channel", id: "interaction-2" },
|
||||
});
|
||||
await button.run(secondInteraction, { cid: "btn_1" } as ComponentData);
|
||||
|
||||
expect(dispatchReplyMock).toHaveBeenCalledTimes(2);
|
||||
expect(resolveDiscordComponentEntry({ id: "btn_1", consume: false })).not.toBeNull();
|
||||
});
|
||||
|
||||
it("routes modal submissions with field values", async () => {
|
||||
registerDiscordComponentEntries({
|
||||
entries: [],
|
||||
@@ -331,6 +361,43 @@ describe("discord component interactions", () => {
|
||||
expect(deliverDiscordReplyMock.mock.calls[0]?.[0]?.replyToId).toBe("msg-2");
|
||||
expect(resolveDiscordModalEntry({ id: "mdl_1" })).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps reusable modal entries active after submission", async () => {
|
||||
registerDiscordComponentEntries({
|
||||
entries: [],
|
||||
modals: [
|
||||
{
|
||||
id: "mdl_1",
|
||||
title: "Details",
|
||||
messageId: "msg-2",
|
||||
sessionKey: "session-2",
|
||||
agentId: "agent-2",
|
||||
accountId: "default",
|
||||
reusable: true,
|
||||
fields: [
|
||||
{
|
||||
id: "fld_1",
|
||||
name: "name",
|
||||
label: "Name",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const modal = createDiscordComponentModal(
|
||||
createComponentContext({
|
||||
discordConfig: createDiscordConfig({ replyToMode: "all" }),
|
||||
}),
|
||||
);
|
||||
const { interaction, acknowledge } = createModalInteraction();
|
||||
|
||||
await modal.run(interaction, { mid: "mdl_1" } as ComponentData);
|
||||
|
||||
expect(acknowledge).toHaveBeenCalledTimes(1);
|
||||
expect(resolveDiscordModalEntry({ id: "mdl_1", consume: false })).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveDiscordOwnerAllowFrom", () => {
|
||||
|
||||
Reference in New Issue
Block a user