From 781c107d8cf8a95227288b8841bd2407cb77768b 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: Mon, 22 Jul 2024 15:12:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8B=89=E5=8F=96=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/MessageUnique.ts | 13 ++++- src/core/src/apis/msg.ts | 49 ++++++++++++----- .../NodeIKernelRecentContactService.ts | 10 +++- src/onebot11/constructor.ts | 53 ++++++++++--------- 4 files changed, 84 insertions(+), 41 deletions(-) diff --git a/src/common/utils/MessageUnique.ts b/src/common/utils/MessageUnique.ts index 15572328..61879bf0 100644 --- a/src/common/utils/MessageUnique.ts +++ b/src/common/utils/MessageUnique.ts @@ -9,6 +9,9 @@ class LimitedHashTable { constructor(maxSize: number) { this.maxSize = maxSize; } + resize(count: number) { + this.maxSize = count; + } set(key: K, value: V): void { const isExist = this.keyToValue.get(key); @@ -19,6 +22,8 @@ class LimitedHashTable { this.valueToKey.set(value, key); while (this.keyToValue.size !== this.valueToKey.size) { console.log('keyToValue.size !== valueToKey.size Error Atom'); + this.keyToValue.clear(); + this.valueToKey.clear(); } // console.log('---------------'); // console.log(this.keyToValue); @@ -71,7 +76,7 @@ class MessageUniqueWrapper { const shortId = parseInt(hash.digest('hex').slice(0, 8), 16); const isExist = this.msgIdMap.getKey(shortId); if (isExist && isExist === msgId) { - return undefined; + return shortId; } this.msgIdMap.set(msgId, shortId); this.msgDataMap.set(key, shortId); @@ -100,6 +105,10 @@ class MessageUniqueWrapper { if (!shortId) return undefined; return this.getMsgIdAndPeerByShortId(shortId); } + resize(maxSize: number): void { + this.msgIdMap.resize(maxSize); + this.msgDataMap.resize(maxSize); + } } -export const MessageUnique = new MessageUniqueWrapper(1000); \ No newline at end of file +export const MessageUnique: MessageUniqueWrapper = new MessageUniqueWrapper(); \ No newline at end of file diff --git a/src/core/src/apis/msg.ts b/src/core/src/apis/msg.ts index 0deb5b1d..c98439cf 100644 --- a/src/core/src/apis/msg.ts +++ b/src/core/src/apis/msg.ts @@ -1,13 +1,38 @@ -import { GetFileListParam, Peer, RawMessage, SendMessageElement } from '@/core/entities'; -import { selfInfo } from '@/core/data'; -import { log, logError } from '@/common/utils/log'; +import { ChatType, GetFileListParam, Peer, RawMessage, SendMessageElement } from '@/core/entities'; +import { friends, groups, selfInfo } from '@/core/data'; +import { log, logError, logWarn } from '@/common/utils/log'; import { sleep } from '@/common/utils/helper'; -import { napCatCore } from '@/core'; +import { napCatCore, NTQQUserApi } from '@/core'; import { MsgListener, onGroupFileInfoUpdateParamType } from '@/core/listeners'; import { GeneralCallResult } from '@/core/services/common'; import { randomUUID } from 'crypto'; +import { MessageUnique } from '../../../common/utils/MessageUnique'; - +setTimeout(() => { + napCatCore.onLoginSuccess(() => { + setTimeout(async () => { + if (groups.size > 100) { + logWarn('群数量大于100,可能会导致性能问题'); + } + let predict = (groups.size + friends.size) / 5; + predict = predict < 20 ? 20 : predict; + predict = predict > 50 ? 50 : predict; + //let waitpromise: Array> = []; + MessageUnique.resize(predict * 50); + let RecentContact = await NTQQUserApi.getRecentContactListSnapShot(predict); + if (RecentContact?.info?.changedList && RecentContact?.info?.changedList?.length > 0) { + for (let i = 0; i < RecentContact.info.changedList.length; i++) { + let Peer: Peer = { chatType: RecentContact.info.changedList[i].chatType, peerUid: RecentContact.info.changedList[i].peerUid, guildId: '' }; + let msgList = await NTQQMsgApi.getMsgHistory(Peer, RecentContact.info.changedList[i].msgId, 50); + for (let j = 0; j < msgList.msgList.length; j++) { + let shortId = MessageUnique.createMsg(Peer, msgList.msgList[j].msgId); + //console.log(`开始创建 ${shortId}<------>${msgList.msgList[j].msgId}`) + } + } + } + }, 500); + }); +}, 100); const sendMessagePool: Record void | Promise) | null> = {};// peerUid: callbackFunc const sendSuccessCBMap: Record boolean | Promise) | null> = {};// uuid: callbackFunc @@ -71,13 +96,13 @@ setTimeout(() => { export class NTQQMsgApi { // static napCatCore: NapCatCore | null = null; -// enum BaseEmojiType { -// NORMAL_EMOJI, -// SUPER_EMOJI, -// RANDOM_SUPER_EMOJI, -// CHAIN_SUPER_EMOJI, -// EMOJI_EMOJI -// } + // enum BaseEmojiType { + // NORMAL_EMOJI, + // SUPER_EMOJI, + // RANDOM_SUPER_EMOJI, + // CHAIN_SUPER_EMOJI, + // EMOJI_EMOJI + // } static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) { // nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览 // nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid diff --git a/src/core/src/services/NodeIKernelRecentContactService.ts b/src/core/src/services/NodeIKernelRecentContactService.ts index ef1630d1..882f6381 100644 --- a/src/core/src/services/NodeIKernelRecentContactService.ts +++ b/src/core/src/services/NodeIKernelRecentContactService.ts @@ -1,5 +1,6 @@ import { Peer } from "../entities"; import { NodeIKernelRecentContactListener } from "../listeners/NodeIKernelRecentContactListener"; +import { GeneralCallResult } from "./common"; export interface FSABRecentContactParams { anchorPointContact: { contactId: string; @@ -33,7 +34,14 @@ export interface NodeIKernelRecentContactService { enterOrExitMsgList(...args: unknown[]): unknown; // 1 arguments - /*!---!*/getRecentContactListSnapShot(count: number): unknown; // 1 arguments + /*!---!*/getRecentContactListSnapShot(count: number): Promise, + changedList: Array + } + }>; // 1 arguments clearMsgUnreadCount(...args: unknown[]): unknown; // 1 arguments diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index e1492bb4..ec1fdcc7 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -136,26 +136,26 @@ export class OB11Constructor { message_data['type'] = 'reply'; // log("收到回复消息", element.replyElement.replayMsgSeq) try { - // let retData = await NTQQMsgApi.getMsgsBySeqAndCount( - // { - // chatType: msg.chatType, - // peerUid: msg.peerUid, - // guildId: '', - // }, - // element.replyElement.replayMsgSeq, - // 1, - // false, - // true - // ); + let replyMsg = await NTQQMsgApi.getMsgsBySeqAndCount( + { + chatType: msg.chatType, + peerUid: msg.peerUid, + guildId: '', + }, + element.replyElement.replayMsgSeq, + 1, + true, + true + ); // console.log(JSON.stringify(retData, null, 2)); - const replyMsg = await NTQQMsgApi.getMsgsBySeqAndCount({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, element.replyElement.replayMsgSeq, 1, true, true); - // log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId) + // const replyMsg = await NTQQMsgApi.getMsgsBySeqAndCount({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, element.replyElement.replayMsgSeq, 1, true, true); if (replyMsg) { - message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgList[0].msgId); + message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgList[0].msgId)?.toString(); } else { continue; } + //log("找到回复消息", message_data['data']['id'], replyMsg.msgList[0].msgId) } catch (e: any) { logError('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq); } @@ -202,18 +202,18 @@ export class OB11Constructor { message_data['data']['file_id'] = videoOrFileElement.fileUuid; message_data['data']['file_size'] = videoOrFileElement.fileSize; if (!element.videoElement) { - // dbUtil.addFileCache({ - // msgId: msg.msgId, - // name: videoOrFileElement.fileName, - // path: videoOrFileElement.filePath, - // size: parseInt(videoOrFileElement.fileSize || '0'), - // uuid: videoOrFileElement.fileUuid || '', - // url: '', - // element: element.videoElement || element.fileElement, - // elementType: element.videoElement ? ElementType.VIDEO : ElementType.FILE, - // elementId: element.elementId - // }).then(); - // } + // dbUtil.addFileCache({ + // msgId: msg.msgId, + // name: videoOrFileElement.fileName, + // path: videoOrFileElement.filePath, + // size: parseInt(videoOrFileElement.fileSize || '0'), + // uuid: videoOrFileElement.fileUuid || '', + // url: '', + // element: element.videoElement || element.fileElement, + // elementType: element.videoElement ? ElementType.VIDEO : ElementType.FILE, + // elementId: element.elementId + // }).then(); + // } } } else if (element.pttElement) { @@ -285,6 +285,7 @@ export class OB11Constructor { else (resMsg.message as OB11MessageData[]).push(message_data); resMsg.raw_message += cqCode; } + } resMsg.raw_message = resMsg.raw_message.trim(); return resMsg;