From ceec9e5e1b40745b9caad57f79c347c9b3e9caed 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: Tue, 26 Nov 2024 11:26:34 +0800 Subject: [PATCH] refactor: self report --- src/onebot/index.ts | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/onebot/index.ts b/src/onebot/index.ts index bf5d130c..a8858bc6 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -265,11 +265,24 @@ export class NapCatOneBot11Adapter { } }; - const msgIdSend = new LRUCache(100); - msgListener.onAddSendMsg = async (msg) => { if (msg.sendStatus == SendStatusType.KSEND_STATUS_SENDING) { - msgIdSend.put(msg.msgId, 0); + await this.core.eventWrapper.registerListen('NodeIKernelMsgListener/onMsgInfoListUpdate', (msgList: RawMessage[]) => { + const report = msgList.find((e) => + e.senderUin == this.core.selfInfo.uin && e.sendStatus == SendStatusType.KSEND_STATUS_SUCCESS && e.msgId === msg.msgId + ); + return !!report; + }, 1, 300); + msg.id = MessageUnique.createUniqueMsgId( + { + chatType: msg.chatType, + peerUid: msg.peerUid, + guildId: '', + }, + msg.msgId + ); + //此时上报的seq不是对的 不过对onebot业务无影响 + this.emitMsg(msg); } }; msgListener.onMsgRecall = async (chatType: ChatType, uid: string, msgSeq: string) => { @@ -291,23 +304,6 @@ export class NapCatOneBot11Adapter { } } } - msgListener.onMsgInfoListUpdate = async (msgList) => { - for (const msg of msgList.filter((e) => e.senderUin == this.core.selfInfo.uin)) { - if (msg.sendStatus == SendStatusType.KSEND_STATUS_SUCCESS && msgIdSend.get(msg.msgId) == 0) { - msgIdSend.put(msg.msgId, 1); - // 完成后再post - msg.id = MessageUnique.createUniqueMsgId( - { - chatType: msg.chatType, - peerUid: msg.peerUid, - guildId: '', - }, - msg.msgId - ); - this.emitMsg(msg); - } - } - }; msgListener.onKickedOffLine = async (kick) => { const event = new BotOfflineEvent(this.core, kick.tipsTitle, kick.tipsDesc); this.networkManager @@ -549,7 +545,7 @@ export class NapCatOneBot11Adapter { message.chatType == ChatType.KCHATTYPEGROUP ? this.handleGroupEvent(message) : this.handlePrivateMsgEvent(message) ]); } - + private async handleMsg(message: RawMessage, network: Array) { try { const ob11Msg = await this.apis.MsgApi.parseMessageV2(message, this.configLoader.configData.parseMultMsg);