mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor
This commit is contained in:
@@ -239,7 +239,7 @@ export type UserV2 = UserDetailInfoListenerArg;
|
||||
export interface UserDetailInfoListenerArg {
|
||||
uid: string;
|
||||
uin: string;
|
||||
simpleInfo: SimpleInfo;
|
||||
simpleInfo?: SimpleInfo;
|
||||
commonExt?: CommonExt;
|
||||
photoWall?: PhotoWall;
|
||||
}
|
||||
|
||||
@@ -29,17 +29,17 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11U
|
||||
user_id: parseInt(extendData.detail.uin) ?? 0,
|
||||
uid: info.uid ?? uid,
|
||||
nickname: extendData.detail.simpleInfo.coreInfo.nick ?? '',
|
||||
age: extendData.detail.simpleInfo.baseInfo.age ?? info.simpleInfo.baseInfo.age,
|
||||
age: extendData.detail.simpleInfo.baseInfo.age ?? info.simpleInfo?.baseInfo.age,
|
||||
qid: extendData.detail.simpleInfo.baseInfo.qid,
|
||||
qqLevel: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? info.commonExt?.qqLevel),
|
||||
sex: OB11Construct.sex(extendData.detail.simpleInfo.baseInfo.sex) ?? OB11UserSex.unknown,
|
||||
long_nick: extendData.detail.simpleInfo.baseInfo.longNick ?? info.simpleInfo.baseInfo.longNick,
|
||||
long_nick: extendData.detail.simpleInfo.baseInfo.longNick ?? info.simpleInfo?.baseInfo.longNick,
|
||||
reg_time: extendData.detail.commonExt?.regTime ?? info.commonExt?.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.simpleInfo.coreInfo.remark,
|
||||
status: extendData.detail.simpleInfo.status?.status ?? info.simpleInfo.status?.status,
|
||||
remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.simpleInfo?.coreInfo.remark,
|
||||
status: extendData.detail.simpleInfo.status?.status ?? info.simpleInfo?.status?.status,
|
||||
login_days: 0,//失效
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ export class SetQQProfile extends OneBotAction<Payload, Awaited<ReturnType<NTQQU
|
||||
const OldProfile = await this.core.apis.UserApi.getUserDetailInfoV2(self.uid);
|
||||
return await this.core.apis.UserApi.modifySelfProfile({
|
||||
nick: payload.nickname,
|
||||
longNick: (payload?.personal_note ?? OldProfile?.simpleInfo.baseInfo.longNick) || '',
|
||||
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.simpleInfo.baseInfo.sex!.toString()),
|
||||
longNick: (payload?.personal_note ?? OldProfile?.simpleInfo!.baseInfo.longNick) || '',
|
||||
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.simpleInfo!.baseInfo.sex!.toString()),
|
||||
birthday: {
|
||||
birthday_year: OldProfile?.simpleInfo.baseInfo.birthday_year!.toString(),
|
||||
birthday_month: OldProfile?.simpleInfo.baseInfo.birthday_month!.toString(),
|
||||
birthday_day: OldProfile?.simpleInfo.baseInfo.birthday_day!.toString(),
|
||||
birthday_year: OldProfile?.simpleInfo!.baseInfo.birthday_year!.toString(),
|
||||
birthday_month: OldProfile?.simpleInfo!.baseInfo.birthday_month!.toString(),
|
||||
birthday_day: OldProfile?.simpleInfo!.baseInfo.birthday_day!.toString(),
|
||||
},
|
||||
location: undefined,
|
||||
});
|
||||
|
||||
@@ -16,16 +16,35 @@ export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]>
|
||||
override actionName = ActionName.GetGroupMemberList;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
/**
|
||||
* 处理获取群成员列表请求
|
||||
*/
|
||||
async _handle(payload: Payload) {
|
||||
const groupIdStr = payload.group_id.toString();
|
||||
const noCache = this.parseBoolean(payload.no_cache ?? false);
|
||||
|
||||
// 获取群成员基本信息
|
||||
const groupMembers = await this.getGroupMembers(groupIdStr, noCache);
|
||||
const _groupMembers = await Promise.all(
|
||||
Array.from(groupMembers.values()).map(async item =>
|
||||
OB11Construct.groupMember(groupIdStr, item, await this.core.apis.UserApi.getUserDetailInfoV2(item.uin))
|
||||
)
|
||||
const memberArray = Array.from(groupMembers.values());
|
||||
|
||||
// 批量并行获取用户详情
|
||||
const userDetailsPromises = memberArray.map(member =>
|
||||
this.core.apis.UserApi.getUserDetailInfoV2(member.uin)
|
||||
.catch(_ => {
|
||||
return { uin: member.uin, uid: member.uid };
|
||||
})
|
||||
);
|
||||
return Array.from(new Map(_groupMembers.map(member => [member.user_id, member])).values());
|
||||
const userDetails = await Promise.all(userDetailsPromises);
|
||||
|
||||
// 并行构建 OneBot 格式的群成员数据
|
||||
const groupMembersList = memberArray.map((member, index) => {
|
||||
// 确保用户详情不会是undefined
|
||||
const userDetail = userDetails[index] || { uin: member.uin, uid: member.uid };
|
||||
return OB11Construct.groupMember(groupIdStr, member, userDetail);
|
||||
});
|
||||
|
||||
// 直接返回处理后的成员列表,不进行去重
|
||||
return groupMembersList;
|
||||
}
|
||||
|
||||
private parseBoolean(value: boolean | string): boolean {
|
||||
@@ -37,13 +56,18 @@ export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]>
|
||||
let groupMembers = memberCache.get(groupIdStr);
|
||||
|
||||
if (noCache || !groupMembers) {
|
||||
const data = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true).then().catch();
|
||||
groupMembers = memberCache.get(groupIdStr) || (await data);
|
||||
if (!groupMembers) {
|
||||
throw new Error(`Failed to get group member list for group ${groupIdStr}`);
|
||||
try {
|
||||
const refreshPromise = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true);
|
||||
|
||||
groupMembers = memberCache.get(groupIdStr) || (await refreshPromise);
|
||||
|
||||
if (!groupMembers) {
|
||||
throw new Error(`无法获取群 ${groupIdStr} 的成员列表`);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`获取群 ${groupIdStr} 成员列表失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
return groupMembers;
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,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);
|
||||
return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.simpleInfo.coreInfo.nick || '');
|
||||
return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.simpleInfo?.coreInfo.nick || '');
|
||||
},
|
||||
|
||||
[OB11MessageDataType.reply]: async ({ data: { id } }) => {
|
||||
@@ -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.getUserDetailInfoV2(msg.senderUid)).simpleInfo?.coreInfo.nick || '';
|
||||
}
|
||||
|
||||
private async handleTempGroupMessage(resMsg: OB11Message, msg: RawMessage) {
|
||||
|
||||
@@ -59,8 +59,8 @@ export class OB11Construct {
|
||||
user_id: +member.uin,
|
||||
nickname: member.nick,
|
||||
card: member.cardName,
|
||||
sex: this.sex(info?.simpleInfo.baseInfo.sex),
|
||||
age: info?.simpleInfo.baseInfo.age ?? 0,
|
||||
sex: this.sex(info?.simpleInfo?.baseInfo.sex),
|
||||
age: info?.simpleInfo?.baseInfo.age ?? 0,
|
||||
area: info?.commonExt?.address,
|
||||
level: member.memberRealLevel?.toString() ?? '0',
|
||||
qq_level: info?.commonExt?.qqLevel && calcQQLevel(info.commonExt.qqLevel) || 0,
|
||||
|
||||
Reference in New Issue
Block a user