mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 10:51:23 +00:00
refactor(auto-reply): dedupe allowlist path and name helpers
This commit is contained in:
@@ -29,6 +29,11 @@ import type { CommandHandler } from "./commands-types.js";
|
|||||||
type AllowlistScope = "dm" | "group" | "all";
|
type AllowlistScope = "dm" | "group" | "all";
|
||||||
type AllowlistAction = "list" | "add" | "remove";
|
type AllowlistAction = "list" | "add" | "remove";
|
||||||
type AllowlistTarget = "both" | "config" | "store";
|
type AllowlistTarget = "both" | "config" | "store";
|
||||||
|
type ResolvedAllowlistName = {
|
||||||
|
input: string;
|
||||||
|
resolved: boolean;
|
||||||
|
name?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
type AllowlistCommand =
|
type AllowlistCommand =
|
||||||
| {
|
| {
|
||||||
@@ -249,6 +254,11 @@ function resolveChannelAllowFromPaths(
|
|||||||
channelId: ChannelId,
|
channelId: ChannelId,
|
||||||
scope: AllowlistScope,
|
scope: AllowlistScope,
|
||||||
): string[] | null {
|
): string[] | null {
|
||||||
|
const supportsGroupAllowlist =
|
||||||
|
channelId === "telegram" ||
|
||||||
|
channelId === "whatsapp" ||
|
||||||
|
channelId === "signal" ||
|
||||||
|
channelId === "imessage";
|
||||||
if (scope === "all") {
|
if (scope === "all") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -257,23 +267,13 @@ function resolveChannelAllowFromPaths(
|
|||||||
// Canonical DM allowlist location for Slack/Discord. Legacy: dm.allowFrom.
|
// Canonical DM allowlist location for Slack/Discord. Legacy: dm.allowFrom.
|
||||||
return ["allowFrom"];
|
return ["allowFrom"];
|
||||||
}
|
}
|
||||||
if (
|
if (supportsGroupAllowlist) {
|
||||||
channelId === "telegram" ||
|
|
||||||
channelId === "whatsapp" ||
|
|
||||||
channelId === "signal" ||
|
|
||||||
channelId === "imessage"
|
|
||||||
) {
|
|
||||||
return ["allowFrom"];
|
return ["allowFrom"];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (scope === "group") {
|
if (scope === "group") {
|
||||||
if (
|
if (supportsGroupAllowlist) {
|
||||||
channelId === "telegram" ||
|
|
||||||
channelId === "whatsapp" ||
|
|
||||||
channelId === "signal" ||
|
|
||||||
channelId === "imessage"
|
|
||||||
) {
|
|
||||||
return ["groupAllowFrom"];
|
return ["groupAllowFrom"];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -281,6 +281,16 @@ function resolveChannelAllowFromPaths(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mapResolvedAllowlistNames(entries: ResolvedAllowlistName[]): Map<string, string> {
|
||||||
|
const map = new Map<string, string>();
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry.resolved && entry.name) {
|
||||||
|
map.set(entry.input, entry.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
async function resolveSlackNames(params: {
|
async function resolveSlackNames(params: {
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
accountId?: string | null;
|
accountId?: string | null;
|
||||||
@@ -292,13 +302,7 @@ async function resolveSlackNames(params: {
|
|||||||
return new Map<string, string>();
|
return new Map<string, string>();
|
||||||
}
|
}
|
||||||
const resolved = await resolveSlackUserAllowlist({ token, entries: params.entries });
|
const resolved = await resolveSlackUserAllowlist({ token, entries: params.entries });
|
||||||
const map = new Map<string, string>();
|
return mapResolvedAllowlistNames(resolved);
|
||||||
for (const entry of resolved) {
|
|
||||||
if (entry.resolved && entry.name) {
|
|
||||||
map.set(entry.input, entry.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolveDiscordNames(params: {
|
async function resolveDiscordNames(params: {
|
||||||
@@ -312,13 +316,7 @@ async function resolveDiscordNames(params: {
|
|||||||
return new Map<string, string>();
|
return new Map<string, string>();
|
||||||
}
|
}
|
||||||
const resolved = await resolveDiscordUserAllowlist({ token, entries: params.entries });
|
const resolved = await resolveDiscordUserAllowlist({ token, entries: params.entries });
|
||||||
const map = new Map<string, string>();
|
return mapResolvedAllowlistNames(resolved);
|
||||||
for (const entry of resolved) {
|
|
||||||
if (entry.resolved && entry.name) {
|
|
||||||
map.set(entry.input, entry.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleAllowlistCommand: CommandHandler = async (params, allowTextCommands) => {
|
export const handleAllowlistCommand: CommandHandler = async (params, allowTextCommands) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user