From 652b5d6118dfe04729d56278a88bd6cbefd38c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Mon, 3 Nov 2025 23:11:48 +0800 Subject: [PATCH] Enhance GrayTip JSON event handling and types Added the XmlToJsonParam interface and extended the GrayTipElement type to support additional JSON event fields. Updated group API logic to handle busiId as string or number and improved event type checks for robustness. --- src/core/types/element.ts | 39 ++++++++++++++++++++++++++++----------- src/onebot/api/group.ts | 7 ++++--- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/core/types/element.ts b/src/core/types/element.ts index a40a877c..1f6f057c 100644 --- a/src/core/types/element.ts +++ b/src/core/types/element.ts @@ -20,16 +20,16 @@ export interface SendElementBase { } type ElementBase< - K extends keyof ElementFullBase, - S extends Partial<{ [P in K]: keyof NonNullable | Array> }> = object + K extends keyof ElementFullBase, + S extends Partial<{ [P in K]: keyof NonNullable | Array> }> = object > = { - [P in K]: - S[P] extends Array + [P in K]: + S[P] extends Array ? Pick, U & keyof NonNullable> : S[P] extends keyof NonNullable - ? Pick, S[P]> - : NonNullable; -}; + ? Pick, S[P]> + : NonNullable; + }; export interface TextElement { content: string; @@ -63,6 +63,20 @@ export interface GrayTipRovokeElement { wording: string; // 自定义的撤回提示语 } +export interface XmlToJsonParam { + busiType: string; + busiId: string; + c2cType: number; + serviceType: number; + ctrlFlag: number; + content: string; + templId: string; + seqId: string; + templParam: Map; + pbReserv: null | string; + members: Map; +} + export interface GrayTipElement { subElementType: NTGrayTipElementSubTypeV2; revokeElement: GrayTipRovokeElement; @@ -74,8 +88,11 @@ export interface GrayTipElement { templId: string; }; jsonGrayTipElement: { - busiId?: number; + busiId?: number | string; jsonStr: string; + recentAbstract?: string; + isServer?: boolean; + xmlToJsonParam?: XmlToJsonParam; }; } @@ -352,7 +369,7 @@ export type SendPicElement = SendElementBase & ElementBase<'pic export type SendPttElement = SendElementBase & ElementBase<'pttElement', { pttElement: ['fileName', 'filePath', 'md5HexStr', 'fileSize', 'duration', 'formatType', 'voiceType', - 'voiceChangeType', 'canConvert2Text', 'waveAmplitudes', 'fileSubId', 'playState', 'autoConvertText', 'storeID', 'otherBusinessInfo'] + 'voiceChangeType', 'canConvert2Text', 'waveAmplitudes', 'fileSubId', 'playState', 'autoConvertText', 'storeID', 'otherBusinessInfo']; }>; export type SendFileElement = SendElementBase & ElementBase<'fileElement'>; @@ -368,5 +385,5 @@ export type SendShareLocationElement = SendElementBase & ElementBase<'multiForwardMsgElement'>; export type SendMessageElement = SendTextElement | SendPttElement | - SendPicElement | SendReplyElement | SendFaceElement | SendMarketFaceElement | SendFileElement | - SendVideoElement | SendArkElement | SendMarkdownElement | SendShareLocationElement; + SendPicElement | SendReplyElement | SendFaceElement | SendMarketFaceElement | SendFileElement | + SendVideoElement | SendArkElement | SendMarkdownElement | SendShareLocationElement; diff --git a/src/onebot/api/group.ts b/src/onebot/api/group.ts index 07913a15..1be81313 100644 --- a/src/onebot/api/group.ts +++ b/src/onebot/api/group.ts @@ -350,15 +350,16 @@ export class OneBotGroupApi { // return await this.obContext.apis.GroupApi.parseGroupIncreaseEvent(msg.peerUid, grayTipElement); } } else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_JSON) { - // 解析json事件 - if (grayTipElement.jsonGrayTipElement.busiId === 1061) { + // 解析json事件 busiId好像是string类型的? + if (grayTipElement.jsonGrayTipElement.busiId?.toString() === '1061') { return await this.parsePaiYiPai(msg, grayTipElement.jsonGrayTipElement.jsonStr); } else if (grayTipElement.jsonGrayTipElement.busiId === JsonGrayBusiId.AIO_GROUP_ESSENCE_MSG_TIP) { return await this.parseEssenceMsg(msg, grayTipElement.jsonGrayTipElement.jsonStr); - } else if (+(grayTipElement.jsonGrayTipElement.busiId ?? 0) === 51) { + } else if ((grayTipElement.jsonGrayTipElement.busiId ?? 0).toString() === '51') { // 51是什么?{"align":"center","items":[{"txt":"下一秒起床通过王者荣耀加入群","type":"nor"}] return await this.parse51TypeEvent(msg, grayTipElement); } else { + console.log('Unknown JSON event:', grayTipElement.jsonGrayTipElement, JSON.stringify(grayTipElement)); return await this.parseOtherJsonEvent(msg, grayTipElement.jsonGrayTipElement.jsonStr, this.core.context); } }