From 37f40a2635a06c85da6dbd320121437f038571e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E7=91=BE?= Date: Thu, 22 Jan 2026 13:20:32 +0800 Subject: [PATCH] feat: support msg_seq parameter in reply message construction (#1529) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: support msg_seq parameter in reply message construction - Add optional 'seq' parameter to OB11MessageReply for using msg_seq - Prioritize seq over id for querying reply messages - Maintain backward compatibility with existing id parameter - Update type definitions across backend and frontend - Update validation schemas for message nodes close #1523 * Update debug button label in NetworkDisplayCard Changed the button label from '关闭调试'/'开启调试' to '默认'/'调试' based on the debug state for improved clarity. --------- Co-authored-by: 手瓜一十雪 --- packages/napcat-onebot/api/msg.ts | 34 ++- packages/napcat-onebot/types/message.ts | 3 +- .../components/display_card/common_card.tsx | 2 +- .../src/const/ob_api/message/node.ts | 3 +- .../src/types/onebot/segment.ts | 201 +++++++++--------- 5 files changed, 132 insertions(+), 111 deletions(-) diff --git a/packages/napcat-onebot/api/msg.ts b/packages/napcat-onebot/api/msg.ts index 94f948aa..6f267d42 100644 --- a/packages/napcat-onebot/api/msg.ts +++ b/packages/napcat-onebot/api/msg.ts @@ -587,15 +587,33 @@ export class OneBotMsgApi { return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.nick || ''); }, - [OB11MessageDataType.reply]: async ({ data: { id } }) => { - const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id)); - if (!replyMsgM) { - this.core.context.logger.logWarn('回复消息不存在', id); + [OB11MessageDataType.reply]: async ({ data: { id, seq } }, context) => { + let replyMsg: RawMessage | undefined; + let replyMsgPeer: Peer | undefined; + + // 优先使用 seq + if (seq) { + const msgList = (await this.core.apis.MsgApi.getMsgsBySeqAndCount( + context.peer, seq.toString(), 1, true, true + )).msgList; + replyMsg = msgList[0]; + replyMsgPeer = context.peer; + } else if (id) { + // 降级使用 id + const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id)); + if (!replyMsgM) { + this.core.context.logger.logWarn('回复消息不存在', id); + return undefined; + } + replyMsg = (await this.core.apis.MsgApi.getMsgsByMsgId( + replyMsgM.Peer, [replyMsgM.MsgId])).msgList[0]; + replyMsgPeer = replyMsgM.Peer; + } else { + this.core.context.logger.logWarn('回复消息缺少id或seq参数'); return undefined; } - const replyMsg = (await this.core.apis.MsgApi.getMsgsByMsgId( - replyMsgM.Peer, [replyMsgM.MsgId])).msgList[0]; - return replyMsg + + return replyMsg && replyMsgPeer ? { elementType: ElementType.REPLY, elementId: '', @@ -605,7 +623,7 @@ export class OneBotMsgApi { senderUin: replyMsg.senderUin, senderUinStr: replyMsg.senderUin, replyMsgClientSeq: replyMsg.clientSeq, - _replyMsgPeer: replyMsgM.Peer, + _replyMsgPeer: replyMsgPeer, }, } : undefined; diff --git a/packages/napcat-onebot/types/message.ts b/packages/napcat-onebot/types/message.ts index 313f0ac5..6b8707de 100644 --- a/packages/napcat-onebot/types/message.ts +++ b/packages/napcat-onebot/types/message.ts @@ -159,7 +159,8 @@ export interface OB11MessageAt { export interface OB11MessageReply { type: OB11MessageDataType.reply; data: { - id: string; + id?: string; // msg_id 的短ID映射 + seq?: number; // msg_seq,优先使用 }; } diff --git a/packages/napcat-webui-frontend/src/components/display_card/common_card.tsx b/packages/napcat-webui-frontend/src/components/display_card/common_card.tsx index a4cfa857..30417ad4 100644 --- a/packages/napcat-webui-frontend/src/components/display_card/common_card.tsx +++ b/packages/napcat-webui-frontend/src/components/display_card/common_card.tsx @@ -93,7 +93,7 @@ const NetworkDisplayCard = ({ onPress={handleEnableDebug} isDisabled={editing} > - {debug ? '关闭调试' : '开启调试'} + {debug ? '默认' : '调试'}