From 6a6a0e05395ebac098e036d674dc5b619e267d25 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Oct 2025 01:26:10 +0000 Subject: [PATCH] Fix spurious group_card events for forward messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent false group card change events when sending forward messages with comments. The issue occurred because forward messages sometimes have empty sendMemberName fields, triggering incorrect "name → empty" card change events. Solution: Skip card change detection when the new card name is empty but the old card name is not empty, as this indicates unreliable data (e.g., from forward messages). Co-authored-by: sj817 <74231782+sj817@users.noreply.github.com> --- src/onebot/api/group.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/onebot/api/group.ts b/src/onebot/api/group.ts index 2f8a7efd..819c82ec 100644 --- a/src/onebot/api/group.ts +++ b/src/onebot/api/group.ts @@ -116,6 +116,16 @@ export class OneBotGroupApi { const member = await this.core.apis.GroupApi.getGroupMember(msg.peerUid, msg.senderUin); if (member && member.cardName !== msg.sendMemberName) { const newCardName = msg.sendMemberName ?? ''; + // 防止误触:如果新名片为空且旧名片不为空,不触发事件(可能是转发消息等场景的不可靠数据) + if (newCardName === '' && member.cardName !== '') { + this.core.context.logger.logDebug('忽略不可靠的群名片变更事件', { + peerUid: msg.peerUid, + senderUin: msg.senderUin, + oldCard: member.cardName, + newCard: newCardName + }); + return undefined; + } const event = new OB11GroupCardEvent(this.core, parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName); member.cardName = newCardName; return event;