From b55f35549db9c5c079063f03a6f39a705d57fdf4 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Wed, 27 Mar 2024 20:07:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20report=20forward=20msg=EF=BC=8Cget=5Ffo?= =?UTF-8?q?rward=5Fmsg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ntqqapi/api/msg.ts | 11 ++++++ src/ntqqapi/ntcall.ts | 2 + src/ntqqapi/types/msg.ts | 36 +++++++++++++++++ .../action/go-cqhttp/GetForwardMsg.ts | 39 +++++++++++++++++++ src/onebot11/action/index.ts | 2 + src/onebot11/action/types.ts | 1 + src/onebot11/constructor.ts | 6 +++ src/onebot11/types.ts | 9 ++++- 8 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/onebot11/action/go-cqhttp/GetForwardMsg.ts diff --git a/src/ntqqapi/api/msg.ts b/src/ntqqapi/api/msg.ts index f5e27af..31db052 100644 --- a/src/ntqqapi/api/msg.ts +++ b/src/ntqqapi/api/msg.ts @@ -16,6 +16,17 @@ export interface Peer { } export class NTQQMsgApi { + static async getMultiMsg(peer: Peer, rootMsgId: string, parentMsgId: string) { + return await callNTQQApi({ + methodName: NTQQApiMethod.GET_MULTI_MSG, + args: [{ + peer, + rootMsgId, + parentMsgId + }, null] + }) + } + static async activateGroupChat(groupCode: string) { // await this.fetchRecentContact(); // await sleep(500); diff --git a/src/ntqqapi/ntcall.ts b/src/ntqqapi/ntcall.ts index 480921d..f4d9895 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -25,6 +25,8 @@ export enum NTQQApiMethod { ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息 HISTORY_MSG_998 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat", HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelf", + GET_MULTI_MSG = "nodeIKernelMsgService/getMultiMsg", + LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike", SELF_INFO = "fetchAuthData", FRIENDS = "nodeIKernelBuddyService/getBuddyList", diff --git a/src/ntqqapi/types/msg.ts b/src/ntqqapi/types/msg.ts index c2be236..0c11f51 100644 --- a/src/ntqqapi/types/msg.ts +++ b/src/ntqqapi/types/msg.ts @@ -279,6 +279,34 @@ export interface VideoElement { "sourceVideoCodecFormat"?: number } +export interface MarkdownElement { + content: string, +} + +export interface InlineKeyboardElementRowButton{ + "id": "", + "label": string, + "visitedLabel": string, + "style": 1, // 未知 + "type": 2, // 未知 + "clickLimit": 0, // 未知 + "unsupportTips": "请升级新版手机QQ", + "data": string, + "atBotShowChannelList": false, + "permissionType": 2, + "specifyRoleIds": [], + "specifyTinyids": [], + "isReply": false, + "anchor": 0, + "enter": false, + "subscribeDataTemplateIds": [] +} +export interface InlineKeyboardElement { + rows: [{ + buttons: InlineKeyboardElementRowButton[] + }] +} + export interface TipAioOpGrayTipElement { // 这是什么提示来着? operateType: number, peerUid: string, @@ -329,6 +357,11 @@ export interface TipGroupElement { } } +export interface MultiForwardMsgElement{ + xmlContent: string, // xml格式的消息内容 + resId: string, + fileName: string, +} export interface RawMessage { msgId: string; @@ -367,5 +400,8 @@ export interface RawMessage { videoElement: VideoElement; fileElement: FileElement; marketFaceElement: MarketFaceElement; + inlineKeyboardElement: InlineKeyboardElement; + markdownElement: MarkdownElement; + multiForwardMsgElement: MultiForwardMsgElement; }[]; } \ No newline at end of file diff --git a/src/onebot11/action/go-cqhttp/GetForwardMsg.ts b/src/onebot11/action/go-cqhttp/GetForwardMsg.ts new file mode 100644 index 0000000..04c89e4 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/GetForwardMsg.ts @@ -0,0 +1,39 @@ +import BaseAction from "../BaseAction"; +import {OB11ForwardMessage, OB11Message, OB11MessageData} from "../../types"; +import {NTQQMsgApi, Peer} from "../../../ntqqapi/api"; +import {dbUtil} from "../../../common/db"; +import {OB11Constructor} from "../../constructor"; +import {ActionName} from "../types"; + +interface Payload { + message_id: string; // long msg id +} + +interface Response{ + messages: (OB11Message & {content: OB11MessageData})[] +} + +export class GoCQHTTGetForwardMsgAction extends BaseAction{ + actionName = ActionName.GoCQHTTP_GetForwardMsg + protected async _handle(payload: Payload): Promise { + const rootMsg = await dbUtil.getMsgByLongId(payload.message_id) + if (!rootMsg){ + throw Error("msg not found") + } + let data = await NTQQMsgApi.getMultiMsg({chatType: rootMsg.chatType, peerUid: rootMsg.peerUid}, rootMsg.msgId, rootMsg.msgId) + if (data.result !== 0){ + throw Error("找不到相关的聊天记录" + data.errMsg) + } + let msgList = data.msgList + let messages = await Promise.all(msgList.map(async msg => { + let resMsg = await OB11Constructor.message(msg) + resMsg.message_id = await dbUtil.addMsg(msg); + return resMsg + })) + messages.map(msg => { + (msg).content = msg.message; + delete msg.message; + }) + return {messages} + } +} \ No newline at end of file diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index bfc5530..7702be9 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -39,6 +39,7 @@ import SetQQAvatar from './llonebot/SetQQAvatar' import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile"; import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory"; import GetFile from "./file/GetFile"; +import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg"; export const actionHandlers = [ new GetFile(), @@ -82,6 +83,7 @@ export const actionHandlers = [ new GoCQHTTPMarkMsgAsRead(), new GoCQHTTPUploadGroupFile(), new GoCQHTTPGetGroupMsgHistory(), + new GoCQHTTGetForwardMsgAction(), ] diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 2216dc0..c3e2f8b 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -60,4 +60,5 @@ export enum ActionName { GoCQHTTP_UploadGroupFile = "upload_group_file", GoCQHTTP_DownloadFile = "download_file", GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history", + GoCQHTTP_GetForwardMsg = "get_forward_msg", } \ No newline at end of file diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index 03c1fe9..10f4df8 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -206,6 +206,12 @@ export class OB11Constructor { } else if (element.marketFaceElement) { message_data["type"] = OB11MessageDataType.mface; message_data["data"]["text"] = element.marketFaceElement.faceName; + } else if (element.markdownElement){ + message_data["type"] = OB11MessageDataType.markdown; + message_data["data"]["data"] = element.markdownElement.content; + } else if (element.multiForwardMsgElement){ + message_data["type"] = OB11MessageDataType.forward; + message_data["data"]["id"] = msg.msgId } if (message_data.type !== "unknown" && message_data.data) { const cqCode = encodeCQCode(message_data); diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index bc2d4e8..f6cdd48 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -88,6 +88,10 @@ export interface OB11Message { raw?: RawMessage } +export interface OB11ForwardMessage extends OB11Message { + content: OB11MessageData[] | string; +} + export interface OB11Return { status: string retcode: number @@ -109,7 +113,10 @@ export enum OB11MessageDataType { json = "json", face = "face", mface = "mface", // 商城表情 - node = "node", // 合并转发消息 + markdown = "markdown", + node = "node", // 合并转发消息节点 + forward = "forward", // 合并转发消息,用于上报 + xml = "xml" } export interface OB11MessageMFace{