mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 04:16:25 +00:00
refactor: share delimited channel entry parsing
This commit is contained in:
@@ -81,6 +81,32 @@ describe("resolveDefaultIrcAccountId", () => {
|
||||
});
|
||||
|
||||
describe("resolveIrcAccount", () => {
|
||||
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";
|
||||
|
||||
try {
|
||||
const account = resolveIrcAccount({
|
||||
cfg: asConfig({
|
||||
channels: {
|
||||
irc: {
|
||||
host: "irc.example.com",
|
||||
nick: "claw",
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
expect(account.config.channels).toEqual(["alpha", "beta", "gamma", "delta"]);
|
||||
} finally {
|
||||
if (previousChannels === undefined) {
|
||||
delete process.env.IRC_CHANNELS;
|
||||
} else {
|
||||
process.env.IRC_CHANNELS = previousChannels;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")("rejects symlinked password files", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-irc-account-"));
|
||||
const passwordFile = path.join(dir, "password.txt");
|
||||
|
||||
@@ -3,6 +3,7 @@ import { tryReadSecretFileSync } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
createAccountListHelpers,
|
||||
normalizeResolvedSecretInputString,
|
||||
parseOptionalDelimitedEntries,
|
||||
} from "openclaw/plugin-sdk/irc";
|
||||
import type { CoreConfig, IrcAccountConfig, IrcNickServConfig } from "./types.js";
|
||||
|
||||
@@ -42,17 +43,6 @@ function parseIntEnv(value?: string): number | undefined {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function parseListEnv(value?: string): string[] | undefined {
|
||||
if (!value?.trim()) {
|
||||
return undefined;
|
||||
}
|
||||
const parsed = value
|
||||
.split(/[\n,;]+/g)
|
||||
.map((entry) => entry.trim())
|
||||
.filter(Boolean);
|
||||
return parsed.length > 0 ? parsed : undefined;
|
||||
}
|
||||
|
||||
const { listAccountIds: listIrcAccountIds, resolveDefaultAccountId: resolveDefaultIrcAccountId } =
|
||||
createAccountListHelpers("irc", { normalizeAccountId });
|
||||
export { listIrcAccountIds, resolveDefaultIrcAccountId };
|
||||
@@ -174,7 +164,9 @@ export function resolveIrcAccount(params: {
|
||||
accountId === DEFAULT_ACCOUNT_ID ? parseIntEnv(process.env.IRC_PORT) : undefined;
|
||||
const port = merged.port ?? envPort ?? (tls ? 6697 : 6667);
|
||||
const envChannels =
|
||||
accountId === DEFAULT_ACCOUNT_ID ? parseListEnv(process.env.IRC_CHANNELS) : undefined;
|
||||
accountId === DEFAULT_ACCOUNT_ID
|
||||
? parseOptionalDelimitedEntries(process.env.IRC_CHANNELS)
|
||||
: undefined;
|
||||
|
||||
const host = (
|
||||
merged.host?.trim() ||
|
||||
|
||||
Reference in New Issue
Block a user