diff --git a/packages/protocol/src/element-builder.ts b/packages/protocol/src/element-builder.ts index 43be2636..a8f5265d 100644 --- a/packages/protocol/src/element-builder.ts +++ b/packages/protocol/src/element-builder.ts @@ -115,7 +115,11 @@ async function makeReplyMentionElem(ctx: SendContext, uin: number): Promise ''); if (!uid) return null; const name = member?.card?.trim() || member?.nickname?.trim() || String(uin); - const extra = protobuf_encode({ 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({ type: 2, uin: 0, field5: 0, uid }); return { text: { str: `@${name} `, pbReserve: extra } }; } diff --git a/packages/protocol/src/msg-push/rich-body-decoder.ts b/packages/protocol/src/msg-push/rich-body-decoder.ts index d0bc4b3d..cf5a5c3b 100644 --- a/packages/protocol/src/msg-push/rich-body-decoder.ts +++ b/packages/protocol/src/msg-push/rich-body-decoder.ts @@ -33,6 +33,13 @@ export function decodeRichBody(body: PushMsgBody | undefined, isGroup: boolean): function convertElements(elems: ElemDecoded[]): MessageElement[] { const result: MessageElement[] = []; let skipNext = false; + // [#127] A QQ NT reply carries the replied sender as a structural auto-mention + // (MentionExtra.type=2, uin=0) right after srcMsg, followed by a blank + // separator text. Both are part of the reply wire shape, not user content — + // drop them so they aren't reported as a spurious @ + empty segment. A real + // user @ carries a non-zero MentionExtra.uin, so it's preserved. + let sawReply = false; + let dropNextBlankText = false; for (const elem of elems) { if (skipNext) { skipNext = false; continue; } @@ -55,6 +62,7 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] { // back empty. const replySeq = elem.srcMsg.origSeqs?.[0] ?? 0; if (replySeq > 0) result.push({ type: 'reply', replySeq }); + sawReply = true; } // Text (with possible @ detection) @@ -67,6 +75,17 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] { const hasAttr6 = t.attr6Buf && t.attr6Buf.length > 11; const hasMention = mention && (mention.type === 1 || mention.type === 2); + // [#127] drop the reply's structural auto-mention (type=2, uin=0) and the + // blank separator text right after it; keep real @s (non-zero uin). + if (sawReply && mention && mention.type === 2 && (mention.uin ?? 0) === 0) { + dropNextBlankText = true; + continue; + } + if (dropNextBlankText) { + dropNextBlankText = false; + if (!hasMention && (t.str ?? '').trim() === '') continue; + } + if (hasAttr6 || hasMention) { const me: MessageElement = { type: 'at', text: t.str ?? '' }; if (hasAttr6) {