feat(onebot): report group name change as notify/group_name

Dispatch the 0x2DC subType-16 push by NotifyMessageBody.field13 (was
emoji-react only); field13==12 decodes eventParam as GroupNameChange and
emits notify/group_name {group_id, user_id=operator, name_new}, matching
NapCat. Emoji-react (field13==35) path unchanged.
This commit is contained in:
DrSmoothl committed 2026-07-07 02:05:52 +08:00
1 parent 852870db59
commit bfde0daab4
7 files changed
+128 -3

No files matched your search

+50 -1
View File
@@ -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,
InputStatusNotify, NotifyMessageBody, GroupNameChange,
} from '@snowluma/proto-defs/notify';
import type { PushMsg } from '@snowluma/proto-defs/message';
import type {
@@ -302,6 +302,55 @@ describe('parseMsgPush Event0x210 subType=277 (input status → 对方正在输
});
});
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.
// The 0x2DC subType16 body carries a 7-byte prefix (groupUin+byte+len) before
// the NotifyMessageBody proto — the decoder strips it via subarray(7).
type GroupNameChangeEvent = Extract<QQEventVariant, { kind: 'group_name_change' }>;
function makeGroupNamePacket(groupUin: number, operatorUid: string, name: string): PacketInfo {
const notify = protobuf_encode<NotifyMessageBody>({
groupUin,
field13: 12,
operatorUid,
eventParam: protobuf_encode<GroupNameChange>({ name }),
});
const content = new Uint8Array(7 + notify.length); // 7-byte prefix + proto
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_name_change with the new name + operator', () => {
const member = makeGroupMember(54321, 'u_operator');
const [event] = parseMsgPush(
makeGroupNamePacket(GROUP_ID, member.uid, '新的群名'),
makeIdentity([member]),
) as GroupNameChangeEvent[];
expect(event.kind).toBe('group_name_change');
expect(event.groupId).toBe(GROUP_ID);
expect(event.name).toBe('新的群名');
expect(event.operatorUin).toBe(54321);
});
it('drops a name-change body with an empty name', () => {
const events = parseMsgPush(
makeGroupNamePacket(GROUP_ID, 'u_operator', ''),
makeIdentity(),
);
expect(events).toEqual([]);
});
});
describe('parseMsgPush Event0x210 subType=139 (self-recall direction)', () => {
// 138 = friend recalled their own message sent to bot
// (peer in friend_recall event = fromUid)
@@ -17,6 +17,7 @@ import {
convertGroupMemberLeave,
convertGroupMsgEmojiLike,
convertGroupMute,
convertGroupNameChange,
convertGroupPoke,
convertGroupRecall,
} from './to-notice';
@@ -80,6 +81,7 @@ const CONVERTERS: ConverterRegistry = {
group_file_upload: convertGroupFileUpload,
friend_add: convertFriendAdd,
friend_input_status: convertFriendInputStatus,
group_name_change: convertGroupNameChange,
group_msg_emoji_like: convertGroupMsgEmojiLike,
// Requests.
friend_request: convertFriendRequest,
@@ -18,6 +18,7 @@ type GroupFileUpload = Extract<QQEventVariant, { kind: 'group_file_upload' }>;
type FriendAdd = Extract<QQEventVariant, { kind: 'friend_add' }>;
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' }>;
export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMemberJoin): JsonObject {
return notice(ctx, event, {
@@ -157,6 +158,18 @@ export function convertFriendAdd(ctx: ConverterContext, event: FriendAdd): JsonO
});
}
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`.
return notice(ctx, event, {
notice_type: 'notify',
sub_type: 'group_name',
group_id: event.groupId,
user_id: event.operatorUin,
name_new: event.name,
});
}
export function convertFriendInputStatus(ctx: ConverterContext, event: FriendInputStatus): JsonObject {
// Mirrors NapCat's OB11InputStatusEvent: notify/input_status with the peer's
// uin, the raw event_type (1 = typing, 3 = recording voice) and status_text.
+1
View File
@@ -71,6 +71,7 @@ const NOTICE_KINDS = [
'group_file_upload',
'friend_add',
'friend_input_status',
'group_name_change',
'group_msg_emoji_like',
] as const satisfies readonly QQEventVariant['kind'][];
+8
View File
@@ -263,6 +263,14 @@ export interface GroupReactNotify {
groupReactionData?: pb<44, GroupReactionData>;
}
// Group-name change (Event 0x2DC subType 16, NotifyMessageBody.field13 == 12).
// Rides in `NotifyMessageBody.eventParam` (field 5). Field layout matches
// Lagrange's `GroupNameChange` (RE'd from wrapper.linux.node): only the new
// name at field 2. The operator uid is `NotifyMessageBody.operatorUid` (f21).
export interface GroupNameChange {
name?: pb<2, string>;
}
// 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`
+13 -1
View File
@@ -294,6 +294,17 @@ export interface PttTransResultEvent extends QQEvent {
text: string;
}
/**
* Group name changed (Event 0x2DC subType 16, field13 == 12). Mirrors NapCat's
* OB11GroupNameEvent → `notice/notify` `sub_type:'group_name'`.
*/
export interface GroupNameChangeEvent extends QQEvent {
kind: 'group_name_change';
groupId: number;
operatorUin: number; // who renamed the group
name: string; // the new group name
}
/**
* C2C "对方正在输入…" input-status push (Event 0x210 subType 0x115 / 277).
* `eventType` 1 = typing, 3 = recording a voice message. Mirrors NapCat's
@@ -326,4 +337,5 @@ export type QQEventVariant =
| FriendAddEvent
| GroupMsgEmojiLikeEvent
| PttTransResultEvent
| FriendInputStatusEvent;
| FriendInputStatusEvent
| GroupNameChangeEvent;
@@ -4,12 +4,14 @@ import type {
GroupEssenceEvent,
GroupMsgEmojiLikeEvent,
GroupMuteEvent,
GroupNameChangeEvent,
GroupPokeEvent,
GroupRecallEvent,
QQEventVariant,
} from '../../events';
import type {
GroupMute,
GroupNameChange,
GroupReactNotify,
NotifyMessageBody,
} from '@snowluma/proto-defs/notify';
@@ -28,7 +30,7 @@ const unknownLog = createLogger('MsgPush.Unknown');
export const decodeEvent0x2DC: MsgPushDecoder = (ctx) => {
switch (ctx.head.subType as Event0x2DCSubType) {
case Event0x2DCSubType.GroupMuteNotice: return decodeGroupMute(ctx);
case Event0x2DCSubType.GroupMsgEmojiLikeNotice: return decodeGroupMsgEmojiLike(ctx);
case Event0x2DCSubType.GroupMsgEmojiLikeNotice: return decodeSubType16(ctx);
case Event0x2DCSubType.GroupRecallNotice: return decodeGroupRecall(ctx);
case Event0x2DCSubType.GroupGreyTipNotice: return decodeGroupGreyTip(ctx);
case Event0x2DCSubType.GroupEssenceNotice: return decodeGroupEssence(ctx);
@@ -123,6 +125,44 @@ const GROUP_REACT_PREFIX_BYTES = 7;
// for other notify variants, only 35 means "emoji react". Anything
// else falls through to MsgPush.Unknown for protocol-drift visibility.
const GROUP_REACT_DISCRIMINATOR = 35;
// Event 0x2DC subType 16 multiplexes several group notices, discriminated by
// `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_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_GROUP_NAME_CHANGE: return decodeGroupName(ctx);
case GROUP_REACT_DISCRIMINATOR: return decodeGroupMsgEmojiLike(ctx);
default:
unknownLog.debug('Event0x2DC subType=16 unhandled field13=%d', field13);
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[] {
const notify = protobuf_decode<NotifyMessageBody>(ctx.content.subarray(GROUP_REACT_PREFIX_BYTES));
const name = notify?.eventParam ? (protobuf_decode<GroupNameChange>(notify.eventParam)?.name ?? '') : '';
if (!name) return [];
const groupId = notify?.groupUin ?? 0;
const ev: GroupNameChangeEvent = {
kind: 'group_name_change',
time: ctx.head.timestamp,
selfUin: ctx.selfUin,
groupId,
// Operator is a group member → resolves from the roster. Fall back to 0
// (not ctx.fromUin, which on a 0x2DC push is the group id) so an
// unresolved operator never surfaces the group id as user_id.
operatorUin: resolveUidToUin(ctx.identity, groupId, notify?.operatorUid ?? '', 0),
name,
};
return [ev];
}
function decodeGroupMsgEmojiLike(ctx: MsgPushContext): QQEventVariant[] {
if (ctx.content.length <= GROUP_REACT_PREFIX_BYTES) return [];