From 31d1ed351f6ee97c78b99dcdff7d6fe8b0481bde Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 01:47:52 +0000 Subject: [PATCH] refactor(channels): dedupe status account bits --- src/commands/channels/status.ts | 92 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/src/commands/channels/status.ts b/src/commands/channels/status.ts index be1e3bb9f..28debb7e4 100644 --- a/src/commands/channels/status.ts +++ b/src/commands/channels/status.ts @@ -18,21 +18,49 @@ export type ChannelsStatusOptions = { timeout?: string; }; +function appendEnabledConfiguredLinkedBits(bits: string[], account: Record) { + if (typeof account.enabled === "boolean") { + bits.push(account.enabled ? "enabled" : "disabled"); + } + if (typeof account.configured === "boolean") { + bits.push(account.configured ? "configured" : "not configured"); + } + if (typeof account.linked === "boolean") { + bits.push(account.linked ? "linked" : "not linked"); + } +} + +function appendModeBit(bits: string[], account: Record) { + if (typeof account.mode === "string" && account.mode.length > 0) { + bits.push(`mode:${account.mode}`); + } +} + +function appendTokenSourceBits(bits: string[], account: Record) { + if (typeof account.tokenSource === "string" && account.tokenSource) { + bits.push(`token:${account.tokenSource}`); + } + if (typeof account.botTokenSource === "string" && account.botTokenSource) { + bits.push(`bot:${account.botTokenSource}`); + } + if (typeof account.appTokenSource === "string" && account.appTokenSource) { + bits.push(`app:${account.appTokenSource}`); + } +} + +function appendBaseUrlBit(bits: string[], account: Record) { + if (typeof account.baseUrl === "string" && account.baseUrl) { + bits.push(`url:${account.baseUrl}`); + } +} + export function formatGatewayChannelsStatusLines(payload: Record): string[] { const lines: string[] = []; lines.push(theme.success("Gateway reachable.")); const accountLines = (provider: ChatChannel, accounts: Array>) => accounts.map((account) => { const bits: string[] = []; - if (typeof account.enabled === "boolean") { - bits.push(account.enabled ? "enabled" : "disabled"); - } - if (typeof account.configured === "boolean") { - bits.push(account.configured ? "configured" : "not configured"); - } - if (typeof account.linked === "boolean") { - bits.push(account.linked ? "linked" : "not linked"); - } + appendEnabledConfiguredLinkedBits(bits, account); if (typeof account.running === "boolean") { bits.push(account.running ? "running" : "stopped"); } @@ -53,9 +81,7 @@ export function formatGatewayChannelsStatusLines(payload: Record 0) { - bits.push(`mode:${account.mode}`); - } + appendModeBit(bits, account); const botUsername = (() => { const bot = account.bot as { username?: string | null } | undefined; const probeBot = (account.probe as { bot?: { username?: string | null } } | undefined)?.bot; @@ -78,15 +104,7 @@ export function formatGatewayChannelsStatusLines(payload: Record 0) { bits.push(`allow:${account.allowFrom.slice(0, 2).join(",")}`); } - if (typeof account.tokenSource === "string" && account.tokenSource) { - bits.push(`token:${account.tokenSource}`); - } - if (typeof account.botTokenSource === "string" && account.botTokenSource) { - bits.push(`bot:${account.botTokenSource}`); - } - if (typeof account.appTokenSource === "string" && account.appTokenSource) { - bits.push(`app:${account.appTokenSource}`); - } + appendTokenSourceBits(bits, account); const application = account.application as | { intents?: { messageContent?: string } } | undefined; @@ -101,9 +119,7 @@ export function formatGatewayChannelsStatusLines(payload: Record>) => accounts.map((account) => { const bits: string[] = []; - if (typeof account.enabled === "boolean") { - bits.push(account.enabled ? "enabled" : "disabled"); - } - if (typeof account.configured === "boolean") { - bits.push(account.configured ? "configured" : "not configured"); - } - if (typeof account.linked === "boolean") { - bits.push(account.linked ? "linked" : "not linked"); - } - if (typeof account.mode === "string" && account.mode.length > 0) { - bits.push(`mode:${account.mode}`); - } - if (typeof account.tokenSource === "string" && account.tokenSource) { - bits.push(`token:${account.tokenSource}`); - } - if (typeof account.botTokenSource === "string" && account.botTokenSource) { - bits.push(`bot:${account.botTokenSource}`); - } - if (typeof account.appTokenSource === "string" && account.appTokenSource) { - bits.push(`app:${account.appTokenSource}`); - } - if (typeof account.baseUrl === "string" && account.baseUrl) { - bits.push(`url:${account.baseUrl}`); - } + appendEnabledConfiguredLinkedBits(bits, account); + appendModeBit(bits, account); + appendTokenSourceBits(bits, account); + appendBaseUrlBit(bits, account); const accountId = typeof account.accountId === "string" ? account.accountId : "default"; const name = typeof account.name === "string" ? account.name.trim() : ""; const labelText = formatChannelAccountLabel({