mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:37:40 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -105,7 +105,9 @@ export async function deliverReplies(params: {
|
||||
const chunks = chunkText(reply.text || "");
|
||||
for (let i = 0; i < chunks.length; i += 1) {
|
||||
const chunk = chunks[i];
|
||||
if (!chunk) continue;
|
||||
if (!chunk) {
|
||||
continue;
|
||||
}
|
||||
// Only attach buttons to the first chunk.
|
||||
const shouldAttachButtons = i === 0 && replyMarkup;
|
||||
await sendTelegramText(bot, chatId, chunk.html, runtime, {
|
||||
@@ -306,7 +308,9 @@ export async function resolveMedia(
|
||||
logVerbose("telegram: skipping animated/video sticker (only static stickers supported)");
|
||||
return null;
|
||||
}
|
||||
if (!sticker.file_id) return null;
|
||||
if (!sticker.file_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const file = await ctx.getFile();
|
||||
@@ -389,7 +393,9 @@ export async function resolveMedia(
|
||||
msg.document ??
|
||||
msg.audio ??
|
||||
msg.voice;
|
||||
if (!m?.file_id) return null;
|
||||
if (!m?.file_id) {
|
||||
return null;
|
||||
}
|
||||
const file = await ctx.getFile();
|
||||
if (!file.file_path) {
|
||||
throw new Error("Telegram getFile returned no file_path");
|
||||
@@ -413,10 +419,15 @@ export async function resolveMedia(
|
||||
originalName,
|
||||
);
|
||||
let placeholder = "<media:document>";
|
||||
if (msg.photo) placeholder = "<media:image>";
|
||||
else if (msg.video) placeholder = "<media:video>";
|
||||
else if (msg.video_note) placeholder = "<media:video>";
|
||||
else if (msg.audio || msg.voice) placeholder = "<media:audio>";
|
||||
if (msg.photo) {
|
||||
placeholder = "<media:image>";
|
||||
} else if (msg.video) {
|
||||
placeholder = "<media:video>";
|
||||
} else if (msg.video_note) {
|
||||
placeholder = "<media:video>";
|
||||
} else if (msg.audio || msg.voice) {
|
||||
placeholder = "<media:audio>";
|
||||
}
|
||||
return { path: saved.path, contentType: saved.contentType, placeholder };
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,9 @@ export function resolveTelegramStreamMode(
|
||||
telegramCfg: Pick<TelegramAccountConfig, "streamMode"> | undefined,
|
||||
): TelegramStreamMode {
|
||||
const raw = telegramCfg?.streamMode?.trim().toLowerCase();
|
||||
if (raw === "off" || raw === "partial" || raw === "block") return raw;
|
||||
if (raw === "off" || raw === "partial" || raw === "block") {
|
||||
return raw;
|
||||
}
|
||||
return "partial";
|
||||
}
|
||||
|
||||
@@ -97,8 +99,12 @@ export function buildSenderLabel(msg: TelegramMessage, senderId?: number | strin
|
||||
senderId != null && `${senderId}`.trim() ? `${senderId}`.trim() : undefined;
|
||||
const fallbackId = normalizedSenderId ?? (msg.from?.id != null ? String(msg.from.id) : undefined);
|
||||
const idPart = fallbackId ? `id:${fallbackId}` : undefined;
|
||||
if (label && idPart) return `${label} ${idPart}`;
|
||||
if (label) return label;
|
||||
if (label && idPart) {
|
||||
return `${label} ${idPart}`;
|
||||
}
|
||||
if (label) {
|
||||
return label;
|
||||
}
|
||||
return idPart ?? "id:unknown";
|
||||
}
|
||||
|
||||
@@ -109,18 +115,26 @@ export function buildGroupLabel(
|
||||
) {
|
||||
const title = msg.chat?.title;
|
||||
const topicSuffix = messageThreadId != null ? ` topic:${messageThreadId}` : "";
|
||||
if (title) return `${title} id:${chatId}${topicSuffix}`;
|
||||
if (title) {
|
||||
return `${title} id:${chatId}${topicSuffix}`;
|
||||
}
|
||||
return `group:${chatId}${topicSuffix}`;
|
||||
}
|
||||
|
||||
export function hasBotMention(msg: TelegramMessage, botUsername: string) {
|
||||
const text = (msg.text ?? msg.caption ?? "").toLowerCase();
|
||||
if (text.includes(`@${botUsername}`)) return true;
|
||||
if (text.includes(`@${botUsername}`)) {
|
||||
return true;
|
||||
}
|
||||
const entities = msg.entities ?? msg.caption_entities ?? [];
|
||||
for (const ent of entities) {
|
||||
if (ent.type !== "mention") continue;
|
||||
if (ent.type !== "mention") {
|
||||
continue;
|
||||
}
|
||||
const slice = (msg.text ?? msg.caption ?? "").slice(ent.offset, ent.offset + ent.length);
|
||||
if (slice.toLowerCase() === `@${botUsername}`) return true;
|
||||
if (slice.toLowerCase() === `@${botUsername}`) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -133,7 +147,9 @@ type TelegramTextLinkEntity = {
|
||||
};
|
||||
|
||||
export function expandTextLinks(text: string, entities?: TelegramTextLinkEntity[] | null): string {
|
||||
if (!text || !entities?.length) return text;
|
||||
if (!text || !entities?.length) {
|
||||
return text;
|
||||
}
|
||||
|
||||
const textLinks = entities
|
||||
.filter(
|
||||
@@ -142,7 +158,9 @@ export function expandTextLinks(text: string, entities?: TelegramTextLinkEntity[
|
||||
)
|
||||
.toSorted((a, b) => b.offset - a.offset);
|
||||
|
||||
if (textLinks.length === 0) return text;
|
||||
if (textLinks.length === 0) {
|
||||
return text;
|
||||
}
|
||||
|
||||
let result = text;
|
||||
for (const entity of textLinks) {
|
||||
@@ -155,9 +173,13 @@ export function expandTextLinks(text: string, entities?: TelegramTextLinkEntity[
|
||||
}
|
||||
|
||||
export function resolveTelegramReplyId(raw?: string): number | undefined {
|
||||
if (!raw) return undefined;
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const parsed = Number(raw);
|
||||
if (!Number.isFinite(parsed)) return undefined;
|
||||
if (!Number.isFinite(parsed)) {
|
||||
return undefined;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
@@ -185,17 +207,25 @@ export function describeReplyTarget(msg: TelegramMessage): TelegramReplyTarget |
|
||||
const replyBody = (reply.text ?? reply.caption ?? "").trim();
|
||||
body = replyBody;
|
||||
if (!body) {
|
||||
if (reply.photo) body = "<media:image>";
|
||||
else if (reply.video) body = "<media:video>";
|
||||
else if (reply.audio || reply.voice) body = "<media:audio>";
|
||||
else if (reply.document) body = "<media:document>";
|
||||
else {
|
||||
if (reply.photo) {
|
||||
body = "<media:image>";
|
||||
} else if (reply.video) {
|
||||
body = "<media:video>";
|
||||
} else if (reply.audio || reply.voice) {
|
||||
body = "<media:audio>";
|
||||
} else if (reply.document) {
|
||||
body = "<media:document>";
|
||||
} else {
|
||||
const locationData = extractTelegramLocation(reply);
|
||||
if (locationData) body = formatLocationText(locationData);
|
||||
if (locationData) {
|
||||
body = formatLocationText(locationData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!body) return null;
|
||||
if (!body) {
|
||||
return null;
|
||||
}
|
||||
const sender = reply ? buildSenderName(reply) : undefined;
|
||||
const senderLabel = sender ? `${sender}` : "unknown sender";
|
||||
|
||||
@@ -243,7 +273,9 @@ function buildForwardedContextFromUser(params: {
|
||||
type: string;
|
||||
}): TelegramForwardedContext | null {
|
||||
const { display, name, username, id } = normalizeForwardedUserLabel(params.user);
|
||||
if (!display) return null;
|
||||
if (!display) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
from: display,
|
||||
date: params.date,
|
||||
@@ -260,7 +292,9 @@ function buildForwardedContextFromHiddenName(params: {
|
||||
type: string;
|
||||
}): TelegramForwardedContext | null {
|
||||
const trimmed = params.name?.trim();
|
||||
if (!trimmed) return null;
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
from: trimmed,
|
||||
date: params.date,
|
||||
@@ -278,7 +312,9 @@ function buildForwardedContextFromChat(params: {
|
||||
const fallbackKind =
|
||||
params.type === "channel" || params.type === "legacy_channel" ? "channel" : "chat";
|
||||
const { display, title, username, id } = normalizeForwardedChatLabel(params.chat, fallbackKind);
|
||||
if (!display) return null;
|
||||
if (!display) {
|
||||
return null;
|
||||
}
|
||||
const signature = params.signature?.trim() || undefined;
|
||||
const from = signature ? `${display} (${signature})` : display;
|
||||
return {
|
||||
@@ -339,7 +375,9 @@ export function normalizeForwardedContext(msg: TelegramMessage): TelegramForward
|
||||
|
||||
if (forwardMsg.forward_origin) {
|
||||
const originContext = resolveForwardOrigin(forwardMsg.forward_origin, signature);
|
||||
if (originContext) return originContext;
|
||||
if (originContext) {
|
||||
return originContext;
|
||||
}
|
||||
}
|
||||
|
||||
if (forwardMsg.forward_from_chat) {
|
||||
@@ -351,7 +389,9 @@ export function normalizeForwardedContext(msg: TelegramMessage): TelegramForward
|
||||
type: legacyType,
|
||||
signature,
|
||||
});
|
||||
if (legacyContext) return legacyContext;
|
||||
if (legacyContext) {
|
||||
return legacyContext;
|
||||
}
|
||||
}
|
||||
|
||||
if (forwardMsg.forward_from) {
|
||||
@@ -360,7 +400,9 @@ export function normalizeForwardedContext(msg: TelegramMessage): TelegramForward
|
||||
date: forwardMsg.forward_date,
|
||||
type: "legacy_user",
|
||||
});
|
||||
if (legacyContext) return legacyContext;
|
||||
if (legacyContext) {
|
||||
return legacyContext;
|
||||
}
|
||||
}
|
||||
|
||||
const hiddenContext = buildForwardedContextFromHiddenName({
|
||||
@@ -368,7 +410,9 @@ export function normalizeForwardedContext(msg: TelegramMessage): TelegramForward
|
||||
date: forwardMsg.forward_date,
|
||||
type: "legacy_hidden_user",
|
||||
});
|
||||
if (hiddenContext) return hiddenContext;
|
||||
if (hiddenContext) {
|
||||
return hiddenContext;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user