Compare commits

..

3 Commits

Author SHA1 Message Date
手瓜一十雪
b2e0cab702 feat: 好友等级 2025-03-27 12:35:05 +08:00
Mlikiowa
3e3609e0f2 release: v4.7.9 2025-03-27 04:16:25 +00:00
手瓜一十雪
83e73d9842 fix: 修复一些数据问题 2025-03-27 12:15:53 +08:00
19 changed files with 156 additions and 191 deletions

View File

@@ -4,7 +4,7 @@
"name": "NapCatQQ", "name": "NapCatQQ",
"slug": "NapCat.Framework", "slug": "NapCat.Framework",
"description": "高性能的 OneBot 11 协议实现", "description": "高性能的 OneBot 11 协议实现",
"version": "4.7.8", "version": "4.7.9",
"icon": "./logo.png", "icon": "./logo.png",
"authors": [ "authors": [
{ {

View File

@@ -2,7 +2,7 @@
"name": "napcat", "name": "napcat",
"private": true, "private": true,
"type": "module", "type": "module",
"version": "4.7.8", "version": "4.7.9",
"scripts": { "scripts": {
"build:universal": "npm run build:webui && vite build --mode universal || exit 1", "build:universal": "npm run build:webui && vite build --mode universal || exit 1",
"build:framework": "npm run build:webui && vite build --mode framework || exit 1", "build:framework": "npm run build:webui && vite build --mode framework || exit 1",

View File

@@ -1 +1 @@
export const napCatVersion = '4.7.8'; export const napCatVersion = '4.7.9';

View File

@@ -44,22 +44,13 @@ export class NTQQGroupApi {
} }
async initApi() { async initApi() {
await this.initCache().then().catch(e => this.context.logger.logError(e)); this.initCache().then().catch(e => this.context.logger.logError(e));
} }
async initCache() { async initCache() {
let promises: Promise<void>[] = [];
for (const group of await this.getGroups(true)) { for (const group of await this.getGroups(true)) {
let user = await this.refreshGroupMemberCache(group.groupCode, false).then().catch(e => this.context.logger.logError(e)); this.refreshGroupMemberCache(group.groupCode, false).then().catch(e => this.context.logger.logError(e));
if (user) {
for (const member of user) {
let promise = this.core.apis.UserApi.fetchUserDetailInfoV3(member[1].uid).then(_ => void 0).catch(e => this.context.logger.logError(e));
promises.push(promise);
}
}
} }
await Promise.all(promises);
this.context.logger.logDebug('[NapCat] [Mark] 群成员缓存初始化完成');
} }
async fetchGroupEssenceList(groupCode: string) { async fetchGroupEssenceList(groupCode: string) {

View File

@@ -1,4 +1,4 @@
import { ModifyProfileParams, UserDetailSource } from '@/core/types'; import { ModifyProfileParams, User, UserDetailSource } from '@/core/types';
import { RequestUtil } from '@/common/request'; import { RequestUtil } from '@/common/request';
import { InstanceContext, NapCatCore, ProfileBizType } from '..'; import { InstanceContext, NapCatCore, ProfileBizType } from '..';
import { solveAsyncProblem } from '@/common/helper'; import { solveAsyncProblem } from '@/common/helper';
@@ -77,7 +77,7 @@ export class NTQQUserApi {
return this.context.session.getGroupService().setHeader(gc, filePath); return this.context.session.getGroupService().setHeader(gc, filePath);
} }
async fetchUserDetailInfoV2(uid: string, mode: UserDetailSource = UserDetailSource.KDB) { async fetchUserDetailInfo(uid: string, mode: UserDetailSource = UserDetailSource.KDB) {
const [, profile] = await this.core.eventWrapper.callNormalEventV2( const [, profile] = await this.core.eventWrapper.callNormalEventV2(
'NodeIKernelProfileService/fetchUserDetailInfo', 'NodeIKernelProfileService/fetchUserDetailInfo',
'NodeIKernelProfileListener/onUserDetailInfoChanged', 'NodeIKernelProfileListener/onUserDetailInfoChanged',
@@ -93,26 +93,37 @@ export class NTQQUserApi {
return profile; return profile;
} }
async fetchUserDetailInfoV3(uid: string) { async getUserDetailInfo(uid: string, no_cache: boolean = false): Promise<User> {
let cache = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KDB); let profile = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, no_cache ? UserDetailSource.KSERVER : UserDetailSource.KDB), uid);
if (!cache.commonExt) { if (profile && profile.uin !== '0' && profile.commonExt) {
cache = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KSERVER); return {
} ...profile.simpleInfo.status,
return cache; ...profile.simpleInfo.vasInfo,
} ...profile.commonExt,
...profile.simpleInfo.baseInfo,
...profile.simpleInfo.coreInfo,
async getUserDetailInfoV2(uid: string) { qqLevel: profile.commonExt?.qqLevel,
let retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfoV2(uid, UserDetailSource.KDB), uid); age: profile.simpleInfo.baseInfo.age,
if (retUser && retUser.uin !== '0') { pendantId: '',
return retUser; nick: profile.simpleInfo.coreInfo.nick || '',
};
} }
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.'); this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
retUser = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KSERVER); profile = await this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
if (retUser && retUser.uin === '0') { if (profile && profile.uin === '0') {
retUser.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0'; profile.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0';
} }
return retUser; return {
...profile.simpleInfo.status,
...profile.simpleInfo.vasInfo,
...profile.commonExt,
...profile.simpleInfo.baseInfo,
...profile.simpleInfo.coreInfo,
qqLevel: profile.commonExt?.qqLevel,
age: profile.simpleInfo.baseInfo.age,
pendantId: '',
nick: profile.simpleInfo.coreInfo.nick || '',
};
} }
async modifySelfProfile(param: ModifyProfileParams) { async modifySelfProfile(param: ModifyProfileParams) {
@@ -201,7 +212,7 @@ export class NTQQUserApi {
.add(() => this.context.session.getUixConvertService().getUin([uid]).then((data) => data.uinInfo.get(uid))) .add(() => this.context.session.getUixConvertService().getUin([uid]).then((data) => data.uinInfo.get(uid)))
.add(() => this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [uid]).get(uid)) .add(() => this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [uid]).get(uid))
.add(() => this.context.session.getGroupService().getUinByUids([uid]).then((data) => data.uins.get(uid))) .add(() => this.context.session.getGroupService().getUinByUids([uid]).then((data) => data.uins.get(uid)))
.add(() => this.fetchUserDetailInfoV2(uid).then((data) => data.uin)); .add(() => this.getUserDetailInfo(uid).then((data) => data.uin));
const uin = await fallback.run().catch(() => '0'); const uin = await fallback.run().catch(() => '0');
return uin ?? '0'; return uin ?? '0';

View File

@@ -1,71 +1,71 @@
import { User, UserDetailInfoListenerArg } from '@/core/types'; import { User, UserDetailInfoListenerArg } from '@/core/types';
export class NodeIKernelProfileListener { export class NodeIKernelProfileListener {
onUserDetailInfoChanged(_arg: UserDetailInfoListenerArg): void { onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void {
} }
onProfileSimpleChanged(..._args: unknown[]): any { onProfileSimpleChanged(...args: unknown[]): any {
} }
onProfileDetailInfoChanged(_profile: User): any { onProfileDetailInfoChanged(profile: User): any {
} }
onStatusUpdate(..._args: unknown[]): any { onStatusUpdate(...args: unknown[]): any {
} }
onSelfStatusChanged(..._args: unknown[]): any { onSelfStatusChanged(...args: unknown[]): any {
} }
onStrangerRemarkChanged(..._args: unknown[]): any { onStrangerRemarkChanged(...args: unknown[]): any {
} }
onMemberListChange(..._args: unknown[]): any { onMemberListChange(...args: unknown[]): any {
} }
onMemberInfoChange(..._args: unknown[]): any { onMemberInfoChange(...args: unknown[]): any {
} }
onGroupListUpdate(..._args: unknown[]): any { onGroupListUpdate(...args: unknown[]): any {
} }
onGroupAllInfoChange(..._args: unknown[]): any { onGroupAllInfoChange(...args: unknown[]): any {
} }
onGroupDetailInfoChange(..._args: unknown[]): any { onGroupDetailInfoChange(...args: unknown[]): any {
} }
onGroupConfMemberChange(..._args: unknown[]): any { onGroupConfMemberChange(...args: unknown[]): any {
} }
onGroupExtListUpdate(..._args: unknown[]): any { onGroupExtListUpdate(...args: unknown[]): any {
} }
onGroupNotifiesUpdated(..._args: unknown[]): any { onGroupNotifiesUpdated(...args: unknown[]): any {
} }
onGroupNotifiesUnreadCountUpdated(..._args: unknown[]): any { onGroupNotifiesUnreadCountUpdated(...args: unknown[]): any {
} }
onGroupMemberLevelInfoChange(..._args: unknown[]): any { onGroupMemberLevelInfoChange(...args: unknown[]): any {
} }
onGroupBulletinChange(..._args: unknown[]): any { onGroupBulletinChange(...args: unknown[]): any {
} }
} }

View File

@@ -1,3 +1,5 @@
import { QQLevel, NTSex } from './user';
export interface KickMemberInfo { export interface KickMemberInfo {
optFlag: number; optFlag: number;
optOperate: number; optOperate: number;
@@ -272,42 +274,24 @@ export enum NTGroupMemberRole {
KOWNER = 4 KOWNER = 4
} }
export interface GroupMember { export interface GroupMember {
uid: string; memberRealLevel: number | undefined;
qid: string; memberSpecialTitle?: string;
uin: string;
nick: string;
remark: string;
cardType: number;
cardName: string;
role: NTGroupMemberRole;
avatarPath: string; avatarPath: string;
shutUpTime: number; cardName: string;
cardType: number;
isDelete: boolean; isDelete: boolean;
isSpecialConcerned: boolean; nick: string;
isSpecialShield: boolean; qid: string;
remark: string;
role: NTGroupMemberRole;
shutUpTime: number; // 禁言时间(S)
uid: string;
uin: string;
isRobot: boolean; isRobot: boolean;
groupHonor: Uint8Array; sex?: NTSex;
memberRealLevel: number; age?: number;
memberLevel: number; qqLevel?: QQLevel;
globalGroupLevel: number; isChangeRole: boolean;
globalGroupPoint: number; joinTime: string;
memberTitleId: number; lastSpeakTime: string;
memberSpecialTitle: string;
specialTitleExpireTime: string;
userShowFlag: number;
userShowFlagNew: number;
richFlag: number;
mssVipType: number;
bigClubLevel: number;
bigClubFlag: number;
autoRemark: string;
creditLevel: number;
joinTime: number;
lastSpeakTime: number;
memberFlag: number;
memberFlagExt: number;
memberMobileFlag: number;
memberFlagExt2: number;
isSpecialShielded: boolean;
cardNameId: number;
} }

View File

@@ -207,8 +207,9 @@ interface PhotoWall {
// 简单信息 // 简单信息
export interface SimpleInfo { export interface SimpleInfo {
uid: string; qqLevel?: QQLevel;//临时添加
uin: string; uid?: string;
uin?: string;
coreInfo: CoreInfo; coreInfo: CoreInfo;
baseInfo: BaseInfo; baseInfo: BaseInfo;
status: UserStatus | null; status: UserStatus | null;
@@ -233,15 +234,13 @@ export interface SelfStatusInfo {
setTime: string; setTime: string;
} }
export type UserV2 = UserDetailInfoListenerArg;
// 用户详细信息监听参数 // 用户详细信息监听参数
export interface UserDetailInfoListenerArg { export interface UserDetailInfoListenerArg {
uid: string; uid: string;
uin: string; uin: string;
simpleInfo?: SimpleInfo; simpleInfo: SimpleInfo;
commonExt?: CommonExt; commonExt: CommonExt;
photoWall?: PhotoWall; photoWall: PhotoWall;
} }
// 修改个人资料参数 // 修改个人资料参数
@@ -334,12 +333,13 @@ export interface User {
} }
// 自身信息 // 自身信息
export interface SelfInfo extends Partial<UserV2> { export interface SelfInfo extends User {
uid: string; online?: boolean;
uin: string;
online: boolean;
} }
// 好友类型
export type Friend = User;
// 业务键枚举 // 业务键枚举
export enum BizKey { export enum BizKey {
KPRIVILEGEICON = 0, KPRIVILEGEICON = 0,

View File

@@ -46,6 +46,7 @@ export async function NCoreInitFramework(
resolveSelfInfo({ resolveSelfInfo({
uid: loginResult.uid, uid: loginResult.uid,
uin: loginResult.uin, uin: loginResult.uin,
nick: '', // 获取不到
online: true, online: true,
}); });
}; };

View File

@@ -19,7 +19,7 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11U
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id); const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id)); let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id));
if (!uid) uid = extendData.detail.uid; if (!uid) uid = extendData.detail.uid;
const info = (await this.core.apis.UserApi.fetchUserDetailInfoV2(uid)); const info = (await this.core.apis.UserApi.getUserDetailInfo(uid));
return { return {
...extendData.detail.simpleInfo.coreInfo, ...extendData.detail.simpleInfo.coreInfo,
...extendData.detail.commonExt ?? {}, ...extendData.detail.commonExt ?? {},
@@ -29,17 +29,17 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11U
user_id: parseInt(extendData.detail.uin) ?? 0, user_id: parseInt(extendData.detail.uin) ?? 0,
uid: info.uid ?? uid, uid: info.uid ?? uid,
nickname: extendData.detail.simpleInfo.coreInfo.nick ?? '', nickname: extendData.detail.simpleInfo.coreInfo.nick ?? '',
age: extendData.detail.simpleInfo.baseInfo.age ?? info.simpleInfo?.baseInfo.age, age: extendData.detail.simpleInfo.baseInfo.age ?? info.age,
qid: extendData.detail.simpleInfo.baseInfo.qid, qid: extendData.detail.simpleInfo.baseInfo.qid,
qqLevel: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? info.commonExt?.qqLevel), qqLevel: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? info.qqLevel),
sex: OB11Construct.sex(extendData.detail.simpleInfo.baseInfo.sex) ?? OB11UserSex.unknown, 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.longNick,
reg_time: extendData.detail.commonExt?.regTime ?? info.commonExt?.regTime, reg_time: extendData.detail.commonExt?.regTime ?? info.regTime,
is_vip: extendData.detail.simpleInfo.vasInfo?.svipFlag, is_vip: extendData.detail.simpleInfo.vasInfo?.svipFlag,
is_years_vip: extendData.detail.simpleInfo.vasInfo?.yearVipFlag, is_years_vip: extendData.detail.simpleInfo.vasInfo?.yearVipFlag,
vip_level: extendData.detail.simpleInfo.vasInfo?.vipLevel, vip_level: extendData.detail.simpleInfo.vasInfo?.vipLevel,
remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.simpleInfo?.coreInfo.remark, remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.remark,
status: extendData.detail.simpleInfo.status?.status ?? info.simpleInfo?.status?.status, status: extendData.detail.simpleInfo.status?.status ?? info.status,
login_days: 0,//失效 login_days: 0,//失效
}; };
} }

View File

@@ -16,15 +16,15 @@ export class SetQQProfile extends OneBotAction<Payload, Awaited<ReturnType<NTQQU
async _handle(payload: Payload) { async _handle(payload: Payload) {
const self = this.core.selfInfo; const self = this.core.selfInfo;
const OldProfile = await this.core.apis.UserApi.fetchUserDetailInfoV2(self.uid); const OldProfile = await this.core.apis.UserApi.getUserDetailInfo(self.uid);
return await this.core.apis.UserApi.modifySelfProfile({ return await this.core.apis.UserApi.modifySelfProfile({
nick: payload.nickname, nick: payload.nickname,
longNick: (payload?.personal_note ?? OldProfile?.simpleInfo!.baseInfo.longNick) || '', longNick: (payload?.personal_note ?? OldProfile?.longNick) || '',
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.simpleInfo!.baseInfo.sex!.toString()), sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
birthday: { birthday: {
birthday_year: OldProfile?.simpleInfo!.baseInfo.birthday_year!.toString(), birthday_year: OldProfile?.birthday_year!.toString(),
birthday_month: OldProfile?.simpleInfo!.baseInfo.birthday_month!.toString(), birthday_month: OldProfile?.birthday_month!.toString(),
birthday_day: OldProfile?.simpleInfo!.baseInfo.birthday_day!.toString(), birthday_day: OldProfile?.birthday_day!.toString(),
}, },
location: undefined, location: undefined,
}); });

View File

@@ -32,20 +32,24 @@ class GetGroupMemberInfo extends OneBotAction<Payload, OB11GroupMember> {
const [member, info] = await Promise.all([ const [member, info] = await Promise.all([
this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache), this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache),
this.core.apis.UserApi.fetchUserDetailInfoV2(uid), this.core.apis.UserApi.getUserDetailInfo(uid),
]); ]);
if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`); if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
return { member, info, groupMember }; return info ? { ...groupMember, ...member, ...info } : member;
} }
async _handle(payload: Payload) { async _handle(payload: Payload) {
const isNocache = this.parseBoolean(payload.no_cache ?? true); const isNocache = this.parseBoolean(payload.no_cache ?? true);
const uid = await this.getUid(payload.user_id); const uid = await this.getUid(payload.user_id);
const { member, info } = await this.getGroupMemberInfo(payload, uid, isNocache); const member = await this.getGroupMemberInfo(payload, uid, isNocache);
console.log('member', JSON.stringify(member, null, 2), 'info', JSON.stringify(info, null, 2));
return OB11Construct.groupMember(payload.group_id.toString(), member, info); if (!member) {
this.core.context.logger.logDebug('获取群成员详细信息失败, 只能返回基础信息');
}
return OB11Construct.groupMember(payload.group_id.toString(), member);
} }
} }

View File

@@ -16,35 +16,16 @@ export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]>
override actionName = ActionName.GetGroupMemberList; override actionName = ActionName.GetGroupMemberList;
override payloadSchema = SchemaData; override payloadSchema = SchemaData;
/**
* 处理获取群成员列表请求
*/
async _handle(payload: Payload) { async _handle(payload: Payload) {
const groupIdStr = payload.group_id.toString(); const groupIdStr = payload.group_id.toString();
const noCache = this.parseBoolean(payload.no_cache ?? false); const noCache = this.parseBoolean(payload.no_cache ?? false);
// 获取群成员基本信息
const groupMembers = await this.getGroupMembers(groupIdStr, noCache); const groupMembers = await this.getGroupMembers(groupIdStr, noCache);
const memberArray = Array.from(groupMembers.values()); const _groupMembers = await Promise.all(
Array.from(groupMembers.values()).map(item =>
// 批量并行获取用户详情 OB11Construct.groupMember(groupIdStr, item)
const userDetailsPromises = memberArray.map(member => )
this.core.apis.UserApi.fetchUserDetailInfoV2(member.uid)
.catch(_ => {
return { uin: member.uin, uid: member.uid };
})
); );
const userDetails = await Promise.all(userDetailsPromises); return Array.from(new Map(_groupMembers.map(member => [member.user_id, member])).values());
// 并行构建 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 { private parseBoolean(value: boolean | string): boolean {
@@ -56,18 +37,13 @@ export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]>
let groupMembers = memberCache.get(groupIdStr); let groupMembers = memberCache.get(groupIdStr);
if (noCache || !groupMembers) { if (noCache || !groupMembers) {
try { const data = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true).then().catch();
const refreshPromise = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true); groupMembers = memberCache.get(groupIdStr) || (await data);
if (!groupMembers) {
groupMembers = memberCache.get(groupIdStr) || (await refreshPromise); throw new Error(`Failed to get group member list for group ${groupIdStr}`);
if (!groupMembers) {
throw new Error(`无法获取群 ${groupIdStr} 的成员列表`);
}
} catch (error) {
throw new Error(`获取群 ${groupIdStr} 成员列表失败: ${error instanceof Error ? error.message : String(error)}`);
} }
} }
return groupMembers; return groupMembers;
} }
} }

View File

@@ -15,24 +15,21 @@ export default class GetFriendList extends OneBotAction<Payload, OB11User[]> {
override payloadSchema = SchemaData; override payloadSchema = SchemaData;
async _handle(_payload: Payload) { async _handle(_payload: Payload) {
// 获取好友列表 const buddyMap = await this.core.apis.FriendApi.getBuddyV2SimpleInfoMap();
let buddyList = await this.core.apis.FriendApi.getBuddyV2SimpleInfoMap();
const buddyArray = Array.from(buddyList.values());
// 批量并行获取用户详情 await Promise.all(
const userDetailsPromises = buddyArray.map(member => Array.from(buddyMap.values()).map(async (buddyInfo) => {
this.core.apis.UserApi.fetchUserDetailInfoV2(member.uid) try {
.catch(_ => { const userDetail = await this.core.apis.UserApi.getUserDetailInfo(buddyInfo.coreInfo.uid);
return { uin: member.uin, uid: member.uid }; const data = buddyMap.get(buddyInfo.coreInfo.uid);
}) if (data) {
data.qqLevel = userDetail.qqLevel;
}
} catch (error) {
this.core.context.logger.logError('获取好友详细信息失败', error);
}
})
); );
const userDetails = await Promise.all(userDetailsPromises); return OB11Construct.friends(Array.from(buddyMap.values()));
const friendList = buddyArray.map((friend, index) => {
const userDetail = userDetails[index] || { uin: friend.uin, uid: friend.uid };
return OB11Construct.friend(friend, userDetail);
});
return friendList;
} }
} }

View File

@@ -444,8 +444,8 @@ export class OneBotMsgApi {
} }
const uid = await this.core.apis.UserApi.getUidByUinV2(`${atQQ}`); const uid = await this.core.apis.UserApi.getUidByUinV2(`${atQQ}`);
if (!uid) throw new Error('Get Uid Error'); if (!uid) throw new Error('Get Uid Error');
const info = await this.core.apis.UserApi.fetchUserDetailInfoV2(uid); const info = await this.core.apis.UserApi.getUserDetailInfo(uid);
return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.simpleInfo?.coreInfo.nick || ''); return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.nick || '');
}, },
[OB11MessageDataType.reply]: async ({ data: { id } }) => { [OB11MessageDataType.reply]: async ({ data: { id } }) => {
@@ -845,7 +845,7 @@ export class OneBotMsgApi {
return; return;
} }
} }
resMsg.sender.nickname = (await this.core.apis.UserApi.fetchUserDetailInfoV2(msg.senderUid)).simpleInfo?.coreInfo.nick || ''; resMsg.sender.nickname = (await this.core.apis.UserApi.getUserDetailInfo(msg.senderUid)).nick;
} }
private async handleTempGroupMessage(resMsg: OB11Message, msg: RawMessage) { private async handleTempGroupMessage(resMsg: OB11Message, msg: RawMessage) {

View File

@@ -1,6 +1,6 @@
import { calcQQLevel } from '@/common/helper'; import { calcQQLevel } from '@/common/helper';
import { FileNapCatOneBotUUID } from '@/common/file-uuid'; import { FileNapCatOneBotUUID } from '@/common/file-uuid';
import { FriendV2, Group, GroupFileInfoUpdateParamType, GroupMember, SelfInfo, NTSex, UserV2 } from '@/core'; import { FriendV2, Group, GroupFileInfoUpdateParamType, GroupMember, SelfInfo, NTSex } from '@/core';
import { import {
OB11Group, OB11Group,
OB11GroupFile, OB11GroupFile,
@@ -14,7 +14,7 @@ export class OB11Construct {
static selfInfo(selfInfo: SelfInfo): OB11User { static selfInfo(selfInfo: SelfInfo): OB11User {
return { return {
user_id: +selfInfo.uin, user_id: +selfInfo.uin,
nickname: selfInfo.simpleInfo?.coreInfo.nick ?? '', nickname: selfInfo.nick,
}; };
} }
@@ -31,10 +31,10 @@ export class OB11Construct {
nickname: rawFriend.coreInfo.nick ?? '', nickname: rawFriend.coreInfo.nick ?? '',
remark: rawFriend.coreInfo.remark ?? rawFriend.coreInfo.nick, remark: rawFriend.coreInfo.remark ?? rawFriend.coreInfo.nick,
sex: this.sex(rawFriend.baseInfo.sex), sex: this.sex(rawFriend.baseInfo.sex),
level: 0, level: rawFriend.qqLevel && calcQQLevel(rawFriend.qqLevel) || 0,
})); }));
} }
static friend(friends: FriendV2,info:UserV2): OB11User { static friend(friends: FriendV2): OB11User {
return { return {
birthday_year: friends.baseInfo.birthday_year, birthday_year: friends.baseInfo.birthday_year,
birthday_month: friends.baseInfo.birthday_month, birthday_month: friends.baseInfo.birthday_month,
@@ -47,8 +47,7 @@ export class OB11Construct {
nickname: friends.coreInfo.nick ?? '', nickname: friends.coreInfo.nick ?? '',
remark: friends.coreInfo.remark ?? friends.coreInfo.nick, remark: friends.coreInfo.remark ?? friends.coreInfo.nick,
sex: this.sex(friends.baseInfo.sex), sex: this.sex(friends.baseInfo.sex),
level: calcQQLevel(info?.commonExt?.qqLevel) || 0, level: 0,
qid: friends.baseInfo.qid,
}; };
} }
static groupMemberRole(role: number): OB11GroupMemberRole | undefined { static groupMemberRole(role: number): OB11GroupMemberRole | undefined {
@@ -69,20 +68,20 @@ export class OB11Construct {
}[sex] || OB11UserSex.unknown; }[sex] || OB11UserSex.unknown;
} }
static groupMember(group_id: string, member: GroupMember, info: UserV2): OB11GroupMember { static groupMember(group_id: string, member: GroupMember): OB11GroupMember {
return { return {
group_id: +group_id, group_id: +group_id,
user_id: +member.uin, user_id: +member.uin,
nickname: member.nick, nickname: member.nick,
card: member.cardName, card: member.cardName,
sex: this.sex(info?.simpleInfo?.baseInfo.sex), sex: this.sex(member.sex),
age: info?.simpleInfo?.baseInfo.age ?? 0, age: member.age ?? 0,
area: info?.commonExt?.address, area: '',
level: member.memberRealLevel?.toString() ?? '0', level: member.memberRealLevel?.toString() ?? '0',
qq_level: info?.commonExt?.qqLevel && calcQQLevel(info.commonExt.qqLevel) || 0, qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,
join_time: +member.joinTime, join_time: +member.joinTime,
last_sent_time: +member.lastSpeakTime, last_sent_time: +member.lastSpeakTime,
title_expire_time: +member.specialTitleExpireTime, title_expire_time: 0,
unfriendly: false, unfriendly: false,
card_changeable: true, card_changeable: true,
is_robot: member.isRobot, is_robot: member.isRobot,

View File

@@ -97,13 +97,13 @@ export class NapCatOneBot11Adapter {
return log; return log;
} }
async InitOneBot() { async InitOneBot() {
const selfInfo = this.core.selfInfo;
const ob11Config = this.configLoader.configData; const ob11Config = this.configLoader.configData;
this.core.apis.UserApi.fetchUserDetailInfoV2(this.core.selfInfo.uid) this.core.apis.UserApi.getUserDetailInfo(selfInfo.uid)
.then((user) => { .then((user) => {
this.core.selfInfo = { ...user, online: this.core.selfInfo.online }; selfInfo.nick = user.nick;
this.context.logger.setLogSelfInfo({ nick: this.core.selfInfo.simpleInfo?.coreInfo.nick ?? '', uid: this.core.selfInfo.uid }); this.context.logger.setLogSelfInfo(selfInfo);
}) })
.catch(e => this.context.logger.logError(e)); .catch(e => this.context.logger.logError(e));
@@ -170,7 +170,7 @@ export class NapCatOneBot11Adapter {
this.initGroupListener(); this.initGroupListener();
WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVesion()); WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVesion());
WebUiDataRuntime.setQQLoginInfo(this.core.selfInfo); WebUiDataRuntime.setQQLoginInfo(selfInfo);
WebUiDataRuntime.setQQLoginStatus(true); WebUiDataRuntime.setQQLoginStatus(true);
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => { WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
const prev = this.configLoader.configData; const prev = this.configLoader.configData;

View File

@@ -1,7 +1,7 @@
export interface OB11User { export interface OB11User {
birthday_year?: number; birthday_year?: number; // 生日
birthday_month?: number; birthday_month?: number; // 生日
birthday_day?: number; birthday_day?: number; // 生日
phone_num?: string; // 手机号 phone_num?: string; // 手机号
email?: string; // 邮箱 email?: string; // 邮箱
category_id?: number; // 分组ID category_id?: number; // 分组ID

View File

@@ -131,6 +131,7 @@ async function handleLogin(
inner_resolve({ inner_resolve({
uid: loginResult.uid, uid: loginResult.uid,
uin: loginResult.uin, uin: loginResult.uin,
nick: '',
online: true, online: true,
}); });
@@ -345,8 +346,8 @@ export async function NCoreInitShell() {
guid, guid,
basicInfoWrapper.QQVersionAppid, basicInfoWrapper.QQVersionAppid,
basicInfoWrapper.getFullQQVesion(), basicInfoWrapper.getFullQQVesion(),
selfInfo.uin ?? '', selfInfo.uin,
selfInfo.uid ?? '', selfInfo.uid,
dataPath, dataPath,
); );
@@ -379,6 +380,7 @@ export async function NCoreInitShell() {
export class NapCatShell { export class NapCatShell {
readonly core: NapCatCore; readonly core: NapCatCore;
readonly context: InstanceContext; readonly context: InstanceContext;
constructor( constructor(
wrapper: WrapperNodeApi, wrapper: WrapperNodeApi,
session: NodeIQQNTWrapperSession, session: NodeIQQNTWrapperSession,