mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: 精简GroupApi实现
This commit is contained in:
@@ -16,7 +16,6 @@ import { NTEventWrapper } from '@/common/event';
|
||||
export class NTQQGroupApi {
|
||||
context: InstanceContext;
|
||||
core: NapCatCore;
|
||||
groupCache: Map<string, Group> = new Map<string, Group>();
|
||||
groupMemberCache: Map<string, Map<string, GroupMember>> = new Map<string, Map<string, GroupMember>>();
|
||||
essenceLRU = new LimitedHashTable<number, string>(1000);
|
||||
|
||||
@@ -30,11 +29,9 @@ export class NTQQGroupApi {
|
||||
}
|
||||
|
||||
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<string, Group>();
|
||||
for (const group of groups) {
|
||||
tempGroupCache.set(group.groupCode, group);
|
||||
}
|
||||
this.groupCache = tempGroupCache;
|
||||
}
|
||||
|
||||
async refreshGroupMemberCache(groupCode: string) {
|
||||
try {
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user