From 45966f072ed0496edbed95d98539671c4b1dd0b9 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:30:51 +0800 Subject: [PATCH] fix(get_msg): return error immediately for recalled messages instead of hanging (#1731) * Initial plan * fix: add timeout to getMsgsByMsgId in GetMsg to handle recalled messages Agent-Logs-Url: https://github.com/NapNeko/NapCatQQ/sessions/15e050cc-734a-4cd5-acb1-69624f6e0978 Co-authored-by: sj817 <74231782+sj817@users.noreply.github.com> * Update GetMsg.ts --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sj817 <74231782+sj817@users.noreply.github.com> --- packages/napcat-onebot/action/msg/GetMsg.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/napcat-onebot/action/msg/GetMsg.ts b/packages/napcat-onebot/action/msg/GetMsg.ts index 43e194e43..f23c68b5d 100644 --- a/packages/napcat-onebot/action/msg/GetMsg.ts +++ b/packages/napcat-onebot/action/msg/GetMsg.ts @@ -1,6 +1,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { MessageUnique } from 'napcat-common/src/message-unique'; +import { PromiseTimer } from 'napcat-common/src/helper'; import { Static, Type } from '@sinclair/typebox'; import { NetworkAdapterConfig } from '@/napcat-onebot/config/config'; @@ -49,8 +50,18 @@ class GetMsg extends OneBotAction { throw new Error('消息不存在'); } const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType }; - const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()])).msgList[0]; - if (!msg) throw Error('消息不存在'); + const getMsgTimeout = this.obContext.configLoader.configData.timeout.baseTimeout; + const msgRes = await PromiseTimer( + this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()]), + getMsgTimeout + ).catch((e: unknown) => { + if (e instanceof Error && e.message.startsWith('PromiseTimer:')) { + throw new Error(`消息不存在或已被撤回: ${e.message || String(e)}`); + } + throw e; + }); + const msg = msgRes.msgList[0]; + if (!msg) throw Error('消息不存在或已被撤回'); const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat); if (!retMsg) throw Error('消息为空'); retMsg.emoji_likes_list = [];