mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 06:02:45 +00:00
refactor(line): share command authorization gate logic
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
|||||||
isSenderAllowed,
|
isSenderAllowed,
|
||||||
normalizeAllowFrom,
|
normalizeAllowFrom,
|
||||||
normalizeDmAllowFromWithStore,
|
normalizeDmAllowFromWithStore,
|
||||||
|
type NormalizedAllowFrom,
|
||||||
} from "./bot-access.js";
|
} from "./bot-access.js";
|
||||||
import {
|
import {
|
||||||
getLineSourceInfo,
|
getLineSourceInfo,
|
||||||
@@ -350,17 +351,15 @@ async function shouldProcessLineEvent(
|
|||||||
return denied;
|
return denied;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const allowForCommands = effectiveGroupAllow;
|
return {
|
||||||
const senderAllowedForCommands = isSenderAllowed({ allow: allowForCommands, senderId });
|
allowed: true,
|
||||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
commandAuthorized: resolveLineCommandAuthorized({
|
||||||
const rawText = resolveEventRawText(event);
|
cfg,
|
||||||
const commandGate = resolveControlCommandGate({
|
event,
|
||||||
useAccessGroups,
|
senderId,
|
||||||
authorizers: [{ configured: allowForCommands.hasEntries, allowed: senderAllowedForCommands }],
|
allow: effectiveGroupAllow,
|
||||||
allowTextCommands: true,
|
}),
|
||||||
hasControlCommand: hasControlCommand(rawText, cfg),
|
};
|
||||||
});
|
|
||||||
return { allowed: true, commandAuthorized: commandGate.commandAuthorized };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmPolicy === "disabled") {
|
if (dmPolicy === "disabled") {
|
||||||
@@ -386,17 +385,15 @@ async function shouldProcessLineEvent(
|
|||||||
return denied;
|
return denied;
|
||||||
}
|
}
|
||||||
|
|
||||||
const allowForCommands = effectiveDmAllow;
|
return {
|
||||||
const senderAllowedForCommands = isSenderAllowed({ allow: allowForCommands, senderId });
|
allowed: true,
|
||||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
commandAuthorized: resolveLineCommandAuthorized({
|
||||||
const rawText = resolveEventRawText(event);
|
cfg,
|
||||||
const commandGate = resolveControlCommandGate({
|
event,
|
||||||
useAccessGroups,
|
senderId,
|
||||||
authorizers: [{ configured: allowForCommands.hasEntries, allowed: senderAllowedForCommands }],
|
allow: effectiveDmAllow,
|
||||||
allowTextCommands: true,
|
}),
|
||||||
hasControlCommand: hasControlCommand(rawText, cfg),
|
};
|
||||||
});
|
|
||||||
return { allowed: true, commandAuthorized: commandGate.commandAuthorized };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveEventRawText(event: MessageEvent | PostbackEvent): string {
|
function resolveEventRawText(event: MessageEvent | PostbackEvent): string {
|
||||||
@@ -413,6 +410,27 @@ function resolveEventRawText(event: MessageEvent | PostbackEvent): string {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveLineCommandAuthorized(params: {
|
||||||
|
cfg: OpenClawConfig;
|
||||||
|
event: MessageEvent | PostbackEvent;
|
||||||
|
senderId?: string;
|
||||||
|
allow: NormalizedAllowFrom;
|
||||||
|
}): boolean {
|
||||||
|
const senderAllowedForCommands = isSenderAllowed({
|
||||||
|
allow: params.allow,
|
||||||
|
senderId: params.senderId,
|
||||||
|
});
|
||||||
|
const useAccessGroups = params.cfg.commands?.useAccessGroups !== false;
|
||||||
|
const rawText = resolveEventRawText(params.event);
|
||||||
|
const commandGate = resolveControlCommandGate({
|
||||||
|
useAccessGroups,
|
||||||
|
authorizers: [{ configured: params.allow.hasEntries, allowed: senderAllowedForCommands }],
|
||||||
|
allowTextCommands: true,
|
||||||
|
hasControlCommand: hasControlCommand(rawText, params.cfg),
|
||||||
|
});
|
||||||
|
return commandGate.commandAuthorized;
|
||||||
|
}
|
||||||
|
|
||||||
async function handleMessageEvent(event: MessageEvent, context: LineHandlerContext): Promise<void> {
|
async function handleMessageEvent(event: MessageEvent, context: LineHandlerContext): Promise<void> {
|
||||||
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
||||||
const message = event.message;
|
const message = event.message;
|
||||||
|
|||||||
Reference in New Issue
Block a user