fix(onebot): 私聊引用丢失 reply 段——按 clientSeq 反查被引用消息 (#2016)

私聊被引用时,引用元素里的 replayMsgSeq 常为 0(客户端未填序号),
replyElement 的三条 seq 查询与协议兜底都会落空,最终返回 null;null 段
被 parseMessageSegments 过滤掉,于是事件里没有 reply 段、也没有报错(#1508)。

同一元素携带的 replyMsgClientSeq / replyMsgTime 在这种场景下依然准确,而
NapCat 已有按 (peer, clientSeq, time) 查询的 getMsgByClientSeqAndTime
(此前无调用点)。这里在 seq 查询链失败之后用它反查被引用消息,命中即用
真实的 msgId 构造 reply 段。

新路径仅在 seq 链失败后追加,群聊与带真实序号的私聊行为不变。

实测(NapCat 4.18.28 / OneBot 私聊):
- 日志复现「方法1/2/3 查询失败,序号: 0」→「所有查找方法均失败」
- 修复后 reply 段的 id 等于被引用消息自身事件里的 message_id,
  get_msg 可反查,带 reply 段回发引用正常

注:本 PR 先前版本改为直用 records.msgId,实测证伪——那是每次事件一份的
快照 id,get_msg 查不到、回发引用会被静默丢弃,已放弃该方案。
This commit is contained in:
风澪 authored and GitHub committed 2026-09-29 15:18:04 +08:00
1 parent 0b4cfe65ed
commit 870a6060b8
1 file changed
+24
+24
View File
@@ -385,6 +385,30 @@ export class OneBotMsgApi {
this.core.context.logger.logError('所有查找方法均失败,获取不到旧客户端的引用消息', element.replayMsgSeq);
}
// 私聊引用:replayMsgSeq 常为 0(客户端未填序号),seq 查询链与协议兜底都会落空,
// 而引用元素里的 replyMsgClientSeq / replyMsgTime 此时依然准确,用它反查被引用消息。
if (element.replyMsgClientSeq) {
try {
const replyMsgTime = element.replyMsgTime ?? records?.msgTime;
if (replyMsgTime) {
const byClientSeq = await this.core.apis.MsgApi.getMsgByClientSeqAndTime(
peer,
element.replyMsgClientSeq,
replyMsgTime
);
const replyMsg = byClientSeq.msgList?.find(msg => msg.msgId);
if (replyMsg) {
return createReplyData(replyMsg.msgId);
}
this.core.context.logger.logWarn(
`按 clientSeq 查询未命中,序号: ${element.replayMsgSeq}, clientSeq: ${element.replyMsgClientSeq}`
);
}
} catch (error) {
this.core.context.logger.logError('按 clientSeq 查询引用消息出错', error);
}
}
// 协议兜底:尝试通过协议直接获取消息
if (this.core.apis.PacketApi.packetStatus) {
try {