From 045e120854bf6fedeb73a0c27b7033b496212009 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: Fri, 26 Jul 2024 15:38:43 +0800 Subject: [PATCH] refactor: type --- src/core/src/entities/msg.ts | 260 ++++++++++-------- .../src/services/NodeIKernelMsgService.ts | 4 +- .../services/NodeIKernelRichMediaService.ts | 28 +- 3 files changed, 177 insertions(+), 115 deletions(-) diff --git a/src/core/src/entities/msg.ts b/src/core/src/entities/msg.ts index 2d438b51..1f8f3fb2 100644 --- a/src/core/src/entities/msg.ts +++ b/src/core/src/entities/msg.ts @@ -55,22 +55,24 @@ export enum ElementType { TASKTOPMSG = 29, RECOMMENDEDMSG = 43, ACTIONBAR = 44 +} +export interface ActionBarElement { + rows: InlineKeyboardRow[]; + botAppid: string; } export interface SendActionBarElement { elementType: ElementType.ACTIONBAR; elementId: string; - actionBarElement: { - rows: InlineKeyboardRow[]; - botAppid: string; - } + actionBarElement: ActionBarElement; +} +export interface RecommendedMsgElement { + rows: InlineKeyboardRow[]; + botAppid: string; } export interface SendRecommendedMsgElement { elementType: ElementType.RECOMMENDEDMSG; elementId: string; - recommendedMsgElement: { - rows: InlineKeyboardRow[]; - botAppid: string; - } + recommendedMsgElement: RecommendedMsgElement; } export interface InlineKeyboardButton { id: string; @@ -93,67 +95,72 @@ export interface TofuElementContent { color: string; tittle: string; } +export interface TaskTopMsgElement { + msgTitle: string; + msgSummary: string; + iconUrl: string; + topMsgType: number; +} export interface SendTaskTopMsgElement { elementType: ElementType.TASKTOPMSG; elementId: string; - taskTopMsgElement: { - msgTitle: string; - msgSummary: string; - iconUrl: string; - topMsgType: number; - } + taskTopMsgElement: TaskTopMsgElement; +} +export interface TofuRecordElement { + type: number; + busiid: string; + busiuuid: string; + descriptionContent: string; + contentlist: TofuElementContent[], + background: string; + icon: string; + uinlist: string[], + uidlist: string[], + busiExtra: string; + updateTime: string; + dependedmsgid: string; + msgtime: string; + onscreennotify: boolean; } export interface SendTofuRecordElement { elementType: ElementType.TOFURECORD; elementId: string; - tofuRecordElement: { - type: number; - busiid: string; - busiuuid: string; - descriptionContent: string; - contentlist: TofuElementContent[], - background: string; - icon: string; - uinlist: string[], - uidlist: string[], - busiExtra: string; - updateTime: string; - dependedmsgid: string; - msgtime: string; - onscreennotify: boolean; + tofuRecordElement: TofuRecordElement; +} + +export interface FaceBubbleElement { + faceCount: number; + faceSummary: string; + faceFlag: number; + content: string; + oldVersionStr: string; + faceType: number; + others: string; + yellowFaceInfo: { + index: number; + buf: string; + compatibleText: string; + text: string; } } export interface SendFaceBubbleElement { elementType: ElementType.FACEBUBBLE; elementId: string; - faceBubbleElement: { - faceCount: number; - faceSummary: string; - faceFlag: number; - content: string; - oldVersionStr: string; - faceType: number; - others: string; - yellowFaceInfo: { - index: number; - buf: string; - compatibleText: string; - text: string; - } - } + faceBubbleElement: FaceBubbleElement; } +export interface AvRecordElement { + type: number; + time: string; + text: string; + mainType: number; + hasRead: boolean; + extraType: number; +} export interface SendavRecordElement { elementType: ElementType.AVRECORD; elementId: string; - avRecordElement: { - type: number; - time: string; - text: string; - mainType: number; - hasRead: boolean; - extraType: number; - } + avRecordElement: AvRecordElement; } export interface YoloUserInfo { uid: string; @@ -170,37 +177,40 @@ export interface SendInlineKeyboardElement { } } +export interface YoloGameResultElement { + UserInfo: YoloUserInfo[]; +} export interface SendYoloGameResultElement { elementType: ElementType.YOLOGAMERESULT; - yoloGameResultElement: { - UserInfo: YoloUserInfo[]; - } + yoloGameResultElement: YoloGameResultElement +} +export interface GiphyElement { + id: string; + isClip: boolean; + width: number; + height: number; } export interface SendGiphyElement { elementType: ElementType.GIPHY; elementId: string; - giphyElement: { - id: string; - isClip: boolean; - width: number; - height: number; - } + giphyElement: GiphyElement; } export interface SendWalletElement { elementType: ElementType.UNKNOWN;//不做 设置位置 elementId: string; walletElement: {} } +export interface CalendarElement { + summary: string; + msg: string; + expireTimeMs: string; + schemaType: number; + schema: string +} export interface SendCalendarElement { elementType: ElementType.CALENDAR; elementId: string; - calendarElement: { - summary: string; - msg: string; - expireTimeMs: string; - schemaType: number; - schema: string - } + calendarElement: CalendarElement; } export interface SendliveGiftElement { elementType: ElementType.LIVEGIFT; @@ -252,32 +262,18 @@ export enum PicSubType { export interface SendPicElement { elementType: ElementType.PIC; elementId: string; - picElement: { - md5HexStr: string; - fileSize: number | string; - picWidth: number; - picHeight: number; - fileName: string; - sourcePath: string; - original: boolean; - picType: PicType; - picSubType: PicSubType; - fileUuid: string; - fileSubId: string; - thumbFileSize: number; - summary: string; - }; + picElement:PicElement +} +export interface ReplyElement { + replayMsgSeq: string; + replayMsgId: string; + senderUin: string; + senderUinStr: string; } - export interface SendReplyElement { elementType: ElementType.REPLY; elementId: string; - replyElement: { - replayMsgSeq: string; - replayMsgId: string; - senderUin: string; - senderUinStr: string; - } + replyElement: ReplyElement } export interface SendFaceElement { @@ -293,10 +289,11 @@ export interface SendMarketFaceElement { export interface SendstructLongMsgElement { elementType: ElementType.STRUCTLONGMSG; elementId: string; - structLongMsgElement: { - xmlContent: string; - resId: string; - } + structLongMsgElement: StructLongMsgElement; +} +export interface StructLongMsgElement { + xmlContent: string; + resId: string; } export interface SendactionBarElement { elementType: ElementType.ACTIONBAR; @@ -306,13 +303,14 @@ export interface SendactionBarElement { botAppid: string; } } +export interface ShareLocationElement { + text: string; + ext: string; +} export interface sendShareLocationElement { elementType: ElementType.SHARELOCATION; elementId: string; - shareLocationElement: { - text: string; - ext: string; - } + shareLocationElement?: ShareLocationElement; } export interface FileElement { @@ -356,10 +354,51 @@ export interface SendMarkdownElement { elementId: string; markdownElement: MarkdownElement; } - export type SendMessageElement = SendTextElement | SendPttElement | - SendPicElement | SendReplyElement | SendFaceElement | SendMarketFaceElement | SendFileElement | SendVideoElement | SendArkElement | SendMarkdownElement | sendShareLocationElement + SendPicElement | SendReplyElement | SendFaceElement | SendMarketFaceElement | SendFileElement | + SendVideoElement | SendArkElement | SendMarkdownElement | sendShareLocationElement; +export interface TextElement { + content: string; + atType: number; + atUid: string; + atTinyId: string; + atNtUid: string; +} +export interface MessageElement { + elementType: ElementType, + elementId: string, + extBufForUI: string, + textElement?: TextElement; + faceElement?: FaceElement, + marketFaceElement?: MarkdownElement, + replyElement?: ReplyElement, + picElement?: PicElement, + pttElement?: PttElement, + videoElement?: VideoElement, + grayTipElement?: GrayTipElement, + arkElement?: ArkElement, + fileElement?: FileElement, + liveGiftElement?: null, + markdownElement?: MarkdownElement, + structLongMsgElement?: StructLongMsgElement, + multiForwardMsgElement?: MultiForwardMsgElement, + giphyElement?: GiphyElement, + walletElement?: null, + inlineKeyboardElement?: InlineKeyboardElement, + textGiftElement?: null,//???? + calendarElement?: CalendarElement, + yoloGameResultElement?: YoloGameResultElement, + avRecordElement?: AvRecordElement, + structMsgElement?: null, + faceBubbleElement?: FaceBubbleElement, + shareLocationElement: ShareLocationElement, + tofuRecordElement?: TofuRecordElement, + taskTopMsgElement?: TaskTopMsgElement, + recommendedMsgElement?: RecommendedMsgElement, + actionBarElement?:ActionBarElement + +} export enum AtType { notAt = 0, atAll = 1, @@ -450,18 +489,23 @@ export const IMAGE_HTTP_HOST = 'https://gchat.qpic.cn'; export const IMAGE_HTTP_HOST_NT = 'https://multimedia.nt.qq.com.cn'; export interface PicElement { - picSubType?: number; - originImageUrl: string; // http url, 没有host,host是https://gchat.qpic.cn/, 带download参数的是https://multimedia.nt.qq.com.cn - originImageMd5?: string; - sourcePath: string; // 图片本地路径 - thumbPath: Map; + md5HexStr?: string; + fileSize: number | string;//number picWidth: number; picHeight: number; - fileSize: number; fileName: string; + sourcePath: string; + original: boolean; + picType: PicType; + picSubType?: PicSubType; fileUuid: string; - md5HexStr?: string; -} + fileSubId: string; + thumbFileSize: number; + summary: string; + thumbPath: Map; + originImageMd5?: string; + originImageUrl?: string; // http url, 没有host,host是https://gchat.qpic.cn/, 带download参数的是https://multimedia.nt.qq.com.cn +}; export enum GrayTipElementSubType { INVITE_NEW_MEMBER = 12, diff --git a/src/core/src/services/NodeIKernelMsgService.ts b/src/core/src/services/NodeIKernelMsgService.ts index 3bf2721e..b38321da 100644 --- a/src/core/src/services/NodeIKernelMsgService.ts +++ b/src/core/src/services/NodeIKernelMsgService.ts @@ -1,4 +1,4 @@ -import { ElementType, Peer, RawMessage, SendMessageElement } from '@/core/entities'; +import { ElementType, MessageElement, Peer, RawMessage, SendMessageElement } from '@/core/entities'; import { NodeIKernelMsgListener } from '@/core/listeners/NodeIKernelMsgListener'; import { GeneralCallResult } from '@/core/services/common'; @@ -115,7 +115,7 @@ export interface NodeIKernelMsgService { addLocalTofuRecordMsg(...args: unknown[]): unknown; - addLocalRecordMsg(Peer: Peer, msgId: string, rawMessage: RawMessage, attr: Array | number, front: boolean): Promise; + addLocalRecordMsg(Peer: Peer, msgId: string, ele: MessageElement, attr: Array | number, front: boolean): Promise; deleteMsg(...args: unknown[]): unknown; diff --git a/src/core/src/services/NodeIKernelRichMediaService.ts b/src/core/src/services/NodeIKernelRichMediaService.ts index 94d20ec6..dfe4d11c 100644 --- a/src/core/src/services/NodeIKernelRichMediaService.ts +++ b/src/core/src/services/NodeIKernelRichMediaService.ts @@ -1,4 +1,4 @@ -import { GetFileListParam, Peer } from "../entities"; +import { GetFileListParam, MessageElement, Peer, SendMessageElement } from "../entities"; import { GeneralCallResult } from "./common"; export interface NodeIKernelRichMediaService { @@ -46,7 +46,7 @@ export interface NodeIKernelRichMediaService { } }>; - getRichMediaFileDir(arg1: unknown, arg2: unknown, arg3: unknown): unknown; + getRichMediaFileDir(elementType: number, downType: number, isTemp: boolean): unknown; // this.senderUid = ""; // this.peerUid = ""; @@ -65,7 +65,20 @@ export interface NodeIKernelRichMediaService { // this.elem = msgElement; // this.useHttps = num; - getVideoPlayUrlInVisit(arg: unknown): unknown; + getVideoPlayUrlInVisit(arg: { + downloadType: number, + thumbSize: number, + msgId: string, + msgRandom: string, + msgSeq: string, + msgTime: string, + chatType: number, + senderUid: string, + peerUid: string, + guildId: string, + ele: MessageElement, + useHttps: boolean + }): Promise; isFileExpired(arg: unknown): unknown; @@ -83,7 +96,12 @@ export interface NodeIKernelRichMediaService { // this.fileSize = j2; // this.fileModelId = j3; - downloadFileForFileUuid(peer: Peer, arg1: string, arg3: unknown[]): unknown; + downloadFileForFileUuid(peer: Peer, uuid: string, arg3: { + fileId: string, + fileName: string, + fileSize: string, + fileModelId: string + }[]): unknown; downloadFileByUrlList(arg1: unknown, arg2: unknown): unknown; @@ -133,7 +151,7 @@ export interface NodeIKernelRichMediaService { moveGroupFile(arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown, arg5: unknown): unknown; transGroupFile(arg1: unknown, arg2: unknown): unknown; - + searchGroupFile( keywords: Array, param: {