mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:48:28 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -5,8 +5,12 @@ export type MediaUnderstandingScopeDecision = "allow" | "deny";
|
||||
|
||||
function normalizeDecision(value?: string | null): MediaUnderstandingScopeDecision | undefined {
|
||||
const normalized = value?.trim().toLowerCase();
|
||||
if (normalized === "allow") return "allow";
|
||||
if (normalized === "deny") return "deny";
|
||||
if (normalized === "allow") {
|
||||
return "allow";
|
||||
}
|
||||
if (normalized === "deny") {
|
||||
return "deny";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -26,23 +30,33 @@ export function resolveMediaUnderstandingScope(params: {
|
||||
chatType?: string;
|
||||
}): MediaUnderstandingScopeDecision {
|
||||
const scope = params.scope;
|
||||
if (!scope) return "allow";
|
||||
if (!scope) {
|
||||
return "allow";
|
||||
}
|
||||
|
||||
const channel = normalizeMatch(params.channel);
|
||||
const chatType = normalizeMediaUnderstandingChatType(params.chatType);
|
||||
const sessionKey = normalizeMatch(params.sessionKey) ?? "";
|
||||
|
||||
for (const rule of scope.rules ?? []) {
|
||||
if (!rule) continue;
|
||||
if (!rule) {
|
||||
continue;
|
||||
}
|
||||
const action = normalizeDecision(rule.action) ?? "allow";
|
||||
const match = rule.match ?? {};
|
||||
const matchChannel = normalizeMatch(match.channel);
|
||||
const matchChatType = normalizeMediaUnderstandingChatType(match.chatType);
|
||||
const matchPrefix = normalizeMatch(match.keyPrefix);
|
||||
|
||||
if (matchChannel && matchChannel !== channel) continue;
|
||||
if (matchChatType && matchChatType !== chatType) continue;
|
||||
if (matchPrefix && !sessionKey.startsWith(matchPrefix)) continue;
|
||||
if (matchChannel && matchChannel !== channel) {
|
||||
continue;
|
||||
}
|
||||
if (matchChatType && matchChatType !== chatType) {
|
||||
continue;
|
||||
}
|
||||
if (matchPrefix && !sessionKey.startsWith(matchPrefix)) {
|
||||
continue;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user