From 0c456e2160d8eaf5285ac72b9bc915d46cab9249 Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 21 Sep 2024 20:19:26 +0800 Subject: [PATCH] optimize --- package.json | 2 +- src/common/utils/misc.ts | 5 +-- src/ntqqapi/api/msg.ts | 2 +- src/ntqqapi/core.ts | 36 ++++++++----------- .../services/NodeIKernelBuddyService.ts | 2 +- src/onebot11/entities.ts | 1 + 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 6795284..2fd8223 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "electron-vite": "^2.3.0", "protobufjs-cli": "^1.1.3", "typescript": "^5.6.2", - "vite": "^5.4.6", + "vite": "^5.4.7", "vite-plugin-cp": "^4.0.8" }, "packageManager": "yarn@4.4.1" diff --git a/src/common/utils/misc.ts b/src/common/utils/misc.ts index 7e0d63f..5be0c73 100644 --- a/src/common/utils/misc.ts +++ b/src/common/utils/misc.ts @@ -12,8 +12,9 @@ export function calcQQLevel(level: QQLevel) { /** QQ Build Version */ export function getBuildVersion(): number { - const version: string = globalThis.LiteLoader.versions.qqnt - return +version.split('-')[1] + //const version: string = globalThis.LiteLoader.versions.qqnt + //return +version.split('-')[1] + return +globalThis.LiteLoader.package.qqnt.buildVersion } /** 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象 */ diff --git a/src/ntqqapi/api/msg.ts b/src/ntqqapi/api/msg.ts index 4ab6270..80e4d38 100644 --- a/src/ntqqapi/api/msg.ts +++ b/src/ntqqapi/api/msg.ts @@ -50,7 +50,7 @@ export class NTQQMsgApi extends Service { } async activateChat(peer: Peer) { - return await invoke(NTMethod.ACTIVE_CHAT_PREVIEW, [{ peer, cnt: 20 }, null]) + return await invoke(NTMethod.ACTIVE_CHAT_PREVIEW, [{ peer, cnt: 1 }, null]) } async activateChatAndGetHistory(peer: Peer) { diff --git a/src/ntqqapi/core.ts b/src/ntqqapi/core.ts index f1fd090..5579161 100644 --- a/src/ntqqapi/core.ts +++ b/src/ntqqapi/core.ts @@ -1,4 +1,4 @@ -import fs from 'node:fs' +import { unlink } from 'node:fs/promises' import { Service, Context } from 'cordis' import { registerCallHook, registerReceiveHook, ReceiveCmdS } from './hook' import { Config as LLOBConfig } from '../common/types' @@ -13,7 +13,6 @@ import { GroupMember, CategoryFriend, SimpleInfo, - User, ChatType } from './types' import { selfInfo } from '../common/globalVars' @@ -53,29 +52,24 @@ class Core extends Service { private registerListener() { registerReceiveHook<{ - data: CategoryFriend[] + data?: CategoryFriend[] + userSimpleInfos?: Map //V2 + buddyCategory?: CategoryFriend[] //V2 }>(ReceiveCmdS.FRIENDS, (payload) => { - type V2data = { userSimpleInfos: Map } - let friendList: User[] = [] - if ('userSimpleInfos' in payload) { - friendList = Object.values((payload as unknown as V2data).userSimpleInfos).map((v: SimpleInfo) => { - return { - ...v.coreInfo, - } - }) - } else { - for (const fData of payload.data) { - friendList.push(...fData.buddyList) - } + let uids: string[] = [] + if (payload.buddyCategory) { + uids = payload.buddyCategory.flatMap(item => item.buddyUids) + } else if (payload.data) { + uids = payload.data.flatMap(item => item.buddyList.map(e => e.uid)) } - this.ctx.logger.info('好友列表变动', friendList.length) - for (const friend of friendList) { - this.ctx.ntMsgApi.activateChat({ peerUid: friend.uid, chatType: ChatType.friend }) + for (const uid of uids) { + this.ctx.ntMsgApi.activateChat({ peerUid: uid, chatType: ChatType.friend }) } + this.ctx.logger.info('好友列表变动', uids.length) }) // 自动清理新消息文件 - registerReceiveHook<{ msgList: Array }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => { + registerReceiveHook<{ msgList: RawMessage[] }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => { if (!this.config.autoDeleteFile) { return } @@ -94,9 +88,7 @@ class Core extends Service { } for (const path of pathList) { if (path) { - fs.unlink(path, () => { - this.ctx.logger.info('删除文件成功', path) - }) + unlink(path).then(() => this.ctx.logger.info('删除文件成功', path)) } } }, this.config.autoDeleteFileSecond! * 1000) diff --git a/src/ntqqapi/services/NodeIKernelBuddyService.ts b/src/ntqqapi/services/NodeIKernelBuddyService.ts index cfd7aef..af04ffc 100644 --- a/src/ntqqapi/services/NodeIKernelBuddyService.ts +++ b/src/ntqqapi/services/NodeIKernelBuddyService.ts @@ -8,7 +8,7 @@ export enum BuddyListReqType { export interface NodeIKernelBuddyService { getBuddyListV2(callFrom: string, reqType: BuddyListReqType): Promise