mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:21:24 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -56,7 +56,9 @@ export function applyChannelAccountConfig(params: {
|
||||
const accountId = normalizeAccountId(params.accountId);
|
||||
const plugin = getChannelPlugin(params.channel);
|
||||
const apply = plugin?.setup?.applyAccountConfig;
|
||||
if (!apply) return params.cfg;
|
||||
if (!apply) {
|
||||
return params.cfg;
|
||||
}
|
||||
const input: ChannelSetupInput = {
|
||||
name: params.name,
|
||||
token: params.token,
|
||||
|
||||
@@ -52,7 +52,9 @@ export type ChannelsAddOptions = {
|
||||
};
|
||||
|
||||
function parseList(value: string | undefined): string[] | undefined {
|
||||
if (!value?.trim()) return undefined;
|
||||
if (!value?.trim()) {
|
||||
return undefined;
|
||||
}
|
||||
const parsed = value
|
||||
.split(/[\n,;]+/g)
|
||||
.map((entry) => entry.trim())
|
||||
@@ -62,10 +64,14 @@ function parseList(value: string | undefined): string[] | undefined {
|
||||
|
||||
function resolveCatalogChannelEntry(raw: string, cfg: OpenClawConfig | null) {
|
||||
const trimmed = raw.trim().toLowerCase();
|
||||
if (!trimmed) return undefined;
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
const workspaceDir = cfg ? resolveAgentWorkspaceDir(cfg, resolveDefaultAgentId(cfg)) : undefined;
|
||||
return listChannelPluginCatalogEntries({ workspaceDir }).find((entry) => {
|
||||
if (entry.id.toLowerCase() === trimmed) return true;
|
||||
if (entry.id.toLowerCase() === trimmed) {
|
||||
return true;
|
||||
}
|
||||
return (entry.meta.aliases ?? []).some((alias) => alias.trim().toLowerCase() === trimmed);
|
||||
});
|
||||
}
|
||||
@@ -76,7 +82,9 @@ export async function channelsAddCommand(
|
||||
params?: { hasFlags?: boolean },
|
||||
) {
|
||||
const cfg = await requireValidConfig(runtime);
|
||||
if (!cfg) return;
|
||||
if (!cfg) {
|
||||
return;
|
||||
}
|
||||
let nextConfig = cfg;
|
||||
|
||||
const useWizard = shouldUseWizard(params);
|
||||
@@ -149,7 +157,9 @@ export async function channelsAddCommand(
|
||||
workspaceDir,
|
||||
});
|
||||
nextConfig = result.cfg;
|
||||
if (!result.installed) return;
|
||||
if (!result.installed) {
|
||||
return;
|
||||
}
|
||||
reloadOnboardingPluginRegistry({ cfg: nextConfig, runtime, workspaceDir });
|
||||
channel = normalizeChannelId(catalogEntry.id) ?? (catalogEntry.id as ChannelId);
|
||||
}
|
||||
|
||||
@@ -67,34 +67,64 @@ const TEAMS_GRAPH_PERMISSION_HINTS: Record<string, string> = {
|
||||
|
||||
function normalizeTimeout(raw: unknown, fallback = 10_000) {
|
||||
const value = typeof raw === "string" ? Number(raw) : Number(raw);
|
||||
if (!Number.isFinite(value) || value <= 0) return fallback;
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
return fallback;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function formatSupport(capabilities?: ChannelCapabilities) {
|
||||
if (!capabilities) return "unknown";
|
||||
if (!capabilities) {
|
||||
return "unknown";
|
||||
}
|
||||
const bits: string[] = [];
|
||||
if (capabilities.chatTypes?.length) {
|
||||
bits.push(`chatTypes=${capabilities.chatTypes.join(",")}`);
|
||||
}
|
||||
if (capabilities.polls) bits.push("polls");
|
||||
if (capabilities.reactions) bits.push("reactions");
|
||||
if (capabilities.edit) bits.push("edit");
|
||||
if (capabilities.unsend) bits.push("unsend");
|
||||
if (capabilities.reply) bits.push("reply");
|
||||
if (capabilities.effects) bits.push("effects");
|
||||
if (capabilities.groupManagement) bits.push("groupManagement");
|
||||
if (capabilities.threads) bits.push("threads");
|
||||
if (capabilities.media) bits.push("media");
|
||||
if (capabilities.nativeCommands) bits.push("nativeCommands");
|
||||
if (capabilities.blockStreaming) bits.push("blockStreaming");
|
||||
if (capabilities.polls) {
|
||||
bits.push("polls");
|
||||
}
|
||||
if (capabilities.reactions) {
|
||||
bits.push("reactions");
|
||||
}
|
||||
if (capabilities.edit) {
|
||||
bits.push("edit");
|
||||
}
|
||||
if (capabilities.unsend) {
|
||||
bits.push("unsend");
|
||||
}
|
||||
if (capabilities.reply) {
|
||||
bits.push("reply");
|
||||
}
|
||||
if (capabilities.effects) {
|
||||
bits.push("effects");
|
||||
}
|
||||
if (capabilities.groupManagement) {
|
||||
bits.push("groupManagement");
|
||||
}
|
||||
if (capabilities.threads) {
|
||||
bits.push("threads");
|
||||
}
|
||||
if (capabilities.media) {
|
||||
bits.push("media");
|
||||
}
|
||||
if (capabilities.nativeCommands) {
|
||||
bits.push("nativeCommands");
|
||||
}
|
||||
if (capabilities.blockStreaming) {
|
||||
bits.push("blockStreaming");
|
||||
}
|
||||
return bits.length ? bits.join(" ") : "none";
|
||||
}
|
||||
|
||||
function summarizeDiscordTarget(raw?: string): DiscordTargetSummary | undefined {
|
||||
if (!raw) return undefined;
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const target = parseDiscordTarget(raw, { defaultKind: "channel" });
|
||||
if (!target) return { raw };
|
||||
if (!target) {
|
||||
return { raw };
|
||||
}
|
||||
if (target.kind === "channel") {
|
||||
return {
|
||||
raw,
|
||||
@@ -118,7 +148,9 @@ function formatDiscordIntents(intents?: {
|
||||
guildMembers?: string;
|
||||
presence?: string;
|
||||
}) {
|
||||
if (!intents) return "unknown";
|
||||
if (!intents) {
|
||||
return "unknown";
|
||||
}
|
||||
return [
|
||||
`messageContent=${intents.messageContent ?? "unknown"}`,
|
||||
`guildMembers=${intents.guildMembers ?? "unknown"}`,
|
||||
@@ -128,7 +160,9 @@ function formatDiscordIntents(intents?: {
|
||||
|
||||
function formatProbeLines(channelId: string, probe: unknown): string[] {
|
||||
const lines: string[] = [];
|
||||
if (!probe || typeof probe !== "object") return lines;
|
||||
if (!probe || typeof probe !== "object") {
|
||||
return lines;
|
||||
}
|
||||
const probeObj = probe as Record<string, unknown>;
|
||||
|
||||
if (channelId === "discord") {
|
||||
@@ -155,10 +189,18 @@ function formatProbeLines(channelId: string, probe: unknown): string[] {
|
||||
?.canReadAllGroupMessages;
|
||||
const inlineQueries = (bot as { supportsInlineQueries?: boolean | null })
|
||||
?.supportsInlineQueries;
|
||||
if (typeof canJoinGroups === "boolean") flags.push(`joinGroups=${canJoinGroups}`);
|
||||
if (typeof canReadAll === "boolean") flags.push(`readAllGroupMessages=${canReadAll}`);
|
||||
if (typeof inlineQueries === "boolean") flags.push(`inlineQueries=${inlineQueries}`);
|
||||
if (flags.length > 0) lines.push(`Flags: ${flags.join(" ")}`);
|
||||
if (typeof canJoinGroups === "boolean") {
|
||||
flags.push(`joinGroups=${canJoinGroups}`);
|
||||
}
|
||||
if (typeof canReadAll === "boolean") {
|
||||
flags.push(`readAllGroupMessages=${canReadAll}`);
|
||||
}
|
||||
if (typeof inlineQueries === "boolean") {
|
||||
flags.push(`inlineQueries=${inlineQueries}`);
|
||||
}
|
||||
if (flags.length > 0) {
|
||||
lines.push(`Flags: ${flags.join(" ")}`);
|
||||
}
|
||||
const webhook = probeObj.webhook as { url?: string | null } | undefined;
|
||||
if (webhook?.url !== undefined) {
|
||||
lines.push(`Webhook: ${webhook.url || "none"}`);
|
||||
@@ -186,7 +228,9 @@ function formatProbeLines(channelId: string, probe: unknown): string[] {
|
||||
|
||||
if (channelId === "msteams") {
|
||||
const appId = typeof probeObj.appId === "string" ? probeObj.appId.trim() : "";
|
||||
if (appId) lines.push(`App: ${theme.accent(appId)}`);
|
||||
if (appId) {
|
||||
lines.push(`App: ${theme.accent(appId)}`);
|
||||
}
|
||||
const graph = probeObj.graph as
|
||||
| { ok?: boolean; roles?: unknown; scopes?: unknown; error?: string }
|
||||
| undefined;
|
||||
@@ -239,7 +283,9 @@ async function buildDiscordPermissions(params: {
|
||||
target?: string;
|
||||
}): Promise<{ target?: DiscordTargetSummary; report?: DiscordPermissionsReport }> {
|
||||
const target = summarizeDiscordTarget(params.target?.trim());
|
||||
if (!target) return {};
|
||||
if (!target) {
|
||||
return {};
|
||||
}
|
||||
if (target.kind !== "channel" || !target.channelId) {
|
||||
return {
|
||||
target,
|
||||
@@ -395,7 +441,9 @@ export async function channelsCapabilitiesCommand(
|
||||
runtime: RuntimeEnv = defaultRuntime,
|
||||
) {
|
||||
const cfg = await requireValidConfig(runtime);
|
||||
if (!cfg) return;
|
||||
if (!cfg) {
|
||||
return;
|
||||
}
|
||||
const timeoutMs = normalizeTimeout(opts.timeout, 10_000);
|
||||
const rawChannel = typeof opts.channel === "string" ? opts.channel.trim().toLowerCase() : "";
|
||||
const rawTarget = typeof opts.target === "string" ? opts.target.trim() : "";
|
||||
@@ -417,7 +465,9 @@ export async function channelsCapabilitiesCommand(
|
||||
? plugins
|
||||
: (() => {
|
||||
const plugin = getChannelPlugin(rawChannel);
|
||||
if (!plugin) return null;
|
||||
if (!plugin) {
|
||||
return null;
|
||||
}
|
||||
return [plugin];
|
||||
})();
|
||||
|
||||
|
||||
@@ -15,8 +15,12 @@ export type ChannelsListOptions = {
|
||||
};
|
||||
|
||||
const colorValue = (value: string) => {
|
||||
if (value === "none") return theme.error(value);
|
||||
if (value === "env") return theme.accent(value);
|
||||
if (value === "none") {
|
||||
return theme.error(value);
|
||||
}
|
||||
if (value === "env") {
|
||||
return theme.accent(value);
|
||||
}
|
||||
return theme.success(value);
|
||||
};
|
||||
|
||||
@@ -101,7 +105,9 @@ export async function channelsListCommand(
|
||||
runtime: RuntimeEnv = defaultRuntime,
|
||||
) {
|
||||
const cfg = await requireValidConfig(runtime);
|
||||
if (!cfg) return;
|
||||
if (!cfg) {
|
||||
return;
|
||||
}
|
||||
const includeUsage = opts.usage !== false;
|
||||
|
||||
const plugins = listChannelPlugins();
|
||||
@@ -129,7 +135,9 @@ export async function channelsListCommand(
|
||||
|
||||
for (const plugin of plugins) {
|
||||
const accounts = plugin.config.listAccountIds(cfg);
|
||||
if (!accounts || accounts.length === 0) continue;
|
||||
if (!accounts || accounts.length === 0) {
|
||||
continue;
|
||||
}
|
||||
for (const accountId of accounts) {
|
||||
const snapshot = await buildChannelAccountSnapshot({
|
||||
plugin,
|
||||
|
||||
@@ -21,32 +21,46 @@ const getChannelSet = () =>
|
||||
|
||||
function parseChannelFilter(raw?: string) {
|
||||
const trimmed = raw?.trim().toLowerCase();
|
||||
if (!trimmed) return "all";
|
||||
if (!trimmed) {
|
||||
return "all";
|
||||
}
|
||||
return getChannelSet().has(trimmed) ? trimmed : "all";
|
||||
}
|
||||
|
||||
function matchesChannel(line: NonNullable<LogLine>, channel: string) {
|
||||
if (channel === "all") return true;
|
||||
if (channel === "all") {
|
||||
return true;
|
||||
}
|
||||
const needle = `gateway/channels/${channel}`;
|
||||
if (line.subsystem?.includes(needle)) return true;
|
||||
if (line.module?.includes(channel)) return true;
|
||||
if (line.subsystem?.includes(needle)) {
|
||||
return true;
|
||||
}
|
||||
if (line.module?.includes(channel)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function readTailLines(file: string, limit: number): Promise<string[]> {
|
||||
const stat = await fs.stat(file).catch(() => null);
|
||||
if (!stat) return [];
|
||||
if (!stat) {
|
||||
return [];
|
||||
}
|
||||
const size = stat.size;
|
||||
const start = Math.max(0, size - MAX_BYTES);
|
||||
const handle = await fs.open(file, "r");
|
||||
try {
|
||||
const length = Math.max(0, size - start);
|
||||
if (length === 0) return [];
|
||||
if (length === 0) {
|
||||
return [];
|
||||
}
|
||||
const buffer = Buffer.alloc(length);
|
||||
const readResult = await handle.read(buffer, 0, length, start);
|
||||
const text = buffer.toString("utf8", 0, readResult.bytesRead);
|
||||
let lines = text.split("\n");
|
||||
if (start > 0) lines = lines.slice(1);
|
||||
if (start > 0) {
|
||||
lines = lines.slice(1);
|
||||
}
|
||||
if (lines.length && lines[lines.length - 1] === "") {
|
||||
lines = lines.slice(0, -1);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ export type ChannelsRemoveOptions = {
|
||||
|
||||
function listAccountIds(cfg: OpenClawConfig, channel: ChatChannel): string[] {
|
||||
const plugin = getChannelPlugin(channel);
|
||||
if (!plugin) return [];
|
||||
if (!plugin) {
|
||||
return [];
|
||||
}
|
||||
return plugin.config.listAccountIds(cfg);
|
||||
}
|
||||
|
||||
@@ -28,7 +30,9 @@ export async function channelsRemoveCommand(
|
||||
params?: { hasFlags?: boolean },
|
||||
) {
|
||||
const cfg = await requireValidConfig(runtime);
|
||||
if (!cfg) return;
|
||||
if (!cfg) {
|
||||
return;
|
||||
}
|
||||
|
||||
const useWizard = shouldUseWizard(params);
|
||||
const prompter = useWizard ? createClackPrompter() : null;
|
||||
|
||||
@@ -25,17 +25,29 @@ type ResolveResult = {
|
||||
function resolvePreferredKind(
|
||||
kind?: ChannelsResolveOptions["kind"],
|
||||
): ChannelResolveKind | undefined {
|
||||
if (!kind || kind === "auto") return undefined;
|
||||
if (kind === "user") return "user";
|
||||
if (!kind || kind === "auto") {
|
||||
return undefined;
|
||||
}
|
||||
if (kind === "user") {
|
||||
return "user";
|
||||
}
|
||||
return "group";
|
||||
}
|
||||
|
||||
function detectAutoKind(input: string): ChannelResolveKind {
|
||||
const trimmed = input.trim();
|
||||
if (!trimmed) return "group";
|
||||
if (trimmed.startsWith("@")) return "user";
|
||||
if (/^<@!?/.test(trimmed)) return "user";
|
||||
if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmed)) return "user";
|
||||
if (!trimmed) {
|
||||
return "group";
|
||||
}
|
||||
if (trimmed.startsWith("@")) {
|
||||
return "user";
|
||||
}
|
||||
if (/^<@!?/.test(trimmed)) {
|
||||
return "user";
|
||||
}
|
||||
if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmed)) {
|
||||
return "user";
|
||||
}
|
||||
if (
|
||||
/^(user|discord|slack|matrix|msteams|teams|zalo|zalouser|googlechat|google-chat|gchat):/i.test(
|
||||
trimmed,
|
||||
@@ -47,7 +59,9 @@ function detectAutoKind(input: string): ChannelResolveKind {
|
||||
}
|
||||
|
||||
function formatResolveResult(result: ResolveResult): string {
|
||||
if (!result.resolved || !result.id) return `${result.input} -> unresolved`;
|
||||
if (!result.resolved || !result.id) {
|
||||
return `${result.input} -> unresolved`;
|
||||
}
|
||||
const name = result.name ? ` (${result.name})` : "";
|
||||
const note = result.note ? ` [${result.note}]` : "";
|
||||
return `${result.input} -> ${result.id}${name}${note}`;
|
||||
|
||||
@@ -25,7 +25,9 @@ export async function requireValidConfig(
|
||||
|
||||
export function formatAccountLabel(params: { accountId: string; name?: string }) {
|
||||
const base = params.accountId || DEFAULT_ACCOUNT_ID;
|
||||
if (params.name?.trim()) return `${base} (${params.name.trim()})`;
|
||||
if (params.name?.trim()) {
|
||||
return `${base} (${params.name.trim()})`;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,12 @@ export function formatGatewayChannelsStatusLines(payload: Record<string, unknown
|
||||
typeof account.lastOutboundAt === "number" && Number.isFinite(account.lastOutboundAt)
|
||||
? account.lastOutboundAt
|
||||
: null;
|
||||
if (inboundAt) bits.push(`in:${formatAge(Date.now() - inboundAt)}`);
|
||||
if (outboundAt) bits.push(`out:${formatAge(Date.now() - outboundAt)}`);
|
||||
if (inboundAt) {
|
||||
bits.push(`in:${formatAge(Date.now() - inboundAt)}`);
|
||||
}
|
||||
if (outboundAt) {
|
||||
bits.push(`out:${formatAge(Date.now() - outboundAt)}`);
|
||||
}
|
||||
if (typeof account.mode === "string" && account.mode.length > 0) {
|
||||
bits.push(`mode:${account.mode}`);
|
||||
}
|
||||
@@ -56,9 +60,13 @@ export function formatGatewayChannelsStatusLines(payload: Record<string, unknown
|
||||
const bot = account.bot as { username?: string | null } | undefined;
|
||||
const probeBot = (account.probe as { bot?: { username?: string | null } } | undefined)?.bot;
|
||||
const raw = bot?.username ?? probeBot?.username ?? "";
|
||||
if (typeof raw !== "string") return "";
|
||||
if (typeof raw !== "string") {
|
||||
return "";
|
||||
}
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) return "";
|
||||
if (!trimmed) {
|
||||
return "";
|
||||
}
|
||||
return trimmed.startsWith("@") ? trimmed : `@${trimmed}`;
|
||||
})();
|
||||
if (botUsername) {
|
||||
@@ -164,7 +172,9 @@ async function formatConfigChannelsStatusLines(
|
||||
if (meta.mode) {
|
||||
lines.push(`Mode: ${meta.mode}`);
|
||||
}
|
||||
if (meta.path || meta.mode) lines.push("");
|
||||
if (meta.path || meta.mode) {
|
||||
lines.push("");
|
||||
}
|
||||
|
||||
const accountLines = (provider: ChatChannel, accounts: Array<Record<string, unknown>>) =>
|
||||
accounts.map((account) => {
|
||||
@@ -206,7 +216,9 @@ async function formatConfigChannelsStatusLines(
|
||||
const plugins = listChannelPlugins();
|
||||
for (const plugin of plugins) {
|
||||
const accountIds = plugin.config.listAccountIds(cfg);
|
||||
if (!accountIds.length) continue;
|
||||
if (!accountIds.length) {
|
||||
continue;
|
||||
}
|
||||
const snapshots: ChannelAccountSnapshot[] = [];
|
||||
for (const accountId of accountIds) {
|
||||
const snapshot = await buildChannelAccountSnapshot({
|
||||
@@ -235,7 +247,9 @@ export async function channelsStatusCommand(
|
||||
const timeoutMs = Number(opts.timeout ?? 10_000);
|
||||
const statusLabel = opts.probe ? "Checking channel status (probe)…" : "Checking channel status…";
|
||||
const shouldLogStatus = opts.json !== true && !process.stderr.isTTY;
|
||||
if (shouldLogStatus) runtime.log(statusLabel);
|
||||
if (shouldLogStatus) {
|
||||
runtime.log(statusLabel);
|
||||
}
|
||||
try {
|
||||
const payload = await withProgress(
|
||||
{
|
||||
@@ -258,7 +272,9 @@ export async function channelsStatusCommand(
|
||||
} catch (err) {
|
||||
runtime.error(`Gateway not reachable: ${String(err)}`);
|
||||
const cfg = await requireValidConfig(runtime);
|
||||
if (!cfg) return;
|
||||
if (!cfg) {
|
||||
return;
|
||||
}
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
const mode = cfg.gateway?.mode === "remote" ? "remote" : "local";
|
||||
runtime.log(
|
||||
|
||||
Reference in New Issue
Block a user