diff --git a/src/common/decorator.ts b/src/common/decorator.ts new file mode 100644 index 00000000..bea6e9f0 --- /dev/null +++ b/src/common/decorator.ts @@ -0,0 +1,22 @@ +// decoratorAsyncMethod(this,function,wrapper) +async function decoratorMethod( + target: T, + method: () => Promise, + wrapper: (result: R) => Promise, + executeImmediately: boolean = true +): Promise { + const execute = async () => { + try { + const result = await method.call(target); + return wrapper(result); + } catch (error) { + return Promise.reject(error instanceof Error ? error : new Error(String(error))); + } + }; + + if (executeImmediately) { + return execute(); + } else { + return execute; + } +} \ No newline at end of file diff --git a/src/core/apis/user.ts b/src/core/apis/user.ts index c6add838..6d1d3a09 100644 --- a/src/core/apis/user.ts +++ b/src/core/apis/user.ts @@ -2,8 +2,6 @@ import { ModifyProfileParams, User, UserDetailSource } from '@/core/types'; import { RequestUtil } from '@/common/request'; import { InstanceContext, NapCatCore, ProfileBizType } from '..'; import { solveAsyncProblem } from '@/common/helper'; -import { promisify } from 'node:util'; -import { LRUCache } from '@/common/lru-cache'; import { Fallback, FallbackUtil } from '@/common/fall-back'; export class NTQQUserApi { @@ -109,6 +107,19 @@ export class NTQQUserApi { return retUser; } + async getUserDetailInfoV2(uid: string): Promise { + const fallback = new Fallback((user) => FallbackUtil.boolchecker(user, user !== undefined && user.uin !== '0')) + .add(() => this.fetchUserDetailInfo(uid, UserDetailSource.KDB)) + .add(() => this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER)); + const retUser = await fallback.run().then(async (user) => { + if (user && user.uin === '0') { + user.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0'; + } + return user; + }); + return retUser; + } + async modifySelfProfile(param: ModifyProfileParams) { return this.context.session.getProfileService().modifyDesktopMiniProfile(param); } diff --git a/src/core/apis/webapi.ts b/src/core/apis/webapi.ts index 933a0941..37707f24 100644 --- a/src/core/apis/webapi.ts +++ b/src/core/apis/webapi.ts @@ -8,7 +8,7 @@ import { WebHonorType, } from '@/core'; import { NapCatCore } from '..'; -import { createReadStream, readFileSync, statSync } from 'node:fs'; +import { readFileSync } from 'node:fs'; import { createHash } from 'node:crypto'; import { basename } from 'node:path'; diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 5cca3c86..1f2ca3ef 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -797,6 +797,13 @@ export class OneBotMsgApi { private async handlePrivateMessage(resMsg: OB11Message, msg: RawMessage) { resMsg.sub_type = 'friend'; + if (await this.core.apis.FriendApi.isBuddy(msg.senderUid)) { + let nickname = (await this.core.apis.UserApi.getCoreAndBaseInfo([msg.senderUid])).get(msg.senderUid)?.coreInfo.nick; + if (nickname) { + resMsg.sender.nickname = nickname; + return; + } + } resMsg.sender.nickname = (await this.core.apis.UserApi.getUserDetailInfo(msg.senderUid)).nick; } diff --git a/src/onebot/index.ts b/src/onebot/index.ts index f74edfa0..0c651591 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -390,9 +390,6 @@ export class NapCatOneBot11Adapter { this.context.logger.logDebug('有加群请求'); try { let requestUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid); - if (isNaN(parseInt(requestUin))) { - requestUin = (await this.core.apis.UserApi.getUserDetailInfo(notify.user1.uid)).uin; - } const groupRequestEvent = new OB11GroupRequestEvent( this.core, parseInt(notify.group.groupCode),