mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 22:55:24 +00:00
refactor: share normalized account lookups
This commit is contained in:
@@ -81,6 +81,29 @@ describe("resolveDefaultIrcAccountId", () => {
|
||||
});
|
||||
|
||||
describe("resolveIrcAccount", () => {
|
||||
it("matches normalized configured account ids", () => {
|
||||
const account = resolveIrcAccount({
|
||||
cfg: asConfig({
|
||||
channels: {
|
||||
irc: {
|
||||
accounts: {
|
||||
"Ops Team": {
|
||||
host: "irc.example.com",
|
||||
nick: "claw",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
accountId: "ops-team",
|
||||
});
|
||||
|
||||
expect(account.accountId).toBe("ops-team");
|
||||
expect(account.host).toBe("irc.example.com");
|
||||
expect(account.nick).toBe("claw");
|
||||
expect(account.configured).toBe(true);
|
||||
});
|
||||
|
||||
it("parses delimited IRC_CHANNELS env values for the default account", () => {
|
||||
const previousChannels = process.env.IRC_CHANNELS;
|
||||
process.env.IRC_CHANNELS = "alpha, beta\ngamma; delta";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createAccountListHelpers, mergeAccountConfig } from "openclaw/plugin-sdk/account-helpers";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||
import { resolveNormalizedAccountEntry } from "openclaw/plugin-sdk/account-resolution";
|
||||
import { parseOptionalDelimitedEntries } from "openclaw/plugin-sdk/core";
|
||||
import { tryReadSecretFileSync } from "openclaw/plugin-sdk/infra-runtime";
|
||||
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
||||
@@ -46,17 +47,11 @@ const { listAccountIds: listIrcAccountIds, resolveDefaultAccountId: resolveDefau
|
||||
export { listIrcAccountIds, resolveDefaultIrcAccountId };
|
||||
|
||||
function resolveAccountConfig(cfg: CoreConfig, accountId: string): IrcAccountConfig | undefined {
|
||||
const accounts = cfg.channels?.irc?.accounts;
|
||||
if (!accounts || typeof accounts !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const direct = accounts[accountId] as IrcAccountConfig | undefined;
|
||||
if (direct) {
|
||||
return direct;
|
||||
}
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === normalized);
|
||||
return matchKey ? (accounts[matchKey] as IrcAccountConfig | undefined) : undefined;
|
||||
return resolveNormalizedAccountEntry(
|
||||
cfg.channels?.irc?.accounts as Record<string, IrcAccountConfig> | undefined,
|
||||
accountId,
|
||||
normalizeAccountId,
|
||||
);
|
||||
}
|
||||
|
||||
function mergeIrcAccountConfig(cfg: CoreConfig, accountId: string): IrcAccountConfig {
|
||||
|
||||
Reference in New Issue
Block a user