fix: avoid Discord /tts conflict
This commit is contained in:
@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildCommandText,
|
||||
buildCommandTextFromArgs,
|
||||
findCommandByNativeName,
|
||||
getCommandDetection,
|
||||
listChatCommands,
|
||||
listChatCommandsForConfig,
|
||||
@@ -85,6 +86,16 @@ describe("commands registry", () => {
|
||||
expect(native.find((spec) => spec.name === "demo_skill")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("applies provider-specific native names", () => {
|
||||
const native = listNativeCommandSpecsForConfig(
|
||||
{ commands: { native: true } },
|
||||
{ provider: "discord" },
|
||||
);
|
||||
expect(native.find((spec) => spec.name === "voice")).toBeTruthy();
|
||||
expect(findCommandByNativeName("voice", "discord")?.key).toBe("tts");
|
||||
expect(findCommandByNativeName("tts", "discord")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("detects known text commands", () => {
|
||||
const detection = getCommandDetection();
|
||||
expect(detection.exact.has("/commands")).toBe(true);
|
||||
|
||||
@@ -105,13 +105,29 @@ export function listChatCommandsForConfig(
|
||||
return [...base, ...buildSkillCommandDefinitions(params.skillCommands)];
|
||||
}
|
||||
|
||||
const NATIVE_NAME_OVERRIDES: Record<string, Record<string, string>> = {
|
||||
discord: {
|
||||
tts: "voice",
|
||||
},
|
||||
};
|
||||
|
||||
function resolveNativeName(command: ChatCommandDefinition, provider?: string): string | undefined {
|
||||
if (!command.nativeName) return undefined;
|
||||
if (provider) {
|
||||
const override = NATIVE_NAME_OVERRIDES[provider]?.[command.key];
|
||||
if (override) return override;
|
||||
}
|
||||
return command.nativeName;
|
||||
}
|
||||
|
||||
export function listNativeCommandSpecs(params?: {
|
||||
skillCommands?: SkillCommandSpec[];
|
||||
provider?: string;
|
||||
}): NativeCommandSpec[] {
|
||||
return listChatCommands({ skillCommands: params?.skillCommands })
|
||||
.filter((command) => command.scope !== "text" && command.nativeName)
|
||||
.map((command) => ({
|
||||
name: command.nativeName ?? command.key,
|
||||
name: resolveNativeName(command, params?.provider) ?? command.key,
|
||||
description: command.description,
|
||||
acceptsArgs: Boolean(command.acceptsArgs),
|
||||
args: command.args,
|
||||
@@ -120,22 +136,27 @@ export function listNativeCommandSpecs(params?: {
|
||||
|
||||
export function listNativeCommandSpecsForConfig(
|
||||
cfg: ClawdbotConfig,
|
||||
params?: { skillCommands?: SkillCommandSpec[] },
|
||||
params?: { skillCommands?: SkillCommandSpec[]; provider?: string },
|
||||
): NativeCommandSpec[] {
|
||||
return listChatCommandsForConfig(cfg, params)
|
||||
.filter((command) => command.scope !== "text" && command.nativeName)
|
||||
.map((command) => ({
|
||||
name: command.nativeName ?? command.key,
|
||||
name: resolveNativeName(command, params?.provider) ?? command.key,
|
||||
description: command.description,
|
||||
acceptsArgs: Boolean(command.acceptsArgs),
|
||||
args: command.args,
|
||||
}));
|
||||
}
|
||||
|
||||
export function findCommandByNativeName(name: string): ChatCommandDefinition | undefined {
|
||||
export function findCommandByNativeName(
|
||||
name: string,
|
||||
provider?: string,
|
||||
): ChatCommandDefinition | undefined {
|
||||
const normalized = name.trim().toLowerCase();
|
||||
return getChatCommands().find(
|
||||
(command) => command.scope !== "text" && command.nativeName?.toLowerCase() === normalized,
|
||||
(command) =>
|
||||
command.scope !== "text" &&
|
||||
resolveNativeName(command, provider)?.toLowerCase() === normalized,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user