mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:18:26 +00:00
fix(discord): dedupe native skill commands by skillName (#17365)
* fix(discord): dedupe native skill commands by skill name * Changelog: credit Discord skill dedupe --------- Co-authored-by: yume <yume@yumedeMacBook-Pro.local> Co-authored-by: Shadow <hi@shadowing.dev>
This commit is contained in:
26
src/discord/monitor/provider.skill-dedupe.test.ts
Normal file
26
src/discord/monitor/provider.skill-dedupe.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { __testing } from "./provider.js";
|
||||
|
||||
describe("dedupeSkillCommandsForDiscord", () => {
|
||||
it("keeps first command per skillName and drops suffix duplicates", () => {
|
||||
const input = [
|
||||
{ name: "github", skillName: "github", description: "GitHub" },
|
||||
{ name: "github_2", skillName: "github", description: "GitHub" },
|
||||
{ name: "weather", skillName: "weather", description: "Weather" },
|
||||
{ name: "weather_2", skillName: "weather", description: "Weather" },
|
||||
];
|
||||
|
||||
const output = __testing.dedupeSkillCommandsForDiscord(input);
|
||||
expect(output.map((entry) => entry.name)).toEqual(["github", "weather"]);
|
||||
});
|
||||
|
||||
it("treats skillName case-insensitively", () => {
|
||||
const input = [
|
||||
{ name: "ClawHub", skillName: "ClawHub", description: "ClawHub" },
|
||||
{ name: "clawhub_2", skillName: "clawhub", description: "ClawHub" },
|
||||
];
|
||||
const output = __testing.dedupeSkillCommandsForDiscord(input);
|
||||
expect(output).toHaveLength(1);
|
||||
expect(output[0]?.name).toBe("ClawHub");
|
||||
});
|
||||
});
|
||||
@@ -81,6 +81,26 @@ function summarizeGuilds(entries?: Record<string, unknown>) {
|
||||
return `${sample.join(", ")}${suffix}`;
|
||||
}
|
||||
|
||||
function dedupeSkillCommandsForDiscord(
|
||||
skillCommands: ReturnType<typeof listSkillCommandsForAgents>,
|
||||
) {
|
||||
const seen = new Set<string>();
|
||||
const deduped: ReturnType<typeof listSkillCommandsForAgents> = [];
|
||||
for (const command of skillCommands) {
|
||||
const key = command.skillName.trim().toLowerCase();
|
||||
if (!key) {
|
||||
deduped.push(command);
|
||||
continue;
|
||||
}
|
||||
if (seen.has(key)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(key);
|
||||
deduped.push(command);
|
||||
}
|
||||
return deduped;
|
||||
}
|
||||
|
||||
async function deployDiscordCommands(params: {
|
||||
client: Client;
|
||||
runtime: RuntimeEnv;
|
||||
@@ -355,7 +375,9 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
|
||||
const maxDiscordCommands = 100;
|
||||
let skillCommands =
|
||||
nativeEnabled && nativeSkillsEnabled ? listSkillCommandsForAgents({ cfg }) : [];
|
||||
nativeEnabled && nativeSkillsEnabled
|
||||
? dedupeSkillCommandsForDiscord(listSkillCommandsForAgents({ cfg }))
|
||||
: [];
|
||||
let commandSpecs = nativeEnabled
|
||||
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "discord" })
|
||||
: [];
|
||||
@@ -648,4 +670,5 @@ async function clearDiscordNativeCommands(params: {
|
||||
|
||||
export const __testing = {
|
||||
createDiscordGatewayPlugin,
|
||||
dedupeSkillCommandsForDiscord,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user