From 1823a17bf98b5f5a92265fa93f149d79cd34b87a 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: Thu, 27 Mar 2025 12:12:12 +0800 Subject: [PATCH] fix --- src/core/apis/group.ts | 13 +++++++++++-- src/core/apis/user.ts | 11 ++++++++++- src/onebot/action/go-cqhttp/GetStrangerInfo.ts | 2 +- src/onebot/action/go-cqhttp/SetQQProfile.ts | 2 +- src/onebot/action/group/GetGroupMemberInfo.ts | 2 +- src/onebot/action/group/GetGroupMemberList.ts | 2 +- src/onebot/action/user/GetFriendList.ts | 2 +- src/onebot/api/msg.ts | 4 ++-- src/onebot/index.ts | 2 +- 9 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/core/apis/group.ts b/src/core/apis/group.ts index 80555d98..f66f144c 100644 --- a/src/core/apis/group.ts +++ b/src/core/apis/group.ts @@ -44,13 +44,22 @@ export class NTQQGroupApi { } async initApi() { - this.initCache().then().catch(e => this.context.logger.logError(e)); + await this.initCache().then().catch(e => this.context.logger.logError(e)); } async initCache() { + let promises: Promise[] = []; for (const group of await this.getGroups(true)) { - this.refreshGroupMemberCache(group.groupCode, false).then().catch(e => this.context.logger.logError(e)); + let user = await this.refreshGroupMemberCache(group.groupCode, false).then().catch(e => this.context.logger.logError(e)); + if (user) { + for (const member of user) { + let promise = this.core.apis.UserApi.fetchUserDetailInfoV3(member[1].uid).then(_ => void 0).catch(e => this.context.logger.logError(e)); + promises.push(promise); + } + } } + await Promise.all(promises); + this.context.logger.logDebug('[NapCat] [Mark] 群成员缓存初始化完成'); } async fetchGroupEssenceList(groupCode: string) { diff --git a/src/core/apis/user.ts b/src/core/apis/user.ts index b66eec0e..ef3ae5cf 100644 --- a/src/core/apis/user.ts +++ b/src/core/apis/user.ts @@ -93,6 +93,15 @@ export class NTQQUserApi { return profile; } + async fetchUserDetailInfoV3(uid: string) { + let cache = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KDB); + if (!cache.commonExt) { + cache = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KSERVER); + } + return cache; + } + + async getUserDetailInfoV2(uid: string) { let retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfoV2(uid, UserDetailSource.KDB), uid); if (retUser && retUser.uin !== '0') { @@ -192,7 +201,7 @@ export class NTQQUserApi { .add(() => this.context.session.getUixConvertService().getUin([uid]).then((data) => data.uinInfo.get(uid))) .add(() => this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [uid]).get(uid)) .add(() => this.context.session.getGroupService().getUinByUids([uid]).then((data) => data.uins.get(uid))) - .add(() => this.getUserDetailInfoV2(uid).then((data) => data.uin)); + .add(() => this.fetchUserDetailInfoV2(uid).then((data) => data.uin)); const uin = await fallback.run().catch(() => '0'); return uin ?? '0'; diff --git a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts index 5c371b94..5613f55a 100644 --- a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts +++ b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts @@ -19,7 +19,7 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction { const [member, info] = await Promise.all([ this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache), - this.core.apis.UserApi.getUserDetailInfoV2(uid), + this.core.apis.UserApi.fetchUserDetailInfoV2(uid), ]); if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`); diff --git a/src/onebot/action/group/GetGroupMemberList.ts b/src/onebot/action/group/GetGroupMemberList.ts index 37543805..a454cf3b 100644 --- a/src/onebot/action/group/GetGroupMemberList.ts +++ b/src/onebot/action/group/GetGroupMemberList.ts @@ -29,7 +29,7 @@ export class GetGroupMemberList extends OneBotAction // 批量并行获取用户详情 const userDetailsPromises = memberArray.map(member => - this.core.apis.UserApi.getUserDetailInfoV2(member.uin) + this.core.apis.UserApi.fetchUserDetailInfoV2(member.uid) .catch(_ => { return { uin: member.uin, uid: member.uid }; }) diff --git a/src/onebot/action/user/GetFriendList.ts b/src/onebot/action/user/GetFriendList.ts index f62baa0b..14fa3bc1 100644 --- a/src/onebot/action/user/GetFriendList.ts +++ b/src/onebot/action/user/GetFriendList.ts @@ -21,7 +21,7 @@ export default class GetFriendList extends OneBotAction { // 批量并行获取用户详情 const userDetailsPromises = buddyArray.map(member => - this.core.apis.UserApi.getUserDetailInfoV2(member.uin ?? '') + this.core.apis.UserApi.fetchUserDetailInfoV2(member.uid) .catch(_ => { return { uin: member.uin, uid: member.uid }; }) diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 41e12d18..c415a1d7 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -444,7 +444,7 @@ export class OneBotMsgApi { } const uid = await this.core.apis.UserApi.getUidByUinV2(`${atQQ}`); if (!uid) throw new Error('Get Uid Error'); - const info = await this.core.apis.UserApi.getUserDetailInfoV2(uid); + const info = await this.core.apis.UserApi.fetchUserDetailInfoV2(uid); return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.simpleInfo?.coreInfo.nick || ''); }, @@ -845,7 +845,7 @@ export class OneBotMsgApi { return; } } - resMsg.sender.nickname = (await this.core.apis.UserApi.getUserDetailInfoV2(msg.senderUid)).simpleInfo?.coreInfo.nick || ''; + resMsg.sender.nickname = (await this.core.apis.UserApi.fetchUserDetailInfoV2(msg.senderUid)).simpleInfo?.coreInfo.nick || ''; } private async handleTempGroupMessage(resMsg: OB11Message, msg: RawMessage) { diff --git a/src/onebot/index.ts b/src/onebot/index.ts index 7c250ab4..75065a61 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -100,7 +100,7 @@ export class NapCatOneBot11Adapter { const ob11Config = this.configLoader.configData; - this.core.apis.UserApi.getUserDetailInfoV2(this.core.selfInfo.uid) + this.core.apis.UserApi.fetchUserDetailInfoV2(this.core.selfInfo.uid) .then((user) => { this.core.selfInfo = { ...user, online: this.core.selfInfo.online }; this.context.logger.setLogSelfInfo({ nick: this.core.selfInfo.simpleInfo?.coreInfo.nick ?? '', uid: this.core.selfInfo.uid });