From 1ce8be3c7e1bc73df57ab611b8842fcc40f76ed6 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: Wed, 4 Dec 2024 10:47:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B2=BE=E7=AE=80GroupApi=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/apis/group.ts | 35 +++-------------------------------- src/onebot/api/msg.ts | 2 -- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/src/core/apis/group.ts b/src/core/apis/group.ts index 41fa1057..fd347c3e 100644 --- a/src/core/apis/group.ts +++ b/src/core/apis/group.ts @@ -16,7 +16,6 @@ import { NTEventWrapper } from '@/common/event'; export class NTQQGroupApi { context: InstanceContext; core: NapCatCore; - groupCache: Map = new Map(); groupMemberCache: Map> = new Map>(); essenceLRU = new LimitedHashTable(1000); @@ -24,17 +23,15 @@ export class NTQQGroupApi { this.context = context; this.core = core; } - + async initApi() { this.initCache().then().catch(e => this.context.logger.logError(e)); } async initCache() { - await this.core.apis.GroupApi.refreshGroups(); - for (const group of this.groupCache.keys()) { - await this.refreshGroupMemberCache(group); + for (const group of await this.getGroups(true)) { + this.refreshGroupMemberCache(group.groupCode).then().catch(); } - this.context.logger.logDebug(`加载${this.groupCache.size}个群组缓存完成`); } async fetchGroupEssenceList(groupCode: string) { @@ -111,36 +108,10 @@ export class NTQQGroupApi { ); } - async getGroup(groupCode: string, forced = false) { - let group = this.groupCache.get(groupCode.toString()); - if (!group) { - try { - const groupList = await this.getGroups(forced); - if (groupList.length) { - groupList.forEach(g => { - this.groupCache.set(g.groupCode, g); - }); - } - } catch (e) { - return undefined; - } - } - group = this.groupCache.get(groupCode.toString()); - return group; - } - async getGroupMemberAll(groupCode: string, forced = false) { return this.context.session.getGroupService().getAllMemberList(groupCode, forced); } - async refreshGroups() { - let groups = await this.getGroups(true); - let tempGroupCache = new Map(); - for (const group of groups) { - tempGroupCache.set(group.groupCode, group); - } - this.groupCache = tempGroupCache; - } async refreshGroupMemberCache(groupCode: string) { try { diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 7af4f11f..a9decfea 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -971,7 +971,6 @@ export class OneBotMsgApi { if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) { const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent); this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch(); - this.core.apis.GroupApi.refreshGroups().then().catch(); return new OB11GroupIncreaseEvent( this.core, groupChange.groupUin, @@ -982,7 +981,6 @@ export class OneBotMsgApi { } else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) { const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent); this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch(); - this.core.apis.GroupApi.refreshGroups().then().catch(); return new OB11GroupDecreaseEvent( this.core, groupChange.groupUin,