From 90a91e4105f5d9044daf9836a2d87aaf05eb556f 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: Fri, 13 Sep 2024 13:54:12 +0800 Subject: [PATCH] fix --- src/common/helper.ts | 3 +- .../action/go-cqhttp/GetStrangerInfo.ts | 38 +++++++++---------- src/onebot/types/entity.ts | 1 + 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/common/helper.ts b/src/common/helper.ts index 59c771aa..c758c3a9 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -209,7 +209,8 @@ export function getQQVersionConfigPath(exePath: string = ''): string | undefined return configVersionInfoPath; } -export function calcQQLevel(level: QQLevel) { +export function calcQQLevel(level?: QQLevel) { + if (!level) return 0; const { crownNum, sunNum, moonNum, starNum } = level; return crownNum * 64 + sunNum * 16 + moonNum * 4 + starNum; } diff --git a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts index 51d7cd3a..3081c4a2 100644 --- a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts +++ b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts @@ -21,24 +21,24 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction { const user_id = payload.user_id.toString(); const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id); - const uid = (await this.core.apis.UserApi.getUidByUinV2(user_id))!; - if (!uid || uid.indexOf('*') != -1) { - return { - ...extendData.detail.simpleInfo.coreInfo, - ...extendData.detail.commonExt, - ...extendData.detail.simpleInfo.baseInfo, - ...extendData.detail.simpleInfo.relationFlags, - ...extendData.detail.simpleInfo.status, - user_id: parseInt(extendData.detail.uin) || 0, - nickname: extendData.detail.simpleInfo.coreInfo.nick, - sex: OB11UserSex.unknown, - age: extendData.detail.simpleInfo.baseInfo.age || 0, - qid: extendData.detail.simpleInfo.baseInfo.qid, - level: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? 0) || 0, - login_days: 0, - }; - } - const data = { ...extendData, ...(await this.core.apis.UserApi.getUserDetailInfo(uid)) }; - return OB11Entities.stranger(data); + let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id)); + if (!uid) uid = extendData.detail.uid; + const info = (await this.core.apis.UserApi.getUserDetailInfo(uid)); + + return { + user_id: parseInt(extendData.detail.uin) ?? 0, + nickname: extendData.detail.simpleInfo.coreInfo.nick, + age: extendData.detail.simpleInfo.baseInfo.age ?? info.age, + qid: extendData.detail.simpleInfo.baseInfo.qid, + qqLevel: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? info.qqLevel), + sex: OB11Entities.sex(extendData.detail.simpleInfo.baseInfo.sex) ?? OB11UserSex.unknown, + long_nick: extendData.detail.simpleInfo.baseInfo.longNick ?? info.longNick, + reg_time: extendData.detail.commonExt.regTime ?? info.regTime, + is_vip: extendData.detail.simpleInfo.vasInfo?.svipFlag, + is_years_vip: extendData.detail.simpleInfo.vasInfo?.yearVipFlag, + vip_level: extendData.detail.simpleInfo.vasInfo?.vipLevel, + remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.remark, + status: extendData.detail.simpleInfo.status?.status ?? info.status + }; } } diff --git a/src/onebot/types/entity.ts b/src/onebot/types/entity.ts index 07355bba..f64cd08f 100644 --- a/src/onebot/types/entity.ts +++ b/src/onebot/types/entity.ts @@ -1,4 +1,5 @@ export interface OB11User { + [key: string]: any; user_id: number; nickname: string; remark?: string;