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:
2 files changed
+24
-1
No files matched your search
@@ -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 } };
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user