diff --git a/packages/core/tests/msg-push-handler.test.ts b/packages/core/tests/msg-push-handler.test.ts index e8e78024..5b1efd09 100644 --- a/packages/core/tests/msg-push-handler.test.ts +++ b/packages/core/tests/msg-push-handler.test.ts @@ -15,6 +15,7 @@ import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/protocol/qq-info'; import type { GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup, GroupAdmin, InputStatusNotify, NotifyMessageBody, GroupNameChange, GroupSpecialTitleChange, + ProfileLikeTip, } from '@snowluma/proto-defs/notify'; import type { PushMsg } from '@snowluma/proto-defs/message'; import type { @@ -302,6 +303,46 @@ describe('parseMsgPush Event0x210 subType=277 (input status → 对方正在输 }); }); +describe('parseMsgPush Event0x210 subType=39 (profile like → 名片赞)', () => { + // 0x210/39 is multiplexed; body.msgContent decodes as ProfileLikeTip and is a + // like only when inner msgType==0 && subType==203. Proto shape from NapCat's + // raw-bytes decoder (pending a real like capture to validate byte-exactly). + type FriendProfileLikeEvent = Extract; + + function makeLikePacket(opts: { msgType?: number; subType?: number; uin?: number; nick?: string; txt?: string; time?: number }): PacketInfo { + const content = protobuf_encode({ + msgType: opts.msgType ?? 0, + subType: opts.subType ?? 203, + content: { msg: { + time: opts.time ?? 1710001111, + detail: { txt: opts.txt ?? '', uin: BigInt(opts.uin ?? 0), nickname: opts.nick ?? '' }, + } }, + }); + return makeEvent0x210PacketAny(39, content); + } + + it('emits friend_profile_like with liker uin, nick and parsed count', () => { + const [event] = parseMsgPush( + makeLikePacket({ uin: 1787882683, nick: '東雪蓮', txt: '赞了你3次' }), + makeIdentity(), + ) as FriendProfileLikeEvent[]; + + expect(event.kind).toBe('friend_profile_like'); + expect(event.operatorUin).toBe(1787882683); + expect(event.operatorNick).toBe('東雪蓮'); + expect(event.times).toBe(3); + expect(event.time).toBe(1710001111); + }); + + it('ignores a non-like 39 variant (inner subType != 203)', () => { + const events = parseMsgPush( + makeLikePacket({ subType: 999, uin: 1787882683 }), + makeIdentity(), + ); + expect(events).toEqual([]); + }); +}); + describe('parseMsgPush Event0x2DC subType=16 field13=6 (group special title)', () => { // Built from a REAL on-wire capture: eventParam f2 = the gray-tip template // "恭喜<{member}>获得群主授予的<{…"text":TITLE…}>头衔", f5 = member uin. The title diff --git a/packages/onebot/src/event-converter/index.ts b/packages/onebot/src/event-converter/index.ts index e5e0089f..3034ca8c 100644 --- a/packages/onebot/src/event-converter/index.ts +++ b/packages/onebot/src/event-converter/index.ts @@ -8,6 +8,7 @@ import { import { convertFriendAdd, convertFriendInputStatus, + convertFriendProfileLike, convertFriendPoke, convertFriendRecall, convertGroupAdmin, @@ -83,6 +84,7 @@ const CONVERTERS: ConverterRegistry = { group_file_upload: convertGroupFileUpload, friend_add: convertFriendAdd, friend_input_status: convertFriendInputStatus, + friend_profile_like: convertFriendProfileLike, group_name_change: convertGroupNameChange, group_title_change: convertGroupTitleChange, group_card_change: convertGroupCardChange, diff --git a/packages/onebot/src/event-converter/to-notice.ts b/packages/onebot/src/event-converter/to-notice.ts index a7a39822..94d76e6b 100644 --- a/packages/onebot/src/event-converter/to-notice.ts +++ b/packages/onebot/src/event-converter/to-notice.ts @@ -21,6 +21,7 @@ type FriendInputStatus = Extract; type GroupCardChange = Extract; type GroupTitleChange = Extract; +type FriendProfileLike = Extract; export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMemberJoin): JsonObject { return notice(ctx, event, { @@ -172,6 +173,18 @@ export function convertGroupCardChange(ctx: ConverterContext, event: GroupCardCh }); } +export function convertFriendProfileLike(ctx: ConverterContext, event: FriendProfileLike): JsonObject { + // Mirrors NapCat's OB11ProfileLikeEvent: notify/profile_like with the liker's + // uin, nickname and like count. + return notice(ctx, event, { + notice_type: 'notify', + sub_type: 'profile_like', + operator_id: event.operatorUin, + operator_nick: event.operatorNick, + times: event.times, + }); +} + export function convertGroupTitleChange(ctx: ConverterContext, event: GroupTitleChange): JsonObject { // Mirrors NapCat's OB11GroupTitleEvent: notify/title with the recipient's uin // and the granted title text. diff --git a/packages/onebot/src/event-pipeline.ts b/packages/onebot/src/event-pipeline.ts index 25827093..5079c481 100644 --- a/packages/onebot/src/event-pipeline.ts +++ b/packages/onebot/src/event-pipeline.ts @@ -71,6 +71,7 @@ const NOTICE_KINDS = [ 'group_file_upload', 'friend_add', 'friend_input_status', + 'friend_profile_like', 'group_name_change', 'group_title_change', 'group_card_change', diff --git a/packages/proto-defs/src/notify.ts b/packages/proto-defs/src/notify.ts index 8d96b4c0..443dac2e 100644 --- a/packages/proto-defs/src/notify.ts +++ b/packages/proto-defs/src/notify.ts @@ -282,6 +282,33 @@ export interface GroupSpecialTitleChange { memberUin?: pb<5, uint_32>; } +// Profile-like ("名片赞") notify — Event 0x210 subType 39, whose body.msgContent +// decodes as this ProfileLikeTip. subType 39 is multiplexed; only inner +// msgType==0 && subType==203 is a like. NOTE: proto shape sourced from NapCat's +// raw-bytes decoder (adaptDecoder.ts) — semantics only; pending a real like +// capture to confirm byte-exactly. times is parsed from `detail.txt`. +export interface ProfileLikeDetail { + txt?: pb<1, string>; + uin?: pb<3, uint_64>; + nickname?: pb<5, string>; +} + +export interface ProfileLikeMsg { + times?: pb<1, int_32>; + time?: pb<2, int_32>; + detail?: pb<3, ProfileLikeDetail>; +} + +export interface ProfileLikeSubTip { + msg?: pb<14, ProfileLikeMsg>; +} + +export interface ProfileLikeTip { + msgType?: pb<1, int_32>; + subType?: pb<2, int_32>; + content?: pb<203, ProfileLikeSubTip>; +} + // C2C input-status notify — the "对方正在输入…" push. Delivered as a system // message (msgType 0x210 / subMsgType 0x115) whose `MsgBody.msgContent` carries // this body. Field layout RE'd from `wrapper.linux.node` diff --git a/packages/protocol/src/events.ts b/packages/protocol/src/events.ts index 1e58a181..a015af0b 100644 --- a/packages/protocol/src/events.ts +++ b/packages/protocol/src/events.ts @@ -329,6 +329,18 @@ export interface GroupNameChangeEvent extends QQEvent { name: string; // the new group name } +/** + * Someone liked the bot's profile card ("名片赞") — Event 0x210 subType 39, + * inner ProfileLikeTip msgType 0 / subType 203. Mirrors NapCat's + * OB11ProfileLikeEvent → `notice/notify` `sub_type:'profile_like'`. + */ +export interface FriendProfileLikeEvent extends QQEvent { + kind: 'friend_profile_like'; + operatorUin: number; // who liked + operatorNick: string; + times: number; // like count from this event +} + /** * C2C "对方正在输入…" input-status push (Event 0x210 subType 0x115 / 277). * `eventType` 1 = typing, 3 = recording a voice message. Mirrors NapCat's @@ -364,4 +376,5 @@ export type QQEventVariant = | FriendInputStatusEvent | GroupNameChangeEvent | GroupCardChangeEvent - | GroupTitleChangeEvent; + | GroupTitleChangeEvent + | FriendProfileLikeEvent; diff --git a/packages/protocol/src/msg-push/decoders/event-0x210.ts b/packages/protocol/src/msg-push/decoders/event-0x210.ts index 2bb43324..047c41c7 100644 --- a/packages/protocol/src/msg-push/decoders/event-0x210.ts +++ b/packages/protocol/src/msg-push/decoders/event-0x210.ts @@ -12,6 +12,7 @@ import type { GeneralGrayTipInfo, InputStatusNotify, NewFriend, + ProfileLikeTip, } from '@snowluma/proto-defs/notify'; import type { PttTransPush } from '@snowluma/proto-defs/ptt-trans'; import type { MsgPushContext } from '../context'; @@ -25,6 +26,7 @@ import type { MsgPushDecoder } from '../registry'; type FriendRecallEvent = Extract; type FriendInputStatusEvent = Extract; +type FriendProfileLikeEvent = Extract; const unknownLog = createLogger('MsgPush.Unknown'); @@ -40,6 +42,7 @@ export const decodeEvent0x210: MsgPushDecoder = (ctx) => { return decodeFriendRecall(ctx); case Event0x210SubType.FriendPokeNotice: return decodeFriendPoke(ctx); case Event0x210SubType.InputStatusNotice: return decodeInputStatus(ctx); + case Event0x210SubType.ProfileLikeNotice: return decodeProfileLike(ctx); // 179 + 226 both carry the NewFriend payload — see enum comment. case Event0x210SubType.NewFriendNotice: case Event0x210SubType.NewFriendNoticeAlt: @@ -159,6 +162,32 @@ function inputStatusText(eventType: number): string { return eventType === 3 ? '对方正在讲话...' : '对方正在输入...'; } +// subType 39 is multiplexed; body.msgContent decodes as ProfileLikeTip and is a +// profile-like ("名片赞") only when inner msgType==0 && subType==203. Other 39 +// variants (multi-device sync etc.) decode to a non-matching tip → dropped. +// `times` is the like count parsed out of `detail.txt`. Proto shape from NapCat's +// raw-bytes decoder — pending a real like capture to validate byte-exactly. +function decodeProfileLike(ctx: MsgPushContext): QQEventVariant[] { + const tip = protobuf_decode(ctx.content); + // msgType 0 is the proto default → omitted on the wire → decodes as undefined, + // so treat missing as 0 (matches NapCat's `msgType !== 0` check). + if (!tip || (tip.msgType ?? 0) !== 0 || (tip.subType ?? 0) !== 203) return []; + const msg = tip.content?.msg; + const detail = msg?.detail; + const operatorUin = Number(detail?.uin ?? 0n); + if (!operatorUin) return []; + const times = Number.parseInt((detail?.txt ?? '').match(/\d+/)?.[0] ?? '0', 10) || 0; + const ev: FriendProfileLikeEvent = { + kind: 'friend_profile_like', + time: msg?.time || ctx.head.timestamp, + selfUin: ctx.selfUin, + operatorUin, + operatorNick: detail?.nickname ?? '', + times, + }; + return [ev]; +} + function decodeFriendPoke(ctx: MsgPushContext): QQEventVariant[] { const grayTip = protobuf_decode(ctx.content); if (!grayTip || (grayTip.busiType ?? 0n) !== 12n) return []; diff --git a/packages/protocol/src/msg-push/enums.ts b/packages/protocol/src/msg-push/enums.ts index d972def1..a408bb44 100644 --- a/packages/protocol/src/msg-push/enums.ts +++ b/packages/protocol/src/msg-push/enums.ts @@ -67,6 +67,14 @@ export enum Event0x210SubType { */ NewFriendNotice = 179, NewFriendNoticeAlt = 226, + /** + * Multiplexed subType (Lagrange calls it FriendDeleteOrPinChanged=39). One of + * its variants is the profile-like ("名片赞") push: body.msgContent decodes as + * `ProfileLikeTip` and is a like only when inner msgType==0 && subType==203. + * NapCat routes 528/39 → parseLikeEvent (`api/msg.ts:1547`); other 39 variants + * (multi-device sync etc.) fall through. + */ + ProfileLikeNotice = 39, /** * C2C input-status notify — the "对方正在输入…" push. subMsgType 0x115 (277). * RE-confirmed against `wrapper.linux.node`