From bf5f548349e11b9a3be49006caa77c80f8985423 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, 30 Jul 2024 23:06:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20msghash=E6=80=A7=E8=83=BD=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/MessageUnique.ts | 22 +++++++++++----------- src/core/src/apis/msg.ts | 16 ++++++++-------- src/onebot11/action/msg/SendMsg/index.ts | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/common/utils/MessageUnique.ts b/src/common/utils/MessageUnique.ts index b1c50f10..215c63ed 100644 --- a/src/common/utils/MessageUnique.ts +++ b/src/common/utils/MessageUnique.ts @@ -15,10 +15,10 @@ class LimitedHashTable { } set(key: K, value: V): void { - const isExist = this.keyToValue.get(key); - if (isExist && isExist === value) { - return; - } + // const isExist = this.keyToValue.get(key); + // if (isExist && isExist === value) { + // return; + // } this.keyToValue.set(key, value); this.valueToKey.set(value, key); while (this.keyToValue.size !== this.valueToKey.size) { @@ -99,13 +99,13 @@ class MessageUniqueWrapper { } createMsg(peer: Peer, msgId: string): number | undefined { const key = `${msgId}|${peer.chatType}|${peer.peerUid}`; - const hash = crypto.createHash('sha1').update(key); - const shortId = Buffer.from(hash.digest('hex').slice(0, 8), 'hex').readInt32BE(); - const isExist = this.msgIdMap.getKey(shortId); - //console.log(`${peer.peerUid} ${msgId} ------- ${shortId}`); - if (isExist && isExist === msgId) { - return shortId; - } + const hash = crypto.createHash('md5').update(key); + const shortId = hash.digest().readInt32BE(0); + //减少性能损耗 + // const isExist = this.msgIdMap.getKey(shortId); + // if (isExist && isExist === msgId) { + // return shortId; + // } this.msgIdMap.set(msgId, shortId); this.msgDataMap.set(key, shortId); return shortId; diff --git a/src/core/src/apis/msg.ts b/src/core/src/apis/msg.ts index d9f8a6db..ec3d190f 100644 --- a/src/core/src/apis/msg.ts +++ b/src/core/src/apis/msg.ts @@ -151,7 +151,7 @@ export class NTQQMsgApi { } static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { let msgId = await NTQQMsgApi.getMsgUnique(await NTQQMsgApi.getServerTime()); - //console.log(msgId); + console.log(msgId); let data = await NTEventDispatch.CallNormalEvent< (msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map) => Promise, (msgList: RawMessage[]) => void @@ -161,14 +161,14 @@ export class NTQQMsgApi { 1, timeout, (msgRecords: RawMessage[]) => { - for (let msgRecord of msgRecords) { - if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) { - return true; - } - } - return false; + // for (let msgRecord of msgRecords) { + // if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) { + // return true; + // } + // } + return true; }, - msgId, + "0", peer, msgElements, new Map() diff --git a/src/onebot11/action/msg/SendMsg/index.ts b/src/onebot11/action/msg/SendMsg/index.ts index 64dc92a6..91a75eb0 100644 --- a/src/onebot11/action/msg/SendMsg/index.ts +++ b/src/onebot11/action/msg/SendMsg/index.ts @@ -170,7 +170,7 @@ export class SendMsg extends BaseAction { // log("send msg:", peer, sendElements) const { sendElements, deleteAfterSentFiles } = await createSendElements(messages, group); - //console.log(peer, JSON.stringify(sendElements,null,2)); + console.log(peer, JSON.stringify(sendElements,null,2)); const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles); return { message_id: returnMsg!.id! }; }