feat(onebot): report group special title grant as notify/title
Decode the 0x2DC subType-16 field13==6 push: eventParam carries the member
uin (f5) and a gray-tip template (f2) whose last rich token holds the title
text. Emit notify/title {group_id, user_id, title}, matching NapCat. Field
layout taken from a real on-wire sample, not ported blindly.
This commit is contained in:
7 files changed
+133
-2
No files matched your search
@@ -14,7 +14,7 @@ import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/protocol/qq-info';
|
||||
// inline-extract the kind.
|
||||
import type {
|
||||
GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup, GroupAdmin,
|
||||
InputStatusNotify, NotifyMessageBody, GroupNameChange,
|
||||
InputStatusNotify, NotifyMessageBody, GroupNameChange, GroupSpecialTitleChange,
|
||||
} from '@snowluma/proto-defs/notify';
|
||||
import type { PushMsg } from '@snowluma/proto-defs/message';
|
||||
import type {
|
||||
@@ -302,6 +302,56 @@ describe('parseMsgPush Event0x210 subType=277 (input status → 对方正在输
|
||||
});
|
||||
});
|
||||
|
||||
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
|
||||
// is the last <{…}> token's text.
|
||||
type GroupTitleChangeEvent = Extract<QQEventVariant, { kind: 'group_title_change' }>;
|
||||
|
||||
const TIP = '恭喜<{"cmd":5,"data":"3433035623","text":"星屿"}>获得群主授予的'
|
||||
+ '<{"cmd":1,"data":"https://qun.qq.com/x?medal=302&uin=3433035623","text":"摸鱼冠军",'
|
||||
+ '"url":"https://qun.qq.com/x?medal=302&uin=3433035623"}>头衔';
|
||||
|
||||
function makeTitlePacket(memberUin: number, tip: string): PacketInfo {
|
||||
const notify = protobuf_encode<NotifyMessageBody>({
|
||||
groupUin: GROUP_ID,
|
||||
field13: 6,
|
||||
eventParam: protobuf_encode<GroupSpecialTitleChange>({ tipText: tip, memberUin }),
|
||||
});
|
||||
const content = new Uint8Array(7 + notify.length);
|
||||
content.set(notify, 7);
|
||||
const body = protobuf_encode<PushMsg>({
|
||||
message: {
|
||||
responseHead: { fromUin: 0, type: 0, sigMap: 0 },
|
||||
contentHead: { msgType: 732, subType: 16, timestamp: 1710000000 },
|
||||
body: { msgContent: content },
|
||||
},
|
||||
status: 0,
|
||||
});
|
||||
return { pid: 1, uin: SELF_UIN, serviceCmd: MSG_PUSH_CMD, seqId: 1, retCode: 0, fromClient: false, body };
|
||||
}
|
||||
|
||||
it('emits group_title_change with the granted title + member', () => {
|
||||
const [event] = parseMsgPush(
|
||||
makeTitlePacket(22222, TIP),
|
||||
makeIdentity([makeGroupMember(22222, 'u_member')]),
|
||||
) as GroupTitleChangeEvent[];
|
||||
|
||||
expect(event.kind).toBe('group_title_change');
|
||||
expect(event.groupId).toBe(GROUP_ID);
|
||||
expect(event.userUin).toBe(22222);
|
||||
expect(event.title).toBe('摸鱼冠军'); // last <{…}> token's text
|
||||
});
|
||||
|
||||
it('drops a title tip with no parseable title token', () => {
|
||||
const events = parseMsgPush(
|
||||
makeTitlePacket(22222, '恭喜获得头衔'),
|
||||
makeIdentity(),
|
||||
);
|
||||
expect(events).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseMsgPush Event0x2DC subType=16 field13=12 (group name change)', () => {
|
||||
// RE cross-ref: Lagrange Event0x2DCSubType16Field13.GroupNameChangeNotice = 12,
|
||||
// EventParam(f5) → GroupNameChange{f2=name}, operator = NotifyMessageBody.f21.
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
convertGroupMsgEmojiLike,
|
||||
convertGroupMute,
|
||||
convertGroupNameChange,
|
||||
convertGroupTitleChange,
|
||||
convertGroupPoke,
|
||||
convertGroupRecall,
|
||||
} from './to-notice';
|
||||
@@ -83,6 +84,7 @@ const CONVERTERS: ConverterRegistry = {
|
||||
friend_add: convertFriendAdd,
|
||||
friend_input_status: convertFriendInputStatus,
|
||||
group_name_change: convertGroupNameChange,
|
||||
group_title_change: convertGroupTitleChange,
|
||||
group_card_change: convertGroupCardChange,
|
||||
group_msg_emoji_like: convertGroupMsgEmojiLike,
|
||||
// Requests.
|
||||
|
||||
@@ -20,6 +20,7 @@ type GroupMsgEmojiLike = Extract<QQEventVariant, { kind: 'group_msg_emoji_like'
|
||||
type FriendInputStatus = Extract<QQEventVariant, { kind: 'friend_input_status' }>;
|
||||
type GroupNameChange = Extract<QQEventVariant, { kind: 'group_name_change' }>;
|
||||
type GroupCardChange = Extract<QQEventVariant, { kind: 'group_card_change' }>;
|
||||
type GroupTitleChange = Extract<QQEventVariant, { kind: 'group_title_change' }>;
|
||||
|
||||
export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMemberJoin): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
@@ -171,6 +172,18 @@ export function convertGroupCardChange(ctx: ConverterContext, event: GroupCardCh
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupTitleChange(ctx: ConverterContext, event: GroupTitleChange): JsonObject {
|
||||
// Mirrors NapCat's OB11GroupTitleEvent: notify/title with the recipient's uin
|
||||
// and the granted title text.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'title',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
title: event.title,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupNameChange(ctx: ConverterContext, event: GroupNameChange): JsonObject {
|
||||
// Mirrors NapCat's OB11GroupNameEvent: notify/group_name with the operator's
|
||||
// uin as user_id and the new name in `name_new`.
|
||||
|
||||
@@ -72,6 +72,7 @@ const NOTICE_KINDS = [
|
||||
'friend_add',
|
||||
'friend_input_status',
|
||||
'group_name_change',
|
||||
'group_title_change',
|
||||
'group_card_change',
|
||||
'group_msg_emoji_like',
|
||||
] as const satisfies readonly QQEventVariant['kind'][];
|
||||
|
||||
@@ -271,6 +271,17 @@ export interface GroupNameChange {
|
||||
name?: pb<2, string>;
|
||||
}
|
||||
|
||||
// Group special-title granted (Event 0x2DC subType 16, NotifyMessageBody.field13
|
||||
// == 6). Rides in `NotifyMessageBody.eventParam` (field 5). Field layout captured
|
||||
// on-wire: f2 = the gray-tip template text ("恭喜<{…}>获得群主授予的<{…"text":TITLE…}>头衔"),
|
||||
// f5 = the member uin who received the title. The title text itself is embedded in
|
||||
// the last `<{…}>` rich token of f2 (the kernel parses that template into a clean
|
||||
// string; on the raw wire we parse it ourselves).
|
||||
export interface GroupSpecialTitleChange {
|
||||
tipText?: pb<2, string>;
|
||||
memberUin?: pb<5, uint_32>;
|
||||
}
|
||||
|
||||
// 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`
|
||||
|
||||
@@ -307,6 +307,17 @@ export interface GroupCardChangeEvent extends QQEvent {
|
||||
cardOld: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A group member was granted a special title (群头衔) — Event 0x2DC subType 16,
|
||||
* field13 == 6. Maps to OB11 `notice/notify` `sub_type:'title'`.
|
||||
*/
|
||||
export interface GroupTitleChangeEvent extends QQEvent {
|
||||
kind: 'group_title_change';
|
||||
groupId: number;
|
||||
userUin: number; // the member who received the title
|
||||
title: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group name changed (Event 0x2DC subType 16, field13 == 12). Mirrors NapCat's
|
||||
* OB11GroupNameEvent → `notice/notify` `sub_type:'group_name'`.
|
||||
@@ -352,4 +363,5 @@ export type QQEventVariant =
|
||||
| PttTransResultEvent
|
||||
| FriendInputStatusEvent
|
||||
| GroupNameChangeEvent
|
||||
| GroupCardChangeEvent;
|
||||
| GroupCardChangeEvent
|
||||
| GroupTitleChangeEvent;
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
GroupMsgEmojiLikeEvent,
|
||||
GroupMuteEvent,
|
||||
GroupNameChangeEvent,
|
||||
GroupTitleChangeEvent,
|
||||
GroupPokeEvent,
|
||||
GroupRecallEvent,
|
||||
QQEventVariant,
|
||||
@@ -12,6 +13,7 @@ import type {
|
||||
import type {
|
||||
GroupMute,
|
||||
GroupNameChange,
|
||||
GroupSpecialTitleChange,
|
||||
GroupReactNotify,
|
||||
NotifyMessageBody,
|
||||
} from '@snowluma/proto-defs/notify';
|
||||
@@ -129,12 +131,14 @@ const GROUP_REACT_DISCRIMINATOR = 35;
|
||||
// `NotifyMessageBody.field13`. RE cross-ref (Lagrange Event0x2DCSubType16Field13,
|
||||
// itself RE'd from wrapper.linux.node): 6=special title, 12=name change, 23=todo,
|
||||
// 35=emoji reaction. We peek field13 off the shared NotifyMessageBody, then branch.
|
||||
const SUBTYPE16_SPECIAL_TITLE = 6;
|
||||
const SUBTYPE16_GROUP_NAME_CHANGE = 12;
|
||||
|
||||
function decodeSubType16(ctx: MsgPushContext): QQEventVariant[] {
|
||||
if (ctx.content.length <= GROUP_REACT_PREFIX_BYTES) return [];
|
||||
const field13 = protobuf_decode<NotifyMessageBody>(ctx.content.subarray(GROUP_REACT_PREFIX_BYTES))?.field13 ?? 0;
|
||||
switch (field13) {
|
||||
case SUBTYPE16_SPECIAL_TITLE: return decodeGroupTitle(ctx);
|
||||
case SUBTYPE16_GROUP_NAME_CHANGE: return decodeGroupName(ctx);
|
||||
case GROUP_REACT_DISCRIMINATOR: return decodeGroupMsgEmojiLike(ctx);
|
||||
default:
|
||||
@@ -143,6 +147,44 @@ function decodeSubType16(ctx: MsgPushContext): QQEventVariant[] {
|
||||
}
|
||||
}
|
||||
|
||||
// field13 == 6: a member was granted a special title. eventParam carries the
|
||||
// member uin (f5) + a gray-tip template string (f2); the title text is the last
|
||||
// `<{"…","text":TITLE,…}>` rich token in that string (on-wire captured shape —
|
||||
// the kernel resolves the template to a clean string, we parse it here).
|
||||
function decodeGroupTitle(ctx: MsgPushContext): QQEventVariant[] {
|
||||
const notify = protobuf_decode<NotifyMessageBody>(ctx.content.subarray(GROUP_REACT_PREFIX_BYTES));
|
||||
const param = notify?.eventParam
|
||||
? protobuf_decode<GroupSpecialTitleChange>(notify.eventParam)
|
||||
: undefined;
|
||||
const userUin = param?.memberUin ?? 0;
|
||||
const title = extractTitleFromTip(param?.tipText ?? '');
|
||||
if (!userUin || !title) return [];
|
||||
const ev: GroupTitleChangeEvent = {
|
||||
kind: 'group_title_change',
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: notify?.groupUin ?? 0,
|
||||
userUin,
|
||||
title,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
|
||||
// The tip text is "恭喜<{member}>获得群主授予的<{…"text":TITLE…}>头衔" — the title is
|
||||
// the `text` of the LAST `<{…}>` rich token (the one just before "头衔"). Tokens
|
||||
// are flat JSON with no `<`/`>` inside, so a non-greedy scan is safe.
|
||||
function extractTitleFromTip(text: string): string {
|
||||
const tokens = text.match(/<\{[^<>]*\}>/g);
|
||||
if (!tokens || tokens.length === 0) return '';
|
||||
const last = tokens[tokens.length - 1];
|
||||
try {
|
||||
const parsed = JSON.parse(last.slice(1, -1)) as { text?: string };
|
||||
return parsed.text ?? '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// field13 == 12: group renamed. New name is nested in `eventParam` as a
|
||||
// `GroupNameChange` (field 2); operator is `NotifyMessageBody.operatorUid`.
|
||||
function decodeGroupName(ctx: MsgPushContext): QQEventVariant[] {
|
||||
|
||||
Reference in new issue
Block a user