From 43ec1b7cfd9d5a606451f3d3e75ea47bbdfc6859 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: Tue, 27 Aug 2024 12:16:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E9=AB=98=E6=95=88=E7=8E=87?= =?UTF-8?q?=E7=9A=84=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/apis/msg.ts | 11 +++++++++- src/core/services/NodeIKernelMsgService.ts | 22 ++++++++++++------- .../action/go-cqhttp/GetFriendMsgHistory.ts | 22 +++++++++---------- .../action/go-cqhttp/GetGroupMsgHistory.ts | 20 ++++++++--------- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/core/apis/msg.ts b/src/core/apis/msg.ts index d22153d9..9333d909 100644 --- a/src/core/apis/msg.ts +++ b/src/core/apis/msg.ts @@ -3,6 +3,10 @@ import { InstanceContext, NapCatCore } from '@/core'; import { GeneralCallResult } from '@/core/services/common'; export class NTQQMsgApi { + // nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览 + // nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid + // 其实以官方文档为准是最好的,https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType + context: InstanceContext; core: NapCatCore; @@ -10,7 +14,12 @@ export class NTQQMsgApi { this.context = context; this.core = core; } - + async getAioFirstViewLatestMsgs(peer: Peer, MsgCount: number) { + return this.context.session.getMsgService().getAioFirstViewLatestMsgs(peer, MsgCount); + } + async getLatestDbMsgs(peer: Peer, MsgCount: number) { + return this.context.session.getMsgService().getLatestDbMsgs(peer, MsgCount); + } async FetchLongMsg(peer: Peer, msgId: string) { return this.context.session.getMsgService().fetchLongMsg(peer, msgId); } diff --git a/src/core/services/NodeIKernelMsgService.ts b/src/core/services/NodeIKernelMsgService.ts index 85cc1eb6..8992f191 100644 --- a/src/core/services/NodeIKernelMsgService.ts +++ b/src/core/services/NodeIKernelMsgService.ts @@ -167,11 +167,17 @@ export interface NodeIKernelMsgService { getAllOnlineFileMsgs(...args: unknown[]): unknown; - getLatestDbMsgs(peer: Peer, cnt: number): Promise; + getLatestDbMsgs(peer: Peer, cnt: number): Promise; - getLastMessageList(peer: Peer[]): Promise; + getLastMessageList(peer: Peer[]): Promise; - getAioFirstViewLatestMsgs(peer: Peer, num: number): unknown; + getAioFirstViewLatestMsgs(peer: Peer, num: number): Promise; getMsgs(peer: Peer, msgId: string, count: unknown, queryOrder: boolean): Promise; @@ -512,11 +518,11 @@ export interface NodeIKernelMsgService { result: number, errMsg: string, emojiLikesList: - Array<{ - tinyId: string, - nickName: string, - headUrl: string - }>, + Array<{ + tinyId: string, + nickName: string, + headUrl: string + }>, cookie: string, isLastPage: boolean, isFirstPage: boolean diff --git a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts index adc717ef..4100bf22 100644 --- a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts @@ -1,7 +1,7 @@ import BaseAction from '../BaseAction'; import { OB11Message } from '@/onebot'; import { ActionName } from '../types'; -import { ChatType, RawMessage } from '@/core/entities'; +import { ChatType, Peer, RawMessage } from '@/core/entities'; import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import { MessageUnique } from '@/common/message-unique'; @@ -13,7 +13,7 @@ const SchemaData = { type: 'object', properties: { user_id: { type: ['number', 'string'] }, - message_seq: { type: 'number' }, + message_seq: { type: ['number', 'string'] }, count: { type: ['number', 'string'] }, reverseOrder: { type: ['boolean', 'string'] }, }, @@ -37,21 +37,19 @@ export default class GetFriendMsgHistory extends BaseAction { if (!uid) throw `记录${payload.user_id}不存在`; const friend = await NTQQFriendApi.isBuddy(uid); const peer = { chatType: friend ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid: uid }; - + const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0'); //拉取消息 - let msgList: RawMessage[]; - if (!payload.message_seq || payload.message_seq == 0) { - msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList; - } else { - const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId; - if (!startMsgId) throw `消息${payload.message_seq}不存在`; - msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList; - } + const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0'; + let msgList = hasMessageSeq ? + (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList : (await NTQQMsgApi.getAioFirstViewLatestMsgs(peer, MsgCount)).msgList; + if (msgList.length === 0) throw `消息${payload.message_seq}不存在`; + //翻转消息 if (isReverseOrder) msgList.reverse(); + //转换序号 await Promise.all(msgList.map(async msg => { msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId); })); - //转换消息 + //烘焙消息 const ob11MsgList = (await Promise.all( msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg))) ).filter(msg => msg !== undefined); diff --git a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts index d62aef29..d66f9bdc 100644 --- a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts @@ -13,7 +13,7 @@ const SchemaData = { type: 'object', properties: { group_id: { type: ['number', 'string'] }, - message_seq: { type: 'number' }, + message_seq: { type: ['number', 'string'] }, count: { type: ['number', 'string'] }, reverseOrder: { type: ['boolean', 'string'] }, }, @@ -32,21 +32,19 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction { msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId); })); - - //转换消息 + //烘焙消息 const ob11MsgList = (await Promise.all( msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg))) ).filter(msg => msg !== undefined);