From ec06c77bdeec8ea2a7a1598375555a6eda8ebf6e Mon Sep 17 00:00:00 2001 From: JianMiau Date: Fri, 14 Aug 2026 17:27:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BC=E4=BD=88=200.1.10=EF=BC=9Atag=20?= =?UTF-8?q?=E5=84=AA=E5=85=88=E6=96=BC=E5=9B=9E=E8=A6=86=E8=A7=B8=E7=99=BC?= =?UTF-8?q?=EF=BC=8C=E5=A4=9A=20bot=20=E5=90=8C=E7=BE=A4=E4=B8=8D=E6=90=B6?= =?UTF-8?q?=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根本原因: 回覆 A bot 的訊息並 tag B bot 時,A 因「被回覆」觸發搶答, B 才是使用者真正要叫的對象。 修法: 群組觸發改為 tag 優先:訊息含任何 bot tag(@xxx...bot)時, 只有第一個被 tag 的 bot 回應,被回覆的 bot 自動讓位; 沒有 bot tag 時維持原邏輯(回覆我 → 我回應)。 tag 一般使用者(非 bot username)不影響判定。 Co-Authored-By: Claude Fable 5 --- package.json | 2 +- src/bot.js | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c0e1cac..1f4311c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telegram-codex-bot", - "version": "0.1.9", + "version": "0.1.10", "description": "Telegram bot powered by the local Codex CLI — zero-dependency, pm2-managed, with a built-in PM2 web viewer", "license": "MIT", "type": "commonjs", diff --git a/src/bot.js b/src/bot.js index 8cdd35b..e8f0c96 100644 --- a/src/bot.js +++ b/src/bot.js @@ -111,14 +111,21 @@ function startBot(config) { function shouldRespond(message) { if (message.chat.type === 'private') return true; - if (message.reply_to_message?.from?.id === botId) return true; const text = message.text || message.caption || ''; const entities = message.entities || message.caption_entities || []; - return entities.some((e) => - (e.type === 'mention' && - text.slice(e.offset, e.offset + e.length).toLowerCase() === `@${botUsername.toLowerCase()}`) || - (e.type === 'text_mention' && e.user?.id === botId) - ); + // 訊息中所有被 tag 的 bot(Telegram bot username 一定以 bot 結尾; + // tag 到一般使用者不算,不影響回覆觸發) + const botMentions = entities + .filter((e) => e.type === 'mention') + .map((e) => text.slice(e.offset + 1, e.offset + e.length)) + .filter((u) => /bot$/i.test(u)); + if (botMentions.length > 0) { + // 有明確 tag 時以 tag 為準:只有第一個被 tag 的 bot 回應。 + // 就算這則訊息是回覆我的(例如回覆我的訊息但 tag 別的 bot),我也讓位。 + return botMentions[0].toLowerCase() === botUsername.toLowerCase(); + } + if (message.reply_to_message?.from?.id === botId) return true; + return entities.some((e) => e.type === 'text_mention' && e.user?.id === botId); } function stripMention(text) {