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

@@ -91,7 +91,9 @@ export function getTelegramSequentialKey(ctx: {
rawText &&
isControlCommandMessage(rawText, undefined, botUsername ? { botUsername } : undefined)
) {
if (typeof chatId === "number") return `telegram:${chatId}:control`;
if (typeof chatId === "number") {
return `telegram:${chatId}:control`;
}
return "telegram:control";
}
const isGroup = msg?.chat?.type === "group" || msg?.chat?.type === "supergroup";
@@ -158,8 +160,12 @@ export function createTelegramBot(opts: TelegramBotOptions) {
const recordUpdateId = (ctx: TelegramUpdateKeyContext) => {
const updateId = resolveTelegramUpdateId(ctx);
if (typeof updateId !== "number") return;
if (lastUpdateId !== null && updateId <= lastUpdateId) return;
if (typeof updateId !== "number") {
return;
}
if (lastUpdateId !== null && updateId <= lastUpdateId) {
return;
}
lastUpdateId = updateId;
void opts.updateOffset?.onUpdateId?.(updateId);
};
@@ -167,7 +173,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
const shouldSkipUpdate = (ctx: TelegramUpdateKeyContext) => {
const updateId = resolveTelegramUpdateId(ctx);
if (typeof updateId === "number" && lastUpdateId !== null) {
if (updateId <= lastUpdateId) return true;
if (updateId <= lastUpdateId) {
return true;
}
}
const key = buildTelegramUpdateKey(ctx);
const skipped = recentUpdates.check(key);
@@ -195,7 +203,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
}
if (value && typeof value === "object") {
const obj = value as object;
if (seen.has(obj)) return "[Circular]";
if (seen.has(obj)) {
return "[Circular]";
}
seen.add(obj);
}
return value;
@@ -261,7 +271,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
botHasTopicsEnabled = fromCtx.has_topics_enabled;
return botHasTopicsEnabled;
}
if (typeof botHasTopicsEnabled === "boolean") return botHasTopicsEnabled;
if (typeof botHasTopicsEnabled === "boolean") {
return botHasTopicsEnabled;
}
try {
const me = (await withTelegramApiErrorLogging({
operation: "getMe",
@@ -296,8 +308,12 @@ export function createTelegramBot(opts: TelegramBotOptions) {
try {
const store = loadSessionStore(storePath);
const entry = store[sessionKey];
if (entry?.groupActivation === "always") return false;
if (entry?.groupActivation === "mention") return true;
if (entry?.groupActivation === "always") {
return false;
}
if (entry?.groupActivation === "mention") {
return true;
}
} catch (err) {
logVerbose(`Failed to load session for activation check: ${String(err)}`);
}
@@ -314,7 +330,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
});
const resolveTelegramGroupConfig = (chatId: string | number, messageThreadId?: number) => {
const groups = telegramCfg.groups;
if (!groups) return { groupConfig: undefined, topicConfig: undefined };
if (!groups) {
return { groupConfig: undefined, topicConfig: undefined };
}
const groupKey = String(chatId);
const groupConfig = groups[groupKey] ?? groups["*"];
const topicConfig =
@@ -369,8 +387,12 @@ export function createTelegramBot(opts: TelegramBotOptions) {
bot.on("message_reaction", async (ctx) => {
try {
const reaction = ctx.messageReaction;
if (!reaction) return;
if (shouldSkipUpdate(ctx)) return;
if (!reaction) {
return;
}
if (shouldSkipUpdate(ctx)) {
return;
}
const chatId = reaction.chat.id;
const messageId = reaction.message_id;
@@ -378,9 +400,15 @@ export function createTelegramBot(opts: TelegramBotOptions) {
// Resolve reaction notification mode (default: "own")
const reactionMode = telegramCfg.reactionNotifications ?? "own";
if (reactionMode === "off") return;
if (user?.is_bot) return;
if (reactionMode === "own" && !wasSentByBot(chatId, messageId)) return;
if (reactionMode === "off") {
return;
}
if (user?.is_bot) {
return;
}
if (reactionMode === "own" && !wasSentByBot(chatId, messageId)) {
return;
}
// Detect added reactions
const oldEmojis = new Set(
@@ -392,7 +420,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
.filter((r): r is { type: "emoji"; emoji: string } => r.type === "emoji")
.filter((r) => !oldEmojis.has(r.emoji));
if (addedReactions.length === 0) return;
if (addedReactions.length === 0) {
return;
}
// Build sender label
const senderName = user