refactor(discord): dedupe onboarding config patching

This commit is contained in:
Peter Steinberger
2026-02-15 13:14:50 +00:00
parent 2944c7d6af
commit 360b73bbb8

View File

@@ -55,10 +55,10 @@ async function noteDiscordTokenHelp(prompter: WizardPrompter): Promise<void> {
);
}
function setDiscordGroupPolicy(
function patchDiscordConfigForAccount(
cfg: OpenClawConfig,
accountId: string,
groupPolicy: "open" | "allowlist" | "disabled",
patch: Record<string, unknown>,
): OpenClawConfig {
if (accountId === DEFAULT_ACCOUNT_ID) {
return {
@@ -68,7 +68,7 @@ function setDiscordGroupPolicy(
discord: {
...cfg.channels?.discord,
enabled: true,
groupPolicy,
...patch,
},
},
};
@@ -85,7 +85,7 @@ function setDiscordGroupPolicy(
[accountId]: {
...cfg.channels?.discord?.accounts?.[accountId],
enabled: cfg.channels?.discord?.accounts?.[accountId]?.enabled ?? true,
groupPolicy,
...patch,
},
},
},
@@ -93,6 +93,14 @@ function setDiscordGroupPolicy(
};
}
function setDiscordGroupPolicy(
cfg: OpenClawConfig,
accountId: string,
groupPolicy: "open" | "allowlist" | "disabled",
): OpenClawConfig {
return patchDiscordConfigForAccount(cfg, accountId, { groupPolicy });
}
function setDiscordGuildChannelAllowlist(
cfg: OpenClawConfig,
accountId: string,
@@ -117,37 +125,7 @@ function setDiscordGuildChannelAllowlist(
guilds[guildKey] = existing;
}
}
if (accountId === DEFAULT_ACCOUNT_ID) {
return {
...cfg,
channels: {
...cfg.channels,
discord: {
...cfg.channels?.discord,
enabled: true,
guilds,
},
},
};
}
return {
...cfg,
channels: {
...cfg.channels,
discord: {
...cfg.channels?.discord,
enabled: true,
accounts: {
...cfg.channels?.discord?.accounts,
[accountId]: {
...cfg.channels?.discord?.accounts?.[accountId],
enabled: cfg.channels?.discord?.accounts?.[accountId]?.enabled ?? true,
guilds,
},
},
},
},
};
return patchDiscordConfigForAccount(cfg, accountId, { guilds });
}
function setDiscordAllowFrom(cfg: OpenClawConfig, allowFrom: string[]): OpenClawConfig {