mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:58:26 +00:00
refactor: share sampled entry summary formatting
This commit is contained in:
@@ -43,6 +43,7 @@ import { createDiscordRetryRunner } from "../../infra/retry-policy.js";
|
||||
import { createSubsystemLogger } from "../../logging/subsystem.js";
|
||||
import { getPluginCommandSpecs } from "../../plugins/commands.js";
|
||||
import { createNonExitingRuntime, type RuntimeEnv } from "../../runtime.js";
|
||||
import { summarizeStringEntries } from "../../shared/string-sample.js";
|
||||
import { resolveDiscordAccount } from "../accounts.js";
|
||||
import { fetchDiscordApplicationId } from "../probe.js";
|
||||
import { normalizeDiscordToken } from "../token.js";
|
||||
@@ -103,25 +104,6 @@ export type MonitorDiscordOpts = {
|
||||
setStatus?: DiscordMonitorStatusSink;
|
||||
};
|
||||
|
||||
function summarizeAllowList(list?: string[]) {
|
||||
if (!list || list.length === 0) {
|
||||
return "any";
|
||||
}
|
||||
const sample = list.slice(0, 4).map((entry) => String(entry));
|
||||
const suffix = list.length > sample.length ? ` (+${list.length - sample.length})` : "";
|
||||
return `${sample.join(", ")}${suffix}`;
|
||||
}
|
||||
|
||||
function summarizeGuilds(entries?: Record<string, unknown>) {
|
||||
if (!entries || Object.keys(entries).length === 0) {
|
||||
return "any";
|
||||
}
|
||||
const keys = Object.keys(entries);
|
||||
const sample = keys.slice(0, 4);
|
||||
const suffix = keys.length > sample.length ? ` (+${keys.length - sample.length})` : "";
|
||||
return `${sample.join(", ")}${suffix}`;
|
||||
}
|
||||
|
||||
function formatThreadBindingDurationForConfigLabel(durationMs: number): string {
|
||||
const label = formatThreadBindingDurationLabel(durationMs);
|
||||
return label === "disabled" ? "off" : label;
|
||||
@@ -402,8 +384,23 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
allowFrom = allowlistResolved.allowFrom;
|
||||
|
||||
if (shouldLogVerbose()) {
|
||||
const allowFromSummary = summarizeStringEntries({
|
||||
entries: allowFrom ?? [],
|
||||
limit: 4,
|
||||
emptyText: "any",
|
||||
});
|
||||
const groupDmChannelSummary = summarizeStringEntries({
|
||||
entries: groupDmChannels ?? [],
|
||||
limit: 4,
|
||||
emptyText: "any",
|
||||
});
|
||||
const guildSummary = summarizeStringEntries({
|
||||
entries: Object.keys(guildEntries ?? {}),
|
||||
limit: 4,
|
||||
emptyText: "any",
|
||||
});
|
||||
logVerbose(
|
||||
`discord: config dm=${dmEnabled ? "on" : "off"} dmPolicy=${dmPolicy} allowFrom=${summarizeAllowList(allowFrom)} groupDm=${groupDmEnabled ? "on" : "off"} groupDmChannels=${summarizeAllowList(groupDmChannels)} groupPolicy=${groupPolicy} guilds=${summarizeGuilds(guildEntries)} historyLimit=${historyLimit} mediaMaxMb=${Math.round(mediaMaxBytes / (1024 * 1024))} native=${nativeEnabled ? "on" : "off"} nativeSkills=${nativeSkillsEnabled ? "on" : "off"} accessGroups=${useAccessGroups ? "on" : "off"} threadBindings=${threadBindingsEnabled ? "on" : "off"} threadIdleTimeout=${formatThreadBindingDurationForConfigLabel(threadBindingIdleTimeoutMs)} threadMaxAge=${formatThreadBindingDurationForConfigLabel(threadBindingMaxAgeMs)}`,
|
||||
`discord: config dm=${dmEnabled ? "on" : "off"} dmPolicy=${dmPolicy} allowFrom=${allowFromSummary} groupDm=${groupDmEnabled ? "on" : "off"} groupDmChannels=${groupDmChannelSummary} groupPolicy=${groupPolicy} guilds=${guildSummary} historyLimit=${historyLimit} mediaMaxMb=${Math.round(mediaMaxBytes / (1024 * 1024))} native=${nativeEnabled ? "on" : "off"} nativeSkills=${nativeSkillsEnabled ? "on" : "off"} accessGroups=${useAccessGroups ? "on" : "off"} threadBindings=${threadBindingsEnabled ? "on" : "off"} threadIdleTimeout=${formatThreadBindingDurationForConfigLabel(threadBindingIdleTimeoutMs)} threadMaxAge=${formatThreadBindingDurationForConfigLabel(threadBindingMaxAgeMs)}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user