From 28f3ff4971a2c178ac36a7573ec87f27089aacf5 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: Wed, 30 Oct 2024 15:27:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20reply=20msg=20=E5=A4=A7=E5=9D=90?= =?UTF-8?q?=E7=89=A2=20#452=20#477?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/apis/msg.ts | 13 +++++++---- src/core/services/NodeIKernelMsgService.ts | 20 ++++++++-------- src/onebot/api/msg.ts | 27 ++++++++++++++++------ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/core/apis/msg.ts b/src/core/apis/msg.ts index 2a73f950..37041dd4 100644 --- a/src/core/apis/msg.ts +++ b/src/core/apis/msg.ts @@ -3,6 +3,9 @@ import { InstanceContext, NapCatCore } from '@/core'; import { GeneralCallResult } from '@/core/services/common'; export class NTQQMsgApi { + getMsgByClientSeqAndTime(peer: Peer, replyMsgClientSeq: string, replyMsgTime: string) { + return this.context.session.getMsgService().getMsgByClientSeqAndTime(peer, replyMsgClientSeq, replyMsgTime); + } // 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 @@ -22,7 +25,9 @@ export class NTQQMsgApi { async sendShowInputStatusReq(peer: Peer, eventType: number) { return this.context.session.getMsgService().sendShowInputStatusReq(peer.chatType, eventType, peer.peerUid); } - + async getSourceOfReplyMsgV2(peer: Peer, clientSeq: string, time: string) { + return this.context.session.getMsgService().getSourceOfReplyMsgV2(peer, clientSeq, time); + } async getMsgEmojiLikesList(peer: Peer, msgSeq: string, emojiId: string, emojiType: string, count: number = 20) { //注意此处emojiType 可选值一般为1-2 2好像是unicode表情dec值 大部分情况 Taged Mlikiowa return this.context.session.getMsgService().getMsgEmojiLikesList(peer, msgSeq, emojiId, emojiType, '', false, count); @@ -106,9 +111,9 @@ export class NTQQMsgApi { pageLimit: 1, }); } - //@deprecated - async getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, z: boolean) { - return await this.context.session.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z); + // 客户端还在用别慌 + async getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, isReverseOrder: boolean) { + return await this.context.session.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, isReverseOrder); } async getMsgExBySeq(peer: Peer, msgSeq: string) { const DateNow = Math.floor(Date.now() / 1000); diff --git a/src/core/services/NodeIKernelMsgService.ts b/src/core/services/NodeIKernelMsgService.ts index c779a736..5e279195 100644 --- a/src/core/services/NodeIKernelMsgService.ts +++ b/src/core/services/NodeIKernelMsgService.ts @@ -172,7 +172,7 @@ export interface NodeIKernelMsgService { msgList: RawMessage[] }>; //@deprecated - getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, unknownArg: boolean): Promise; @@ -186,27 +186,29 @@ export interface NodeIKernelMsgService { getSingleMsg(Peer: Peer, msgSeq: string): Promise; - getSourceOfReplyMsg(peer: Peer, MsgId: string, SourceSeq: string): unknown; + // 下面的msgid全部不真实 + getSourceOfReplyMsg(peer: Peer, msgId: string, sourceSeq: string): Promise; - getSourceOfReplyMsgV2(peer: Peer, RootMsgId: string, ReplyMsgId: string): unknown; + //用法和聊天记录一样 + getSourceOfReplyMsgV2(peer: Peer, rootMsgId: string, replyMsgId: string): Promise; - getMsgByClientSeqAndTime(peer: Peer, clientSeq: string, time: string): unknown; + getMsgByClientSeqAndTime(peer: Peer, clientSeq: string, time: string): Promise; - getSourceOfReplyMsgByClientSeqAndTime(peer: Peer, clientSeq: string, time: string): unknown; + getSourceOfReplyMsgByClientSeqAndTime(peer: Peer, clientSeq: string, time: string, replyMsgId: string): Promise; getMsgsByTypeFilter(peer: Peer, msgId: string, cnt: unknown, queryOrder: boolean, typeFilter: { type: number, subtype: Array - }): unknown; + }): Promise; getMsgsByTypeFilters(peer: Peer, msgId: string, cnt: unknown, queryOrder: boolean, typeFilters: Array<{ type: number, subtype: Array - }>): unknown; + }>): Promise; - getMsgWithAbstractByFilterParam(...args: unknown[]): unknown; + getMsgWithAbstractByFilterParam(...args: unknown[]): Promise; - queryMsgsWithFilter(...args: unknown[]): unknown; + queryMsgsWithFilter(...args: unknown[]): Promise; //queryMsgsWithFilterVer2(MsgId: string, MsgTime: string, param: QueryMsgsParams): Promise; diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 1e2b6466..bce77da1 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -217,21 +217,34 @@ export class OneBotMsgApi { if (records.peerUin === '284840486' || records.peerUin === '1094950020') { return createReplyData(records.msgId); } - let replyMsgList = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeqV2(peer, element.replayMsgSeq, element.replyMsgTime, [element.senderUidStr])).msgList; + let replyMsgList = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeqV2(peer, element.replayMsgSeq, records.msgTime, [element.senderUidStr])).msgList; let replyMsg = replyMsgList.find(msg => msg.msgRandom === records.msgRandom); + if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) { - // 我猜测可能是时间参数未对上 导致找不到引用消息 或者msgList 存在问题 - this.core.context.logger.logWarn.bind(this.core.context.logger)( - '初次筛选消息失败,获取不到引用的消息 Seq:', + this.core.context.logger.logError.bind(this.core.context.logger)( + '筛选结果,筛选消息失败,将使用Fallback-1 Seq: ', element.replayMsgSeq, ',消息长度:', replyMsgList.length ); - // 再次筛选 - replyMsgList = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeqV3(peer, element.replayMsgSeq, [element.senderUidStr])).msgList; - // console.log(JSON.stringify(replyMsgList, null, 4)); + replyMsgList = (await this.core.apis.MsgApi.getMsgsBySeqAndCount(peer, element.replayMsgSeq, 1, true, true)).msgList; replyMsg = replyMsgList.find(msg => msg.msgRandom === records.msgRandom); } + + if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) { + this.core.context.logger.logWarn.bind(this.core.context.logger)( + '筛选消息失败,将使用Fallback-2 Seq:', + element.replayMsgSeq, + ',消息长度:', + replyMsgList.length + ); + replyMsgList = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeqV3(peer, element.replayMsgSeq, [element.senderUidStr])).msgList; + replyMsg = replyMsgList.find(msg => msg.msgRandom === records.msgRandom); + } + + + + // 丢弃该消息段 if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) { this.core.context.logger.logError.bind(this.core.context.logger)( '最终筛选结果,筛选消息失败,获取不到引用的消息 Seq: ',