mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-24 03:15:46 -06:00
b34bba8e57
* refactor(channels): migrate irc, nextcloud-talk, zalouser, slack, and matrix group policy onto the scope tree * fix(irc): drop unused tree binding in group match * fix(zalouser): keep wildcard lookup opt-in for explicit-only candidates * fix(zalouser): adapter opts into the wildcard fallback candidate * refactor(channels): migrate feishu, msteams, and discord group policy onto the scope tree and drop the core discord duplicate * fix(msteams): restore the cross-team scan fallback for policy-less matched teams * fix(feishu): keep the adapter's zod-typed group config for the scope tree * revert(core): keep the discord require-mention fallback until stage 3 makes it provably redundant * chore(matrix): drop the now-unused channel entry match re-export * refactor(telegram): migrate group policy onto the scope tree * test(telegram): keep the bot token fixture off secret-scanner patterns * test(telegram): use a computed key for the bot token fixture * test(telegram): assemble the bot token fixture indirectly for scanner and lint
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
// Irc plugin module implements policy behavior.
|
|
import {
|
|
resolveScopeKeyCaseInsensitive,
|
|
resolveScopeRequireMention,
|
|
resolveScopeToolsPolicy,
|
|
type GroupToolPolicyConfig,
|
|
type ScopeTree,
|
|
} from "openclaw/plugin-sdk/channel-policy";
|
|
import type { IrcChannelConfig } from "./types.js";
|
|
|
|
type IrcGroupMatch = {
|
|
allowed: boolean;
|
|
groupConfig?: IrcChannelConfig;
|
|
wildcardConfig?: IrcChannelConfig;
|
|
hasConfiguredGroups: boolean;
|
|
};
|
|
|
|
function resolveIrcGroupScope(params: {
|
|
groups?: Record<string, IrcChannelConfig>;
|
|
target: string;
|
|
}) {
|
|
const { "*": wildcard, ...groups } = params.groups ?? {};
|
|
// This adapter historically reads tools only; do not widen it to toolsBySender.
|
|
const project = (entry: IrcChannelConfig) => ({
|
|
requireMention: entry.requireMention,
|
|
tools: entry.tools,
|
|
});
|
|
const tree: ScopeTree = {
|
|
defaults: wildcard ? project(wildcard) : undefined,
|
|
scopes: Object.fromEntries(Object.entries(groups).map(([key, entry]) => [key, project(entry)])),
|
|
};
|
|
// Legacy IRC matching checks exact keys before case-insensitive keys;
|
|
// the canonical helper preserves that order.
|
|
const key = resolveScopeKeyCaseInsensitive(tree, params.target);
|
|
return { tree, path: key ? [key] : [] };
|
|
}
|
|
|
|
export function resolveIrcGroupMatch(params: {
|
|
groups?: Record<string, IrcChannelConfig>;
|
|
target: string;
|
|
}): IrcGroupMatch {
|
|
const { path } = resolveIrcGroupScope(params);
|
|
const key = path[0];
|
|
const groupConfig = key ? params.groups?.[key] : undefined;
|
|
const wildcardConfig = params.groups?.["*"];
|
|
return {
|
|
allowed: Boolean(groupConfig ?? wildcardConfig),
|
|
groupConfig,
|
|
wildcardConfig,
|
|
hasConfiguredGroups: Object.keys(params.groups ?? {}).length > 0,
|
|
};
|
|
}
|
|
|
|
export function resolveIrcGroupRequireMention(params: {
|
|
groups?: Record<string, IrcChannelConfig>;
|
|
target: string;
|
|
}): boolean {
|
|
const { tree, path } = resolveIrcGroupScope(params);
|
|
return resolveScopeRequireMention({ tree, path });
|
|
}
|
|
|
|
export function resolveIrcGroupToolPolicy(params: {
|
|
groups?: Record<string, IrcChannelConfig>;
|
|
target: string;
|
|
}): GroupToolPolicyConfig | undefined {
|
|
const { tree, path } = resolveIrcGroupScope(params);
|
|
return resolveScopeToolsPolicy({ tree, path });
|
|
}
|