mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:01:25 +00:00
feat(discord): add configurable ephemeral option for slash commands
This commit is contained in:
24
src/discord/monitor/commands.test.ts
Normal file
24
src/discord/monitor/commands.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveDiscordSlashCommandConfig } from "./commands.js";
|
||||
|
||||
describe("resolveDiscordSlashCommandConfig", () => {
|
||||
it("defaults ephemeral to true when undefined", () => {
|
||||
const result = resolveDiscordSlashCommandConfig(undefined);
|
||||
expect(result.ephemeral).toBe(true);
|
||||
});
|
||||
|
||||
it("defaults ephemeral to true when not explicitly false", () => {
|
||||
const result = resolveDiscordSlashCommandConfig({});
|
||||
expect(result.ephemeral).toBe(true);
|
||||
});
|
||||
|
||||
it("sets ephemeral to false when explicitly false", () => {
|
||||
const result = resolveDiscordSlashCommandConfig({ ephemeral: false });
|
||||
expect(result.ephemeral).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps ephemeral true when explicitly true", () => {
|
||||
const result = resolveDiscordSlashCommandConfig({ ephemeral: true });
|
||||
expect(result.ephemeral).toBe(true);
|
||||
});
|
||||
});
|
||||
9
src/discord/monitor/commands.ts
Normal file
9
src/discord/monitor/commands.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { DiscordSlashCommandConfig } from "../../config/types.discord.js";
|
||||
|
||||
export function resolveDiscordSlashCommandConfig(
|
||||
raw?: DiscordSlashCommandConfig,
|
||||
): Required<DiscordSlashCommandConfig> {
|
||||
return {
|
||||
ephemeral: raw?.ephemeral !== false,
|
||||
};
|
||||
}
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
createDiscordComponentStringSelect,
|
||||
createDiscordComponentUserSelect,
|
||||
} from "./agent-components.js";
|
||||
import { resolveDiscordSlashCommandConfig } from "./commands.js";
|
||||
import { createExecApprovalButton, DiscordExecApprovalHandler } from "./exec-approvals.js";
|
||||
import { createDiscordGatewayPlugin } from "./gateway-plugin.js";
|
||||
import { registerGateway, unregisterGateway } from "./gateway-registry.js";
|
||||
@@ -246,8 +247,9 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
const slashCommand = resolveDiscordSlashCommandConfig(discordCfg.slashCommand);
|
||||
const sessionPrefix = "discord:slash";
|
||||
const ephemeralDefault = true;
|
||||
const ephemeralDefault = slashCommand.ephemeral;
|
||||
const voiceEnabled = discordCfg.voice?.enabled !== false;
|
||||
|
||||
if (token) {
|
||||
|
||||
Reference in New Issue
Block a user