diff --git a/package.json b/package.json index 893067f5..c24d2d70 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "napcat", "private": true, "type": "module", - "version": "1.7.3", + "version": "1.7.4", "scripts": { "watch:dev": "vite --mode development", "watch:prod": "vite --mode production", diff --git a/src/core/src/apis/msg.ts b/src/core/src/apis/msg.ts index 48f88f06..30f32eea 100644 --- a/src/core/src/apis/msg.ts +++ b/src/core/src/apis/msg.ts @@ -64,6 +64,9 @@ setTimeout(() => { // )); // console.log(await NTQQMsgApi.multiForwardMsg(peer, peer, [MsgId])); // }, 25000) + +let SendMsgSeq = new Map>(); + export class NTQQMsgApi { // static async CheckSendMode() { // try { @@ -141,9 +144,6 @@ export class NTQQMsgApi { } static async getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, z: boolean) { return await napCatCore.session.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z); - } - static async testMode() { - } static async setMsgRead(peer: Peer) { return napCatCore.session.getMsgService().setMsgRead(peer); @@ -175,7 +175,13 @@ export class NTQQMsgApi { peerUid: peer.peerUid }, msgIds); } - static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { + //并发Seq + static async sendMsgV3(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { + let msgList = await NTQQMsgApi.getLastestMsgByUids(peer); + let data = await napCatCore.session.getMsgService().sendMsg("0", peer, msgElements, new Map()); + SendMsgSeq.get(peer)?.push() + } + static async sendMsgV2(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { // function generateMsgId() { // const timestamp = Math.floor(Date.now() / 1000); // const random = Math.floor(Math.random() * Math.pow(2, 32)); @@ -185,7 +191,7 @@ export class NTQQMsgApi { // const msgId = BigInt("0x" + buffer.toString('hex')).toString(); // return msgId; // } - + let msgId = await NTQQMsgApi.getMsgUnique(await NTQQMsgApi.getServerTime()); let data = await NTEventDispatch.CallNormalEvent< (msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map) => Promise, @@ -218,45 +224,37 @@ export class NTQQMsgApi { static sendMsgEx(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { //return NTQQMsgApi.sendMsgV1(peer, msgElements, waitComplete, timeout); } - static async sendMsgV1(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { - let msgList = await NTQQMsgApi.getLastestMsgByUids(peer); - let msgCurrentSeq = 0n; - if (msgList.msgList.length > 0) { - msgCurrentSeq = BigInt(msgList.msgList[0].msgSeq); - } - let rawMsg: RawMessage | undefined; - let onAddSendMsgListener = NTEventDispatch.RegisterListen('NodeIKernelMsgListener/onAddSendMsg', 1, timeout, (msg: RawMessage) => { - //console.log("msgSeq:", msgCurrentSeq.toString(), JSON.stringify(msgList.msgList[0], null, 4)); - if (msg.peerUid == peer.peerUid && (msgCurrentSeq == 0n || msgList.msgList[0].msgSeq == msgCurrentSeq.toString())) { - rawMsg = msg; - return true; - } - return false; - }).catch(logError); - let MsgInfoListUpdateListener = NTEventDispatch.RegisterListen('NodeIKernelMsgListener/onMsgInfoListUpdate', 1, timeout, - (msgList: RawMessage[]) => { - for (let msg of msgList) { - if (msg.peerUid == peer.peerUid && rawMsg && rawMsg.msgId == msg.msgId && msg.sendStatus == 2) { - rawMsg = msg; + static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { + //唉? !我有个想法 + let msgId = await NTQQMsgApi.getMsgUnique(await NTQQMsgApi.getServerTime()); + peer.guildId = msgId; + let data = await NTEventDispatch.CallNormalEvent< + (msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map) => Promise, + (msgList: RawMessage[]) => void + >( + 'NodeIKernelMsgService/sendMsg', + 'NodeIKernelMsgListener/onMsgInfoListUpdate', + 1, + timeout, + (msgRecords: RawMessage[]) => { + for (let msgRecord of msgRecords) { + if (msgRecord.guildId === msgId && msgRecord.sendStatus === 2) { return true; } } return false; - }).catch(logError); - let data = await napCatCore.session.getMsgService().sendMsg("0", peer, msgElements, new Map()); - //await NTEventDispatch.CallNoListenerEvent('NodeIKernelMsgService/sendMsg', timeout, "0", peer, msgElements, new Map()); - await onAddSendMsgListener; - if (data.result !== 0 && rawMsg) { - //发送失败msgid - await napCatCore.session.getMsgService().deleteMsg(peer, [rawMsg.msgId]); - throw new Error('发送消息失败'); - } - await MsgInfoListUpdateListener; - // console.log("rawMsg", JSON.stringify(rawMsg, null, 4)); - if (rawMsg) { - return rawMsg; - } - throw new Error('发送消息超时'); + }, + "0", + peer, + msgElements, + new Map() + ); + let retMsg = data[1].find(msgRecord => { + if (msgRecord.guildId === msgId) { + return true; + } + }); + return retMsg; } static async getMsgUniqueEx() { let msgId = await NTQQMsgApi.getMsgUnique(await NTQQMsgApi.getServerTime()); diff --git a/src/core/src/entities/msg.ts b/src/core/src/entities/msg.ts index c79a5be4..d450931b 100644 --- a/src/core/src/entities/msg.ts +++ b/src/core/src/entities/msg.ts @@ -731,6 +731,7 @@ export interface MultiForwardMsgElement { } export interface RawMessage { + guildId: string; msgRandom: string; // int32, 自己维护的消息id id?: number; diff --git a/src/onebot11/version.ts b/src/onebot11/version.ts index f7c3c77c..d2d3ef06 100644 --- a/src/onebot11/version.ts +++ b/src/onebot11/version.ts @@ -1 +1 @@ -export const version = '1.7.3'; +export const version = '1.7.4'; diff --git a/src/webui/ui/NapCat.ts b/src/webui/ui/NapCat.ts index 75de7428..31eb05bb 100644 --- a/src/webui/ui/NapCat.ts +++ b/src/webui/ui/NapCat.ts @@ -29,7 +29,7 @@ async function onSettingWindowCreated(view: Element) { SettingItem( 'Napcat', undefined, - SettingButton('V1.7.3', 'napcat-update-button', 'secondary') + SettingButton('V1.7.4', 'napcat-update-button', 'secondary') ), ]), SettingList([ diff --git a/static/assets/renderer.js b/static/assets/renderer.js index e14598e6..fec5f11f 100644 --- a/static/assets/renderer.js +++ b/static/assets/renderer.js @@ -163,7 +163,7 @@ async function onSettingWindowCreated(view) { SettingItem( 'Napcat', void 0, - SettingButton("V1.7.3", "napcat-update-button", "secondary") + SettingButton("V1.7.4", "napcat-update-button", "secondary") ) ]), SettingList([