feat(onebot): add group_name to group message events (#212)
Group message events (message + message_sent) now carry group_name — a non-standard but common OneBot extension. The name comes from the message's own wire field (ResponseGrp field 7, accurate even right after a rename), falling back to the identity group cache, else '' when neither is available. It's resolved in the group-message decoder, where both the wire head and the identity cache are already at hand, so the converter just passes it through (no ConverterContext change). Verified live (tempserver): real inbound group messages from a non-self account carry group_name set to the actual group name.
This commit is contained in:
5 files changed
+15
-3
No files matched your search
@@ -133,6 +133,10 @@ export interface FriendMessage extends QQEvent {
|
||||
export interface GroupMessage extends QQEvent {
|
||||
kind: 'group_message';
|
||||
groupId: number;
|
||||
/** Group display name. From the message's own wire field (ResponseGrp
|
||||
* field 7 — accurate even right after a rename), falling back to the
|
||||
* identity group cache, else '' when neither is available. */
|
||||
groupName: string;
|
||||
senderUin: number;
|
||||
senderNick: string;
|
||||
senderCard: string;
|
||||
|
||||
@@ -12,6 +12,7 @@ export const decodeGroupMessage: MsgPushDecoder = (ctx) => {
|
||||
msgId: ctx.head.msgId & 0x7FFFFFFF,
|
||||
elements: decodeRichBody(ctx.body, true),
|
||||
groupId: 0,
|
||||
groupName: '',
|
||||
senderNick: '',
|
||||
senderCard: '',
|
||||
senderRole: '',
|
||||
@@ -43,5 +44,9 @@ export const decodeGroupMessage: MsgPushDecoder = (ctx) => {
|
||||
} else if (!ev.senderNick && grp?.memberCard) {
|
||||
ev.senderNick = grp.memberCard;
|
||||
}
|
||||
// Group name: prefer the message's own wire field (ResponseGrp field 7 —
|
||||
// fresh even right after a rename), fall back to the cached group list, else
|
||||
// leave it empty. `ev.groupId` is set above from grp.groupUin.
|
||||
ev.groupName = grp?.groupName || ctx.identity.findGroup(ev.groupId)?.groupName || '';
|
||||
return [ev];
|
||||
};
|
||||
Reference in new issue
Block a user