feat(msg-push): decode group message emoji reactions (Event0x2DC subType=16)

QQ has been pushing Event0x2DC subType=16 every time someone tapped
an emoji on a message in a group, and we were dropping it silently
(only surfacing the PR5 [MsgPush.Unknown] debug line that prompted
this issue). Now we decode it into a first-class event and fan it
out to OneBot clients.

Wire details (cribbed from NapCat's GroupReactNotify transformer):
  - body.msgContent has a 7-byte magic prefix; strip before decoding.
  - GroupReactNotify { groupUin(4), field13(13), groupReactionData(44) }.
  - field13 is a discriminator — same subType is reused for other
    notify variants, only 35 means "emoji react". Other values now
    fall through to MsgPush.Unknown so we still spot future variants.
  - Inside groupReactionData (3-level nested data wrapper, ugh):
      code         emoji id (system face = numeric str, market = code)
      count        usually 1
      operatorUid  needs identity.findUinByUid to resolve to uin
      type         1 = add, else = remove
      target.seq   msg_seq of the reacted-to message

New event kind `group_msg_emoji_like` flows through the standard
pipeline: bridge event → event-bus → converter → OneBot wire.
Converter emits the gocqhttp / NapCat extension shape:

  notice_type:  group_msg_emoji_like
  sub_type:     add | remove
  group_id, user_id, operator_id, message_id, message_seq,
  likes: [{ emoji_id, count }]

message_id is reconstructed via hashMessageIdInt32(msgSeq, groupId,
GROUP_MESSAGE_EVENT) so it matches whatever id the bot originally
handed out for the message being reacted to, even if it's no longer
in the message store.

formatEvent also gets a case so the [Event] log reads cleanly:
  表情回应 [群名(123)] | [Alice(99999)] +[76] msgSeq=4242

7 new tests cover the happy path, type=2 (remove), field13!=35
(routed to MsgPush.Unknown), prefix-too-short edge, converter
shape both for add and remove, and the formatEvent string.
This commit is contained in:
DrSmoothl committed 2026-05-18 14:06:44 +08:00
1 parent a07521d9de
commit 24056c3de0
9 files changed
+358 -3

No files matched your search

+18 -1
View File
@@ -230,6 +230,22 @@ export interface FriendAddEvent extends QQEvent {
userUin: number;
}
export interface GroupMsgEmojiLikeEvent extends QQEvent {
kind: 'group_msg_emoji_like';
groupId: number;
operatorUin: number;
operatorUid: string;
/** Sequence of the message that was reacted to (server-assigned msg_seq). */
msgSeq: number;
/** Emoji ID. QQ system faces are short numeric strings; market faces
* are alphanumeric. We keep the wire string verbatim. */
emojiId: string;
/** Multiplicity of the reaction event. Usually 1. */
count: number;
/** True when the reaction is being added; false when removed. */
isAdd: boolean;
}
export type QQEventVariant =
| FriendMessage
| GroupMessage
@@ -246,4 +262,5 @@ export type QQEventVariant =
| GroupPokeEvent
| GroupEssenceEvent
| GroupFileUploadEvent
| FriendAddEvent;
| FriendAddEvent
| GroupMsgEmojiLikeEvent;
@@ -1,12 +1,14 @@
// Handles Event0x2DC wrapper (732). Internal switch on subType dispatches
// to GroupMute (12) / GroupRecall (17) / GroupGreyTip (20) / GroupEssence (21).
// to GroupMute (12) / GroupMsgEmojiLike (16) / GroupRecall (17) /
// GroupGreyTip (20) / GroupEssence (21).
import { protoDecode } from '../../../protobuf/decode';
import {
GroupMuteSchema, NotifyMessageBodySchema,
GroupMuteSchema, NotifyMessageBodySchema, GroupReactNotifySchema,
} from '../../proto/notify';
import type {
GroupMuteEvent, GroupRecallEvent, GroupPokeEvent, GroupEssenceEvent,
GroupMsgEmojiLikeEvent,
QQEventVariant,
} from '../../events';
import type { MsgPushDecoder } from '../registry';
@@ -23,6 +25,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.GroupRecallNotice: return decodeGroupRecall(ctx);
case Event0x2DCSubType.GroupGreyTipNotice: return decodeGroupGreyTip(ctx);
case Event0x2DCSubType.GroupEssenceNotice: return decodeGroupEssence(ctx);
@@ -108,3 +111,51 @@ function decodeGroupEssence(ctx: MsgPushContext): QQEventVariant[] {
};
return [ev];
}
// Magic prefix QQ prepends to the GroupReactNotify payload inside
// body.msgContent for Event0x2DC subType=16. Same value NapCat strips
// (see api/group.ts: `msgContent?.slice(7)`).
const GROUP_REACT_PREFIX_BYTES = 7;
// Discriminator on GroupReactNotify.field13 — same subType is reused
// 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;
function decodeGroupMsgEmojiLike(ctx: MsgPushContext): QQEventVariant[] {
if (ctx.content.length <= GROUP_REACT_PREFIX_BYTES) return [];
const payload = ctx.content.subarray(GROUP_REACT_PREFIX_BYTES);
const notify = protoDecode(payload, GroupReactNotifySchema);
if (!notify) return [];
if ((notify.field13 ?? 0) !== GROUP_REACT_DISCRIMINATOR) {
unknownLog.debug('Event0x2DC subType=16 unhandled field13=%d (expected %d for emoji react)',
notify.field13 ?? 0, GROUP_REACT_DISCRIMINATOR);
return [];
}
const content = notify.groupReactionData?.data?.data?.groupReactionDataContent;
const target = notify.groupReactionData?.data?.data?.groupReactionTarget;
if (!content) return [];
const groupId = Number(notify.groupUin ?? 0n);
const operatorUid = content.operatorUid ?? '';
const emojiId = content.code ?? '';
const count = content.count ?? 1;
// type is QQ's add/remove discriminator: 1 = react added, 2 = react
// removed. Older payloads occasionally omit it; default to "add"
// since most clients can only generate add events.
const isAdd = (content.type ?? 1) === 1;
const msgSeq = Number(target?.seq ?? 0n);
const ev: GroupMsgEmojiLikeEvent = {
kind: 'group_msg_emoji_like',
time: ctx.head.timestamp,
selfUin: ctx.selfUin,
groupId,
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid, ctx.fromUin),
operatorUid,
msgSeq,
emojiId,
count,
isAdd,
};
return [ev];
}
@@ -21,6 +21,7 @@ export enum PkgType {
export enum Event0x2DCSubType {
GroupMuteNotice = 12,
GroupMsgEmojiLikeNotice = 16,
GroupRecallNotice = 17,
GroupGreyTipNotice = 20,
GroupEssenceNotice = 21,
+38
View File
@@ -205,3 +205,41 @@ export const NotifyMessageBodySchema = {
msgSequence: { field: 37, type: 'uint32' as const },
field39: { field: 39, type: 'uint32' as const },
} satisfies ProtoSchema;
// ─── Event0x2DC subType=16: GroupMsgEmojiLike ──────────────────────────────
//
// QQ pushes a Group message emoji reaction (someone tapped an emoji on a
// message in a group). The payload nesting matches NapCat's transformer
// (packet/transformer/proto/message/message.ts → GroupReactNotify); the
// outermost message is preceded by a 7-byte prefix that must be stripped
// before decoding (see the call site).
export const GroupReactionDataInnerDataTargetSchema = {
seq: { field: 1, type: 'uint64' as const },
} satisfies ProtoSchema;
export const GroupReactionDataContentSchema = {
code: { field: 1, type: 'string' as const },
count: { field: 3, type: 'uint32' as const },
operatorUid: { field: 4, type: 'string' as const },
type: { field: 5, type: 'uint32' as const },
} satisfies ProtoSchema;
export const GroupReactionDataInnerDataSchema = {
groupReactionTarget: { field: 2, type: 'message' as const, schema: GroupReactionDataInnerDataTargetSchema },
groupReactionDataContent: { field: 3, type: 'message' as const, schema: GroupReactionDataContentSchema },
} satisfies ProtoSchema;
export const GroupReactionDataInnerSchema = {
data: { field: 1, type: 'message' as const, schema: GroupReactionDataInnerDataSchema },
} satisfies ProtoSchema;
export const GroupReactionDataSchema = {
data: { field: 1, type: 'message' as const, schema: GroupReactionDataInnerSchema },
} satisfies ProtoSchema;
export const GroupReactNotifySchema = {
groupUin: { field: 4, type: 'uint64' as const },
field13: { field: 13, type: 'uint32' as const },
groupReactionData: { field: 44, type: 'message' as const, schema: GroupReactionDataSchema },
} satisfies ProtoSchema;