fix(discord): avoid native plugin command collisions

This commit is contained in:
Peter Steinberger
2026-03-07 21:59:12 +00:00
parent 4dcd930923
commit be9ea991de
9 changed files with 77 additions and 9 deletions

View File

@@ -77,12 +77,20 @@ function asTrimmedString(value: unknown): string {
return typeof value === "string" ? value.trim() : "";
}
function resolveCommandLabel(channel: string): string {
return channel === "discord" ? "/talkvoice" : "/voice";
}
export default function register(api: OpenClawPluginApi) {
api.registerCommand({
name: "voice",
nativeNames: {
discord: "talkvoice",
},
description: "List/set ElevenLabs Talk voice (affects iOS Talk playback).",
acceptsArgs: true,
handler: async (ctx) => {
const commandLabel = resolveCommandLabel(ctx.channel);
const args = ctx.args?.trim() ?? "";
const tokens = args.split(/\s+/).filter(Boolean);
const action = (tokens[0] ?? "status").toLowerCase();
@@ -118,13 +126,13 @@ export default function register(api: OpenClawPluginApi) {
if (action === "set") {
const query = tokens.slice(1).join(" ").trim();
if (!query) {
return { text: "Usage: /voice set <voiceId|name>" };
return { text: `Usage: ${commandLabel} set <voiceId|name>` };
}
const voices = await listVoices(apiKey);
const chosen = findVoice(voices, query);
if (!chosen) {
const hint = isLikelyVoiceId(query) ? query : `"${query}"`;
return { text: `No voice found for ${hint}. Try: /voice list` };
return { text: `No voice found for ${hint}. Try: ${commandLabel} list` };
}
const nextConfig = {
@@ -144,9 +152,9 @@ export default function register(api: OpenClawPluginApi) {
text: [
"Voice commands:",
"",
"/voice status",
"/voice list [limit]",
"/voice set <voiceId|name>",
`${commandLabel} status`,
`${commandLabel} list [limit]`,
`${commandLabel} set <voiceId|name>`,
].join("\n"),
};
},