Merge pull request #278 from cnxysoft/upmain

fix: 多处修改
This commit is contained in:
Alen 2024-08-19 10:07:16 +08:00 committed by GitHub
commit 5c1df82076
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 30 deletions

View File

@ -253,22 +253,45 @@ export class NTQQGroupApi {
} }
async getGroupMemberV2(GroupCode: string, uid: string, forced = false) { async getGroupMemberV2(GroupCode: string, uid: string, forced = false) {
type ListenerType = NodeIKernelGroupListener['onMemberInfoChange']; //type ListenerType = NodeIKernelGroupListener['onMemberInfoChange'];
type EventType = NodeIKernelGroupService['getMemberInfo']; type EventType = NodeIKernelGroupService['getMemberInfo'];
// NTEventDispatch.CreatListenerFunction('NodeIKernelGroupListener/onGroupMemberInfoUpdate', // NTEventDispatch.CreatListenerFunction('NodeIKernelGroupListener/onGroupMemberInfoUpdate',
//return napCatCore.session.getGroupService().getMemberInfo(GroupCode, [uid], forced); //return napCatCore.session.getGroupService().getMemberInfo(GroupCode, [uid], forced);
const [, , , _members] = await this.core.eventWrapper.CallNormalEvent<EventType, ListenerType> const Listener = this.core.eventWrapper.RegisterListen<(params: any) => void>
( (
'NodeIKernelGroupService/getMemberInfo',
'NodeIKernelGroupListener/onMemberInfoChange', 'NodeIKernelGroupListener/onMemberInfoChange',
1, 1,
5000, forced ? 5000 : 500,
(groupCode: string, changeType: number, members: Map<string, GroupMember>) => { (params) => {
return groupCode == GroupCode && members.has(uid); return params === GroupCode;
}, },
GroupCode, [uid], forced,
); );
return _members.get(uid); const EventFunc = this.core.eventWrapper.createEventFunction<EventType>('NodeIKernelGroupService/getMemberInfo');
const retData = await EventFunc!(GroupCode, [uid], forced);
if (retData.result !== 0) {
throw new Error(`获取群成员信息失败: ${retData.errMsg}`);
}
const result = await Listener as unknown;
let member: GroupMember | undefined;
if (Array.isArray(result) && result?.[2] instanceof Map) {
let members = result[2] as Map<string, GroupMember>;
member = members.get(uid);
};
return member;
// 原本的方法: (no_cache 下效率很高, cache 下效率一致)
// const [, , , _members] = await this.core.eventWrapper.CallNormalEvent<EventType, ListenerType>
// (
// 'NodeIKernelGroupService/getMemberInfo',
// 'NodeIKernelGroupListener/onMemberInfoChange',
// 1,
// 5000,
// (groupCode: string, changeType: number, members: Map<string, GroupMember>) => {
// return groupCode == GroupCode && members.has(uid);
// },
// GroupCode, [uid], forced,
// );
// return _members.get(uid);
} }
async getGroupMembers(groupQQ: string, num = 3000): Promise<Map<string, GroupMember>> { async getGroupMembers(groupQQ: string, num = 3000): Promise<Map<string, GroupMember>> {

View File

@ -100,7 +100,7 @@ export class NTQQUserApi {
return retData; return retData;
} }
async fetchUserDetailInfo(uid: string) { async fetchUserDetailInfo(uid: string, mode: UserDetailSource = UserDetailSource.KDB) {
type EventService = NodeIKernelProfileService['fetchUserDetailInfo']; type EventService = NodeIKernelProfileService['fetchUserDetailInfo'];
type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged']; type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged'];
const [_retData, profile] = await this.core.eventWrapper.CallNormalEvent<EventService, EventListener>( const [_retData, profile] = await this.core.eventWrapper.CallNormalEvent<EventService, EventListener>(
@ -111,7 +111,7 @@ export class NTQQUserApi {
(profile) => profile.uid === uid, (profile) => profile.uid === uid,
'BuddyProfileStore', 'BuddyProfileStore',
[uid], [uid],
UserDetailSource.KSERVER, mode,
[ProfileBizType.KALL], [ProfileBizType.KALL],
); );
const RetUser: User = { const RetUser: User = {
@ -121,13 +121,19 @@ export class NTQQUserApi {
...profile.commonExt, ...profile.commonExt,
...profile.simpleInfo.baseInfo, ...profile.simpleInfo.baseInfo,
qqLevel: profile.commonExt.qqLevel, qqLevel: profile.commonExt.qqLevel,
age: profile.simpleInfo.baseInfo.age,
pendantId: '', pendantId: '',
}; };
return RetUser; return RetUser;
} }
async getUserDetailInfo(uid: string) { async getUserDetailInfo(uid: string) {
return this.fetchUserDetailInfo(uid); const ret = await this.fetchUserDetailInfo(uid, UserDetailSource.KDB);
if (ret.uin === '0') {
console.log('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.')
return await this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
}
return ret;
} }
async modifySelfProfile(param: ModifyProfileParams) { async modifySelfProfile(param: ModifyProfileParams) {

View File

@ -1,4 +1,4 @@
import { QQLevel, Sex } from './user'; import { QQLevel, Sex, User } from './user';
export enum GroupListUpdateType { export enum GroupListUpdateType {
REFRESHALL, REFRESHALL,
@ -65,6 +65,7 @@ export interface GroupMember {
uin: string; // QQ号 uin: string; // QQ号
isRobot: boolean; isRobot: boolean;
sex?: Sex; sex?: Sex;
age?: number;
qqLevel?: QQLevel; qqLevel?: QQLevel;
isChangeRole: boolean; isChangeRole: boolean;
joinTime: string; joinTime: string;

View File

@ -231,6 +231,7 @@ export interface User {
longNick?: string; // 签名 longNick?: string; // 签名
remark?: string; remark?: string;
sex?: Sex; sex?: Sex;
age?: number;
qqLevel?: QQLevel; qqLevel?: QQLevel;
qid?: string; qid?: string;
birthday_year?: number; birthday_year?: number;

View File

@ -38,22 +38,6 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
} }
const date = Math.round(Date.now() / 1000); const date = Math.round(Date.now() / 1000);
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member); const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member);
const SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), this.CoreContext.selfInfo.uid, isNocache);
let isPrivilege = false;
if (SelfInfoInGroup) {
isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4;
}
if (isPrivilege) {
const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString());
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
if (webGroupMembers[i]?.uin && webGroupMembers[i].uin === retMember.user_id) {
retMember.join_time = webGroupMembers[i]?.join_time;
retMember.last_sent_time = webGroupMembers[i]?.last_speak_time;
retMember.qage = webGroupMembers[i]?.qage;
retMember.level = webGroupMembers[i]?.lv.level.toString();
}
}
}
retMember.last_sent_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString()); retMember.last_sent_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString());
retMember.join_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString()); retMember.join_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString());
return retMember; return retMember;

View File

@ -149,6 +149,7 @@ export class OB11Constructor {
message_data['type'] = OB11MessageDataType.reply; message_data['type'] = OB11MessageDataType.reply;
//log("收到回复消息", element.replyElement); //log("收到回复消息", element.replyElement);
try { try {
let oldMsgFlag = false;
const records = msg.records.find(msgRecord => msgRecord.msgId === element?.replyElement?.sourceMsgIdInRecords); const records = msg.records.find(msgRecord => msgRecord.msgId === element?.replyElement?.sourceMsgIdInRecords);
const peer = { const peer = {
chatType: msg.chatType, chatType: msg.chatType,
@ -163,12 +164,13 @@ export class OB11Constructor {
chatType: msg.chatType, chatType: msg.chatType,
}, element.replyElement.replayMsgSeq, 1, true, true)).msgList.find(msg => msg.msgRandom === records.msgRandom); }, element.replyElement.replayMsgSeq, 1, true, true)).msgList.find(msg => msg.msgRandom === records.msgRandom);
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) { if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
if (!replyMsg && records.msgRandom === '0') oldMsgFlag = true;
replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0]; replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0];
} }
if (msg.peerUin == '284840486') { if (msg.peerUin == '284840486') {
//合并消息内侧 消息具体定位不到 //合并消息内侧 消息具体定位不到
} }
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') { if ((!replyMsg || (records.msgRandom !== replyMsg.msgRandom && !oldMsgFlag || (oldMsgFlag && records.msgSeq !== replyMsg.msgSeq))) && msg.peerUin !== '284840486') {
throw new Error('回复消息消息验证失败'); throw new Error('回复消息消息验证失败');
} }
message_data['data']['id'] = MessageUnique.createMsg({ message_data['data']['id'] = MessageUnique.createMsg({
@ -709,7 +711,7 @@ export class OB11Constructor {
nickname: member.nick, nickname: member.nick,
card: member.cardName, card: member.cardName,
sex: OB11Constructor.sex(member.sex!), sex: OB11Constructor.sex(member.sex!),
age: 0, age: member.age ?? 0,
area: '', area: '',
level: '0', level: '0',
qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0, qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,