fix(actions): layer per-account gate fallback

This commit is contained in:
Sebastian
2026-02-16 20:59:23 -05:00
parent 616c0bd4c7
commit 2b3ecee7c5
10 changed files with 203 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
import { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
import type { OpenClawConfig } from "../config/config.js";
import type { DiscordAccountConfig } from "../config/types.js";
import type { DiscordAccountConfig, DiscordActionConfig } from "../config/types.js";
import { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
import { normalizeAccountId } from "../routing/session-key.js";
import { resolveDiscordToken } from "./token.js";
@@ -36,6 +36,26 @@ function mergeDiscordAccountConfig(cfg: OpenClawConfig, accountId: string): Disc
return { ...base, ...account };
}
export function createDiscordActionGate(params: {
cfg: OpenClawConfig;
accountId?: string | null;
}): (key: keyof DiscordActionConfig, defaultValue?: boolean) => boolean {
const accountId = normalizeAccountId(params.accountId);
const baseActions = params.cfg.channels?.discord?.actions;
const accountActions = resolveAccountConfig(params.cfg, accountId)?.actions;
return (key, defaultValue = true) => {
const accountValue = accountActions?.[key];
if (accountValue !== undefined) {
return accountValue;
}
const baseValue = baseActions?.[key];
if (baseValue !== undefined) {
return baseValue;
}
return defaultValue;
};
}
export function resolveDiscordAccount(params: {
cfg: OpenClawConfig;
accountId?: string | null;