fix(protocol): strip reply auto-mention on receive; align send to uin=0 (#127)

A QQ NT reply carries the replied sender as a structural auto-mention
(MentionExtra.type=2, uin=0) right after srcMsg, plus a blank separator
text. SnowLuma reported both as a real [CQ:at] + empty/space segment, so
downstreams saw a phantom @ (#127). A real user @ carries a non-zero
MentionExtra.uin, so it is preserved.

- receive (rich-body-decoder): after a reply, drop a type=2/uin=0 mention
  and the blank text that follows it; keep non-zero-uin mentions.
- send (element-builder, #129 follow-up): the reply auto-mention added for
  reply+@ now uses uin=0 (real uid stays in `uid`) to match QQ's native wire
  shape, so the bot's own replies are stripped the same way by receivers and
  don't surface a phantom @ either.

Validated on-target (Docker, group): reply w/o @ -> [reply, text] (no
phantom @/empty); reply w/ @ -> [reply, at(real), text]; bot reply+@ still
delivers the @ (uin=0).
This commit is contained in:
DrSmoothl committed 2026-06-22 20:53:10 +08:00
1 parent 45aae92af5
commit 4593ba3340
2 files changed
+24 -1

No files matched your search

+5 -1
View File
@@ -115,7 +115,11 @@ async function makeReplyMentionElem(ctx: SendContext, uin: number): Promise<Prot
if (!uid) uid = await ctx.bridge.identity.resolveUid(uin, ctx.groupId).catch(() => '');
if (!uid) return null;
const name = member?.card?.trim() || member?.nickname?.trim() || String(uin);
const extra = protobuf_encode<MentionExtraSend>({ type: 2, uin, field5: 0, uid });
// uin=0 matches QQ NT's native reply auto-mention (the real uid lives in
// `uid`). It does not itself notify — the user's own @ does — and the receive
// side strips a type=2/uin=0 mention as structural (#127), so the bot's own
// replies don't surface a spurious @ either.
const extra = protobuf_encode<MentionExtraSend>({ type: 2, uin: 0, field5: 0, uid });
return { text: { str: `@${name} `, pbReserve: extra } };
}