發佈 0.1.10:tag 優先於回覆觸發,多 bot 同群不搶答
根本原因: 回覆 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 <noreply@anthropic.com>
This commit is contained in:
+13
-6
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user