From 1c3883399875b7374f63b8f960ebd2d7692f8015 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: Sun, 4 Aug 2024 23:26:51 +0800 Subject: [PATCH] fix: 177 --- src/common/server/http.ts | 4 ++-- src/core/src/apis/friend.ts | 3 ++- src/core/src/apis/group.ts | 4 ++-- src/core/src/apis/user.ts | 14 +++++++------- src/onebot11/action/msg/SendMsg/index.ts | 2 +- src/onebot11/server/http.ts | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/common/server/http.ts b/src/common/server/http.ts index b8610fd63..a507b32cf 100644 --- a/src/common/server/http.ts +++ b/src/common/server/http.ts @@ -86,7 +86,7 @@ export abstract class HttpServerBase { this.start(port, host); } - abstract handleFailed(res: Response, payload: any, err: any): void + abstract handleFailed(res: Response, payload: any, err: Error): void registerRouter(method: 'post' | 'get' | string, url: string, handler: RegisterHandler) { if (!url.startsWith('/')) { @@ -111,7 +111,7 @@ export abstract class HttpServerBase { try { res.send(await handler(res, payload)); } catch (e: any) { - this.handleFailed(res, payload, e.stack.toString()); + this.handleFailed(res, payload, e); } }); } diff --git a/src/core/src/apis/friend.ts b/src/core/src/apis/friend.ts index 795a9517d..d9f853fee 100644 --- a/src/core/src/apis/friend.ts +++ b/src/core/src/apis/friend.ts @@ -14,7 +14,7 @@ export class NTQQFriendApi { ); return Array.from(data.values()); } - @CacheClassFuncAsyncExtend(5000, 'getBuddyIdMap', true) + @CacheClassFuncAsyncExtend(3600 * 1000, 'getBuddyIdMap', () => true) static async getBuddyIdMapCache(refresh = false): Promise> { return await NTQQFriendApi.getBuddyIdMap(refresh); } @@ -30,6 +30,7 @@ export class NTQQFriendApi { data.forEach((value, key) => { retMap.set(value.uin!, value.uid!); }); + //console.log('getBuddyIdMap', retMap.getValue); return retMap; } static async getBuddyV2ExWithCate(refresh = false) { diff --git a/src/core/src/apis/group.ts b/src/core/src/apis/group.ts index 811f9dba5..1ccf1e993 100644 --- a/src/core/src/apis/group.ts +++ b/src/core/src/apis/group.ts @@ -23,7 +23,7 @@ export class NTQQGroupApi { return groupList; } - @CacheClassFuncAsyncExtend(600, "LastestSendTime", () => true) + @CacheClassFuncAsyncExtend(3600 * 1000, "LastestSendTime", () => true) static async getGroupMemberLastestSendTimeCache(GroupCode: string) { return NTQQGroupApi.getGroupMemberLastestSendTime(GroupCode); } @@ -184,7 +184,7 @@ export class NTQQGroupApi { if (result.errCode !== 0) { throw ('获取群成员列表出错,' + result.errMsg); } - + //logDebug(`获取群(${groupQQ})成员列表结果:`, `finish: ${result.result.finish}`); //, Array.from(result.result.infos.values())); return result.result.infos; /* diff --git a/src/core/src/apis/user.ts b/src/core/src/apis/user.ts index 04453fb5a..0446c1089 100644 --- a/src/core/src/apis/user.ts +++ b/src/core/src/apis/user.ts @@ -202,11 +202,11 @@ export class NTQQUserApi { } return skey; } - @CacheClassFuncAsyncExtend(3600, 'Uin2Uid', (Uin: string, Uid: string | undefined) => { + @CacheClassFuncAsyncExtend(3600 * 1000, 'Uin2Uid', (Uin: string, Uid: string | undefined) => { if (Uid && Uid.indexOf('u_') != -1) { return true } - logWarn("uin转换到uid时异常", Uin); + logWarn("uin转换到uid时异常", Uin, Uid); return false; }) static async getUidByUin(Uin: string) { @@ -216,11 +216,11 @@ export class NTQQUserApi { } return await NTQQUserApi.getUidByUinV1(Uin); } - @CacheClassFuncAsyncExtend(3600, 'Uid2Uin', (Uid: string | undefined, Uin: number | undefined) => { + @CacheClassFuncAsyncExtend(3600 * 1000, 'Uid2Uin', (Uid: string | undefined, Uin: number | undefined) => { if (Uin && Uin != 0 && !isNaN(Uin)) { return true } - logWarn("uid转换到uin时异常", Uid); + logWarn("uid转换到uin时异常", Uid, Uin); return false; }) static async getUinByUid(Uid: string) { @@ -239,13 +239,13 @@ export class NTQQUserApi { if (uid) return uid; uid = (await napCatCore.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin); if (uid) return uid; + console.log((await NTQQFriendApi.getBuddyIdMapCache(true))); uid = (await NTQQFriendApi.getBuddyIdMapCache(true)).getValue(Uin);//从Buddy缓存获取Uid if (uid) return uid; uid = (await NTQQFriendApi.getBuddyIdMap(true)).getValue(Uin); if (uid) return uid; - // let unveifyUid = (await NTQQUserApi.getUserDetailInfoByUin(Uin)).info.uid;//从QQ Native 特殊转换 - // if (unveifyUid.indexOf("*") == -1) uid = unveifyUid; - + let unveifyUid = (await NTQQUserApi.getUserDetailInfoByUinV2(Uin)).detail.uid;//从QQ Native 特殊转换 + if (unveifyUid.indexOf("*") == -1) uid = unveifyUid; //if (uid) return uid; return uid; } diff --git a/src/onebot11/action/msg/SendMsg/index.ts b/src/onebot11/action/msg/SendMsg/index.ts index 0b557dcff..2932aa775 100644 --- a/src/onebot11/action/msg/SendMsg/index.ts +++ b/src/onebot11/action/msg/SendMsg/index.ts @@ -128,7 +128,7 @@ export class SendMsg extends BaseAction { return { valid: false, message: `群${payload.group_id}不存在` }; } if (payload.user_id && payload.message_type !== 'group') { - const uid = await NTQQUserApi.getUidByUin(payload.user_id); + const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString()); const isBuddy = await NTQQFriendApi.isBuddy(uid!); // 此处有问题 if (!isBuddy) { diff --git a/src/onebot11/server/http.ts b/src/onebot11/server/http.ts index 013989a02..f5c06c5c3 100644 --- a/src/onebot11/server/http.ts +++ b/src/onebot11/server/http.ts @@ -10,8 +10,8 @@ import { postOB11Event } from '@/onebot11/server/postOB11Event'; class OB11HTTPServer extends HttpServerBase { name = 'OneBot V11 server'; - handleFailed(res: Response, payload: any, e: any) { - res.send(OB11Response.error(e.stack.toString(), 200)); + handleFailed(res: Response, payload: any, e: Error) { + res.send(OB11Response.error(e?.stack?.toString() || e.message || "Error Handle", 200)); } protected listen(port: number, host: string) {