Skip to content

Commit dbba6b3

Browse files
committed
Add protocol fallback to fetch quoted messages
When existing lookup methods fail to find a referenced/reply message, try a protocol-level fallback using PacketApi. If PacketApi.packetStatus is available, attempt FetchGroupMessage or FetchC2CMessage by sequence, match by contentHead.sequence, and use contentHead.newId as the message id to build reply data. Log warnings on success/not-found and errors on exceptions.
1 parent 03dd89a commit dbba6b3

File tree

1 file changed

+20
-0
lines changed
  • packages/napcat-onebot/api

1 file changed

+20
-0
lines changed

packages/napcat-onebot/api/msg.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,26 @@ export class OneBotMsgApi {
384384
this.core.context.logger.logError('所有查找方法均失败,获取不到旧客户端的引用消息', element.replayMsgSeq);
385385
}
386386

387+
// 协议兜底:尝试通过协议直接获取消息
388+
if (this.core.apis.PacketApi.packetStatus) {
389+
try {
390+
const msgSeq = +element.replayMsgSeq;
391+
const fetchedMsgs = msg.chatType === ChatType.KCHATTYPEGROUP
392+
? await this.core.apis.PacketApi.pkt.operation.FetchGroupMessage(+msg.peerUin, msgSeq, msgSeq)
393+
: await this.core.apis.PacketApi.pkt.operation.FetchC2CMessage(msg.peerUid, msgSeq, msgSeq);
394+
395+
const targetMsg = fetchedMsgs.find(m => (m.contentHead.sequence ?? 0) === msgSeq);
396+
if (targetMsg?.contentHead?.newId) {
397+
const msgId = String(targetMsg.contentHead.newId);
398+
this.core.context.logger.logWarn('通过协议兜底成功获取引用消息', msgId);
399+
return createReplyData(msgId);
400+
}
401+
this.core.context.logger.logWarn('协议兜底未找到匹配的引用消息');
402+
} catch (e) {
403+
this.core.context.logger.logError('协议兜底获取引用消息失败', (e as Error).stack);
404+
}
405+
}
406+
387407
return null;
388408
},
389409
videoElement: async (element, msg, elementWrapper, { disableGetUrl }) => {

0 commit comments

Comments
 (0)