Skip to content

Commit

Permalink
fix: 177
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Aug 4, 2024
1 parent 3889417 commit 1c38833
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/common/server/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')) {
Expand All @@ -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);
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/apis/friend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LimitedHashTable<string, string>> {
return await NTQQFriendApi.getBuddyIdMap(refresh);
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/src/apis/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
/*
Expand Down
14 changes: 7 additions & 7 deletions src/core/src/apis/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/onebot11/action/msg/SendMsg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/onebot11/server/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

1 comment on commit 1c38833

@MliKiowa
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有处console.log未注释

Please sign in to comment.