feat(onebot): report profile like as notify/profile_like
Decode the multiplexed 0x210 subType-39 push: when body.msgContent is a
ProfileLikeTip with inner msgType==0/subType==203, emit notify/profile_like
{operator_id, operator_nick, times}. times is parsed from detail.txt.
Proto shape from NapCat's raw decoder; wiring + decode verified, but the
byte-exact wire is pending a real like capture to confirm.
This commit is contained in:
8 files changed
+135
-1
No files matched your search
@@ -15,6 +15,7 @@ import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/protocol/qq-info';
|
|||||||
import type {
|
import type {
|
||||||
GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup, GroupAdmin,
|
GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup, GroupAdmin,
|
||||||
InputStatusNotify, NotifyMessageBody, GroupNameChange, GroupSpecialTitleChange,
|
InputStatusNotify, NotifyMessageBody, GroupNameChange, GroupSpecialTitleChange,
|
||||||
|
ProfileLikeTip,
|
||||||
} from '@snowluma/proto-defs/notify';
|
} from '@snowluma/proto-defs/notify';
|
||||||
import type { PushMsg } from '@snowluma/proto-defs/message';
|
import type { PushMsg } from '@snowluma/proto-defs/message';
|
||||||
import type {
|
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<QQEventVariant, { kind: 'friend_profile_like' }>;
|
||||||
|
|
||||||
|
function makeLikePacket(opts: { msgType?: number; subType?: number; uin?: number; nick?: string; txt?: string; time?: number }): PacketInfo {
|
||||||
|
const content = protobuf_encode<ProfileLikeTip>({
|
||||||
|
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)', () => {
|
describe('parseMsgPush Event0x2DC subType=16 field13=6 (group special title)', () => {
|
||||||
// Built from a REAL on-wire capture: eventParam f2 = the gray-tip template
|
// Built from a REAL on-wire capture: eventParam f2 = the gray-tip template
|
||||||
// "恭喜<{member}>获得群主授予的<{…"text":TITLE…}>头衔", f5 = member uin. The title
|
// "恭喜<{member}>获得群主授予的<{…"text":TITLE…}>头衔", f5 = member uin. The title
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
convertFriendAdd,
|
convertFriendAdd,
|
||||||
convertFriendInputStatus,
|
convertFriendInputStatus,
|
||||||
|
convertFriendProfileLike,
|
||||||
convertFriendPoke,
|
convertFriendPoke,
|
||||||
convertFriendRecall,
|
convertFriendRecall,
|
||||||
convertGroupAdmin,
|
convertGroupAdmin,
|
||||||
@@ -83,6 +84,7 @@ const CONVERTERS: ConverterRegistry = {
|
|||||||
group_file_upload: convertGroupFileUpload,
|
group_file_upload: convertGroupFileUpload,
|
||||||
friend_add: convertFriendAdd,
|
friend_add: convertFriendAdd,
|
||||||
friend_input_status: convertFriendInputStatus,
|
friend_input_status: convertFriendInputStatus,
|
||||||
|
friend_profile_like: convertFriendProfileLike,
|
||||||
group_name_change: convertGroupNameChange,
|
group_name_change: convertGroupNameChange,
|
||||||
group_title_change: convertGroupTitleChange,
|
group_title_change: convertGroupTitleChange,
|
||||||
group_card_change: convertGroupCardChange,
|
group_card_change: convertGroupCardChange,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ type FriendInputStatus = Extract<QQEventVariant, { kind: 'friend_input_status' }
|
|||||||
type GroupNameChange = Extract<QQEventVariant, { kind: 'group_name_change' }>;
|
type GroupNameChange = Extract<QQEventVariant, { kind: 'group_name_change' }>;
|
||||||
type GroupCardChange = Extract<QQEventVariant, { kind: 'group_card_change' }>;
|
type GroupCardChange = Extract<QQEventVariant, { kind: 'group_card_change' }>;
|
||||||
type GroupTitleChange = Extract<QQEventVariant, { kind: 'group_title_change' }>;
|
type GroupTitleChange = Extract<QQEventVariant, { kind: 'group_title_change' }>;
|
||||||
|
type FriendProfileLike = Extract<QQEventVariant, { kind: 'friend_profile_like' }>;
|
||||||
|
|
||||||
export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMemberJoin): JsonObject {
|
export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMemberJoin): JsonObject {
|
||||||
return notice(ctx, event, {
|
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 {
|
export function convertGroupTitleChange(ctx: ConverterContext, event: GroupTitleChange): JsonObject {
|
||||||
// Mirrors NapCat's OB11GroupTitleEvent: notify/title with the recipient's uin
|
// Mirrors NapCat's OB11GroupTitleEvent: notify/title with the recipient's uin
|
||||||
// and the granted title text.
|
// and the granted title text.
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ const NOTICE_KINDS = [
|
|||||||
'group_file_upload',
|
'group_file_upload',
|
||||||
'friend_add',
|
'friend_add',
|
||||||
'friend_input_status',
|
'friend_input_status',
|
||||||
|
'friend_profile_like',
|
||||||
'group_name_change',
|
'group_name_change',
|
||||||
'group_title_change',
|
'group_title_change',
|
||||||
'group_card_change',
|
'group_card_change',
|
||||||
|
|||||||
@@ -282,6 +282,33 @@ export interface GroupSpecialTitleChange {
|
|||||||
memberUin?: pb<5, uint_32>;
|
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
|
// C2C input-status notify — the "对方正在输入…" push. Delivered as a system
|
||||||
// message (msgType 0x210 / subMsgType 0x115) whose `MsgBody.msgContent` carries
|
// message (msgType 0x210 / subMsgType 0x115) whose `MsgBody.msgContent` carries
|
||||||
// this body. Field layout RE'd from `wrapper.linux.node`
|
// this body. Field layout RE'd from `wrapper.linux.node`
|
||||||
|
|||||||
@@ -329,6 +329,18 @@ export interface GroupNameChangeEvent extends QQEvent {
|
|||||||
name: string; // the new group name
|
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).
|
* C2C "对方正在输入…" input-status push (Event 0x210 subType 0x115 / 277).
|
||||||
* `eventType` 1 = typing, 3 = recording a voice message. Mirrors NapCat's
|
* `eventType` 1 = typing, 3 = recording a voice message. Mirrors NapCat's
|
||||||
@@ -364,4 +376,5 @@ export type QQEventVariant =
|
|||||||
| FriendInputStatusEvent
|
| FriendInputStatusEvent
|
||||||
| GroupNameChangeEvent
|
| GroupNameChangeEvent
|
||||||
| GroupCardChangeEvent
|
| GroupCardChangeEvent
|
||||||
| GroupTitleChangeEvent;
|
| GroupTitleChangeEvent
|
||||||
|
| FriendProfileLikeEvent;
|
||||||
@@ -12,6 +12,7 @@ import type {
|
|||||||
GeneralGrayTipInfo,
|
GeneralGrayTipInfo,
|
||||||
InputStatusNotify,
|
InputStatusNotify,
|
||||||
NewFriend,
|
NewFriend,
|
||||||
|
ProfileLikeTip,
|
||||||
} from '@snowluma/proto-defs/notify';
|
} from '@snowluma/proto-defs/notify';
|
||||||
import type { PttTransPush } from '@snowluma/proto-defs/ptt-trans';
|
import type { PttTransPush } from '@snowluma/proto-defs/ptt-trans';
|
||||||
import type { MsgPushContext } from '../context';
|
import type { MsgPushContext } from '../context';
|
||||||
@@ -25,6 +26,7 @@ import type { MsgPushDecoder } from '../registry';
|
|||||||
|
|
||||||
type FriendRecallEvent = Extract<QQEventVariant, { kind: 'friend_recall' }>;
|
type FriendRecallEvent = Extract<QQEventVariant, { kind: 'friend_recall' }>;
|
||||||
type FriendInputStatusEvent = Extract<QQEventVariant, { kind: 'friend_input_status' }>;
|
type FriendInputStatusEvent = Extract<QQEventVariant, { kind: 'friend_input_status' }>;
|
||||||
|
type FriendProfileLikeEvent = Extract<QQEventVariant, { kind: 'friend_profile_like' }>;
|
||||||
|
|
||||||
const unknownLog = createLogger('MsgPush.Unknown');
|
const unknownLog = createLogger('MsgPush.Unknown');
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ export const decodeEvent0x210: MsgPushDecoder = (ctx) => {
|
|||||||
return decodeFriendRecall(ctx);
|
return decodeFriendRecall(ctx);
|
||||||
case Event0x210SubType.FriendPokeNotice: return decodeFriendPoke(ctx);
|
case Event0x210SubType.FriendPokeNotice: return decodeFriendPoke(ctx);
|
||||||
case Event0x210SubType.InputStatusNotice: return decodeInputStatus(ctx);
|
case Event0x210SubType.InputStatusNotice: return decodeInputStatus(ctx);
|
||||||
|
case Event0x210SubType.ProfileLikeNotice: return decodeProfileLike(ctx);
|
||||||
// 179 + 226 both carry the NewFriend payload — see enum comment.
|
// 179 + 226 both carry the NewFriend payload — see enum comment.
|
||||||
case Event0x210SubType.NewFriendNotice:
|
case Event0x210SubType.NewFriendNotice:
|
||||||
case Event0x210SubType.NewFriendNoticeAlt:
|
case Event0x210SubType.NewFriendNoticeAlt:
|
||||||
@@ -159,6 +162,32 @@ function inputStatusText(eventType: number): string {
|
|||||||
return eventType === 3 ? '对方正在讲话...' : '对方正在输入...';
|
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<ProfileLikeTip>(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[] {
|
function decodeFriendPoke(ctx: MsgPushContext): QQEventVariant[] {
|
||||||
const grayTip = protobuf_decode<GeneralGrayTipInfo>(ctx.content);
|
const grayTip = protobuf_decode<GeneralGrayTipInfo>(ctx.content);
|
||||||
if (!grayTip || (grayTip.busiType ?? 0n) !== 12n) return [];
|
if (!grayTip || (grayTip.busiType ?? 0n) !== 12n) return [];
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ export enum Event0x210SubType {
|
|||||||
*/
|
*/
|
||||||
NewFriendNotice = 179,
|
NewFriendNotice = 179,
|
||||||
NewFriendNoticeAlt = 226,
|
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).
|
* C2C input-status notify — the "对方正在输入…" push. subMsgType 0x115 (277).
|
||||||
* RE-confirmed against `wrapper.linux.node`
|
* RE-confirmed against `wrapper.linux.node`
|
||||||
|
|||||||
Reference in new issue
Block a user