mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:11:22 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -9,7 +9,9 @@ import { isRich, theme } from "../terminal/theme.js";
|
||||
|
||||
const shortenText = (value: string, maxLen: number) => {
|
||||
const chars = Array.from(value);
|
||||
if (chars.length <= maxLen) return value;
|
||||
if (chars.length <= maxLen) {
|
||||
return value;
|
||||
}
|
||||
return `${chars.slice(0, Math.max(0, maxLen - 1)).join("")}…`;
|
||||
};
|
||||
|
||||
@@ -17,13 +19,19 @@ const resolveChannelLabel = (channel: ChannelId) =>
|
||||
getChannelPlugin(channel)?.meta.label ?? channel;
|
||||
|
||||
function extractMessageId(payload: unknown): string | null {
|
||||
if (!payload || typeof payload !== "object") return null;
|
||||
if (!payload || typeof payload !== "object") {
|
||||
return null;
|
||||
}
|
||||
const direct = (payload as { messageId?: unknown }).messageId;
|
||||
if (typeof direct === "string" && direct.trim()) return direct.trim();
|
||||
if (typeof direct === "string" && direct.trim()) {
|
||||
return direct.trim();
|
||||
}
|
||||
const result = (payload as { result?: unknown }).result;
|
||||
if (result && typeof result === "object") {
|
||||
const nested = (result as { messageId?: unknown }).messageId;
|
||||
if (typeof nested === "string" && nested.trim()) return nested.trim();
|
||||
if (typeof nested === "string" && nested.trim()) {
|
||||
return nested.trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -56,7 +64,9 @@ function renderObjectSummary(payload: unknown, opts: FormatOpts): string[] {
|
||||
}
|
||||
const obj = payload as Record<string, unknown>;
|
||||
const keys = Object.keys(obj);
|
||||
if (keys.length === 0) return [theme.muted("(empty)")];
|
||||
if (keys.length === 0) {
|
||||
return [theme.muted("(empty)")];
|
||||
}
|
||||
|
||||
const rows = keys.slice(0, 20).map((k) => {
|
||||
const v = obj[k];
|
||||
@@ -145,23 +155,35 @@ function renderMessageList(messages: unknown[], opts: FormatOpts, emptyLabel: st
|
||||
}
|
||||
|
||||
function renderMessagesFromPayload(payload: unknown, opts: FormatOpts): string[] | null {
|
||||
if (!payload || typeof payload !== "object") return null;
|
||||
if (!payload || typeof payload !== "object") {
|
||||
return null;
|
||||
}
|
||||
const messages = (payload as { messages?: unknown }).messages;
|
||||
if (!Array.isArray(messages)) return null;
|
||||
if (!Array.isArray(messages)) {
|
||||
return null;
|
||||
}
|
||||
return renderMessageList(messages, opts, "No messages.");
|
||||
}
|
||||
|
||||
function renderPinsFromPayload(payload: unknown, opts: FormatOpts): string[] | null {
|
||||
if (!payload || typeof payload !== "object") return null;
|
||||
if (!payload || typeof payload !== "object") {
|
||||
return null;
|
||||
}
|
||||
const pins = (payload as { pins?: unknown }).pins;
|
||||
if (!Array.isArray(pins)) return null;
|
||||
if (!Array.isArray(pins)) {
|
||||
return null;
|
||||
}
|
||||
return renderMessageList(pins, opts, "No pins.");
|
||||
}
|
||||
|
||||
function extractDiscordSearchResultsMessages(results: unknown): unknown[] | null {
|
||||
if (!results || typeof results !== "object") return null;
|
||||
if (!results || typeof results !== "object") {
|
||||
return null;
|
||||
}
|
||||
const raw = (results as { messages?: unknown }).messages;
|
||||
if (!Array.isArray(raw)) return null;
|
||||
if (!Array.isArray(raw)) {
|
||||
return null;
|
||||
}
|
||||
// Discord search returns messages as array-of-array; first element is the message.
|
||||
const flattened: unknown[] = [];
|
||||
for (const entry of raw) {
|
||||
@@ -175,9 +197,13 @@ function extractDiscordSearchResultsMessages(results: unknown): unknown[] | null
|
||||
}
|
||||
|
||||
function renderReactions(payload: unknown, opts: FormatOpts): string[] | null {
|
||||
if (!payload || typeof payload !== "object") return null;
|
||||
if (!payload || typeof payload !== "object") {
|
||||
return null;
|
||||
}
|
||||
const reactions = (payload as { reactions?: unknown }).reactions;
|
||||
if (!Array.isArray(reactions)) return null;
|
||||
if (!Array.isArray(reactions)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const rows = reactions.slice(0, 50).map((r) => {
|
||||
const entry = r as Record<string, unknown>;
|
||||
@@ -192,8 +218,12 @@ function renderReactions(payload: unknown, opts: FormatOpts): string[] | null {
|
||||
? (entry.users as unknown[])
|
||||
.slice(0, 8)
|
||||
.map((u) => {
|
||||
if (typeof u === "string") return u;
|
||||
if (!u || typeof u !== "object") return "";
|
||||
if (typeof u === "string") {
|
||||
return u;
|
||||
}
|
||||
if (!u || typeof u !== "object") {
|
||||
return "";
|
||||
}
|
||||
const user = u as Record<string, unknown>;
|
||||
return (
|
||||
(typeof user.tag === "string" && user.tag) ||
|
||||
@@ -211,7 +241,9 @@ function renderReactions(payload: unknown, opts: FormatOpts): string[] | null {
|
||||
};
|
||||
});
|
||||
|
||||
if (rows.length === 0) return [theme.muted("No reactions.")];
|
||||
if (rows.length === 0) {
|
||||
return [theme.muted("No reactions.")];
|
||||
}
|
||||
|
||||
return [
|
||||
renderTable({
|
||||
@@ -304,7 +336,9 @@ export function formatMessageCliText(result: MessageActionRunResult): string[] {
|
||||
}),
|
||||
),
|
||||
];
|
||||
if (pollId) lines.push(ok(`Poll id: ${pollId}`));
|
||||
if (pollId) {
|
||||
lines.push(ok(`Poll id: ${pollId}`));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user