diff --git a/plugin/tools/register-tools.ts b/plugin/tools/register-tools.ts index 71846f1..bf32af5 100644 --- a/plugin/tools/register-tools.ts +++ b/plugin/tools/register-tools.ts @@ -1,7 +1,7 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk"; import type { ChannelPolicy, DirigentConfig } from "../rules.js"; -type DiscordControlAction = "channel-private-create" | "channel-private-update" | "member-list" | "channel-member-list"; +type DiscordControlAction = "channel-private-create" | "channel-private-update" | "member-list"; const PERM_VIEW_CHANNEL = 1n << 10n; // 0x400 const PERM_ADMINISTRATOR = 1n << 3n; // 0x8 @@ -149,62 +149,6 @@ export function registerDirigentTools(deps: ToolDeps): void { return { content: [{ type: "text", text: JSON.stringify({ ok: true, accountId: selected.accountId, members }, null, 2) }] }; } - if (action === "channel-member-list") { - const channelId = String(params.channelId || "").trim(); - if (!channelId) return { content: [{ type: "text", text: "channelId is required" }], isError: true }; - - const ch = await discordRequest(token, "GET", `/channels/${channelId}`); - if (!ch.ok) return { content: [{ type: "text", text: `discord action failed (${ch.status}): ${ch.text}` }], isError: true }; - - const guildId = String(ch.json?.guild_id || ""); - if (!guildId) return { content: [{ type: "text", text: "channel has no guild_id (not a guild channel)" }], isError: true }; - - const rolesResp = await discordRequest(token, "GET", `/guilds/${guildId}/roles`); - if (!rolesResp.ok) return { content: [{ type: "text", text: `discord action failed (${rolesResp.status}): ${rolesResp.text}` }], isError: true }; - const rolePerms = new Map(); - for (const r of Array.isArray(rolesResp.json) ? rolesResp.json : []) { - rolePerms.set(String(r?.id || ""), toBigIntPerm(r?.permissions)); - } - - const members: any[] = []; - let after = ""; - while (true) { - const q = new URLSearchParams({ limit: "1000" }); - if (after) q.set("after", after); - const mResp = await discordRequest(token, "GET", `/guilds/${guildId}/members?${q.toString()}`); - if (!mResp.ok) return { content: [{ type: "text", text: `discord action failed (${mResp.status}): ${mResp.text}` }], isError: true }; - const batch = Array.isArray(mResp.json) ? mResp.json : []; - members.push(...batch); - if (batch.length < 1000) break; - after = String(batch[batch.length - 1]?.user?.id || ""); - if (!after) break; - } - - const overwrites = Array.isArray(ch.json?.permission_overwrites) ? ch.json.permission_overwrites : []; - const visible = members.filter((m) => canViewChannel(m, guildId, rolePerms, overwrites)); - - return { - content: [{ - type: "text", - text: JSON.stringify({ - ok: true, - accountId: selected.accountId, - channelId, - guildId, - totalGuildMembers: members.length, - visibleCount: visible.length, - members: visible.map((m) => ({ - userId: m?.user?.id, - username: m?.user?.username, - globalName: m?.user?.global_name, - nick: m?.nick, - roles: m?.roles || [], - })), - }, null, 2), - }], - }; - } - if (action === "channel-private-create") { const guildId = String(params.guildId || "").trim(); const name = String(params.name || "").trim(); @@ -353,26 +297,6 @@ export function registerDirigentTools(deps: ToolDeps): void { { optional: false }, ); - api.registerTool( - { - name: "dirigent_discord_channel_member_list", - description: "List effective visible members for a Discord channel by computing VIEW_CHANNEL permission.", - parameters: { - type: "object", - additionalProperties: false, - properties: { - accountId: { type: "string" }, - channelId: { type: "string" }, - }, - required: ["channelId"], - }, - async execute(_id: string, params: Record) { - return executeDiscordAction("channel-member-list", params); - }, - }, - { optional: false }, - ); - api.registerTool( { name: "dirigent_policy_get",