feat(tool): register optional discord_control tool in whispergate plugin and align defaults

This commit is contained in:
2026-02-25 23:37:15 +00:00
parent 7f1d6bb3f7
commit 0f526346f4
5 changed files with 154 additions and 11 deletions

View File

@@ -27,4 +27,20 @@ Optional:
- `enabled` (default true)
- `discordOnly` (default true)
- `bypassUserIds` (default [])
- `endSymbols` (default punctuation set)
- `endSymbols` (default ["🔚"])
- `enableDiscordControlTool` (default true)
- `discordControlApiBaseUrl` (default `http://127.0.0.1:8790`)
- `discordControlApiToken`
- `discordControlCallerId`
## Optional tool: `discord_control`
This plugin now registers an optional tool named `discord_control`.
To use it, add tool allowlist entry for either:
- tool name: `discord_control`
- plugin id: `whispergate`
Supported actions:
- `channel-private-create`
- `channel-private-update`
- `member-list`

View File

@@ -1,6 +1,8 @@
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
import { evaluateDecision, type Decision, type WhisperGateConfig } from "./rules.js";
type DiscordControlAction = "channel-private-create" | "channel-private-update" | "member-list";
type DecisionRecord = {
decision: Decision;
createdAt: number;
@@ -53,11 +55,103 @@ function shouldInjectEndMarker(reason: string): boolean {
return reason === "bypass_sender" || reason.startsWith("end_symbol:");
}
function pickDefined(input: Record<string, unknown>) {
const out: Record<string, unknown> = {};
for (const [k, v] of Object.entries(input)) {
if (v !== undefined) out[k] = v;
}
return out;
}
export default {
id: "whispergate",
name: "WhisperGate",
register(api: OpenClawPluginApi) {
const config = (api.pluginConfig || {}) as WhisperGateConfig;
const config = (api.pluginConfig || {}) as WhisperGateConfig & {
enableDiscordControlTool?: boolean;
discordControlApiBaseUrl?: string;
discordControlApiToken?: string;
discordControlCallerId?: string;
};
if (config.enableDiscordControlTool !== false) {
api.registerTool(
{
name: "discord_control",
description: "Discord admin extension actions: private channel create/update and member list.",
parameters: {
type: "object",
additionalProperties: false,
properties: {
action: {
type: "string",
enum: ["channel-private-create", "channel-private-update", "member-list"],
},
guildId: { type: "string" },
name: { type: "string" },
type: { type: "number" },
parentId: { type: "string" },
topic: { type: "string" },
position: { type: "number" },
nsfw: { type: "boolean" },
allowedUserIds: { type: "array", items: { type: "string" } },
allowedRoleIds: { type: "array", items: { type: "string" } },
allowMask: { type: "string" },
denyEveryoneMask: { type: "string" },
channelId: { type: "string" },
mode: { type: "string", enum: ["merge", "replace"] },
addUserIds: { type: "array", items: { type: "string" } },
addRoleIds: { type: "array", items: { type: "string" } },
removeTargetIds: { type: "array", items: { type: "string" } },
denyMask: { type: "string" },
limit: { type: "number" },
after: { type: "string" },
fields: { anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }] },
dryRun: { type: "boolean" },
},
required: ["action", "guildId"],
},
async execute(_id: string, params: Record<string, unknown>) {
const action = String(params.action || "") as DiscordControlAction;
const baseUrl = (config.discordControlApiBaseUrl || "http://127.0.0.1:8790").replace(/\/$/, "");
const body = pickDefined({ ...params, action });
const headers: Record<string, string> = { "Content-Type": "application/json" };
if (config.discordControlApiToken) headers.Authorization = `Bearer ${config.discordControlApiToken}`;
if (config.discordControlCallerId) headers["X-OpenClaw-Caller-Id"] = config.discordControlCallerId;
const r = await fetch(`${baseUrl}/v1/discord/action`, {
method: "POST",
headers,
body: JSON.stringify(body),
});
const text = await r.text();
if (!r.ok) {
return {
content: [
{
type: "text",
text: `discord_control failed (${r.status}): ${text}`,
},
],
isError: true,
};
}
return {
content: [
{
type: "text",
text,
},
],
};
},
},
{ optional: true },
);
}
api.registerHook("message:received", async (event, ctx) => {
try {

View File

@@ -11,9 +11,13 @@
"enabled": { "type": "boolean", "default": true },
"discordOnly": { "type": "boolean", "default": true },
"bypassUserIds": { "type": "array", "items": { "type": "string" }, "default": [] },
"endSymbols": { "type": "array", "items": { "type": "string" }, "default": ["。", "", "", ".", "!", "?"] },
"endSymbols": { "type": "array", "items": { "type": "string" }, "default": ["🔚"] },
"noReplyProvider": { "type": "string" },
"noReplyModel": { "type": "string" }
"noReplyModel": { "type": "string" },
"enableDiscordControlTool": { "type": "boolean", "default": true },
"discordControlApiBaseUrl": { "type": "string", "default": "http://127.0.0.1:8790" },
"discordControlApiToken": { "type": "string" },
"discordControlCallerId": { "type": "string" }
},
"required": ["noReplyProvider", "noReplyModel"]
}