chore: Enable "curly" rule to avoid single-statement if confusion/errors.

This commit is contained in:
cpojer
2026-01-31 16:19:20 +09:00
parent 009b16fab8
commit 5ceff756e1
1266 changed files with 27871 additions and 9393 deletions

View File

@@ -77,7 +77,9 @@ function createTelegramHttpLogger(cfg: ReturnType<typeof loadConfig>) {
return () => {};
}
return (label: string, err: unknown) => {
if (!(err instanceof HttpError)) return;
if (!(err instanceof HttpError)) {
return;
}
const detail = redactSensitiveText(formatUncaughtError(err.error ?? err));
diagLogger.warn(`telegram http error (${label}): ${detail}`);
};
@@ -105,7 +107,9 @@ function resolveTelegramClientOptions(
}
function resolveToken(explicit: string | undefined, params: { accountId: string; token: string }) {
if (explicit?.trim()) return explicit.trim();
if (explicit?.trim()) {
return explicit.trim();
}
if (!params.token) {
throw new Error(
`Telegram bot token missing for account "${params.accountId}" (set channels.telegram.accounts.${params.accountId}.botToken/tokenFile or TELEGRAM_BOT_TOKEN for default).`,
@@ -116,7 +120,9 @@ function resolveToken(explicit: string | undefined, params: { accountId: string;
function normalizeChatId(to: string): string {
const trimmed = to.trim();
if (!trimmed) throw new Error("Recipient is required for Telegram sends");
if (!trimmed) {
throw new Error("Recipient is required for Telegram sends");
}
// Common internal prefixes that sometimes leak into outbound sends.
// - ctx.To uses `telegram:<id>`
@@ -128,14 +134,24 @@ function normalizeChatId(to: string): string {
const m =
/^https?:\/\/t\.me\/([A-Za-z0-9_]+)$/i.exec(normalized) ??
/^t\.me\/([A-Za-z0-9_]+)$/i.exec(normalized);
if (m?.[1]) normalized = `@${m[1]}`;
if (m?.[1]) {
normalized = `@${m[1]}`;
}
if (!normalized) throw new Error("Recipient is required for Telegram sends");
if (normalized.startsWith("@")) return normalized;
if (/^-?\d+$/.test(normalized)) return normalized;
if (!normalized) {
throw new Error("Recipient is required for Telegram sends");
}
if (normalized.startsWith("@")) {
return normalized;
}
if (/^-?\d+$/.test(normalized)) {
return normalized;
}
// If the user passed a username without `@`, assume they meant a public chat/channel.
if (/^[A-Za-z0-9_]{5,}$/i.test(normalized)) return `@${normalized}`;
if (/^[A-Za-z0-9_]{5,}$/i.test(normalized)) {
return `@${normalized}`;
}
return normalized;
}
@@ -150,7 +166,9 @@ function normalizeMessageId(raw: string | number): number {
throw new Error("Message id is required for Telegram actions");
}
const parsed = Number.parseInt(value, 10);
if (Number.isFinite(parsed)) return parsed;
if (Number.isFinite(parsed)) {
return parsed;
}
}
throw new Error("Message id is required for Telegram actions");
}
@@ -158,7 +176,9 @@ function normalizeMessageId(raw: string | number): number {
export function buildInlineKeyboard(
buttons?: TelegramSendOpts["buttons"],
): InlineKeyboardMarkup | undefined {
if (!buttons?.length) return undefined;
if (!buttons?.length) {
return undefined;
}
const rows = buttons
.map((row) =>
row
@@ -171,7 +191,9 @@ export function buildInlineKeyboard(
),
)
.filter((row) => row.length > 0);
if (rows.length === 0) return undefined;
if (rows.length === 0) {
return undefined;
}
return { inline_keyboard: rows };
}
@@ -229,7 +251,9 @@ export async function sendMessageTelegram(
throw err;
});
const wrapChatNotFound = (err: unknown) => {
if (!/400: Bad Request: chat not found/i.test(formatErrorMessage(err))) return err;
if (!/400: Bad Request: chat not found/i.test(formatErrorMessage(err))) {
return err;
}
return new Error(
[
`Telegram send failed: chat not found (chat_id=${chatId}).`,
@@ -690,7 +714,9 @@ export async function sendStickerTelegram(
});
const wrapChatNotFound = (err: unknown) => {
if (!/400: Bad Request: chat not found/i.test(formatErrorMessage(err))) return err;
if (!/400: Bad Request: chat not found/i.test(formatErrorMessage(err))) {
return err;
}
return new Error(
[
`Telegram send failed: chat not found (chat_id=${chatId}).`,