diff --git a/src/core/apis/msg.ts b/src/core/apis/msg.ts index a0059d66..87fa8ce5 100644 --- a/src/core/apis/msg.ts +++ b/src/core/apis/msg.ts @@ -103,18 +103,18 @@ export class NTQQMsgApi { const data = await this.core.eventWrapper.CallNormalEvent< (GroupCode: string, params: GetFileListParam) => Promise, (groupFileListResult: onGroupFileInfoUpdateParamType) => void - >( - 'NodeIKernelRichMediaService/getGroupFileList', - 'NodeIKernelMsgListener/onGroupFileInfoUpdate', - 1, - 5000, - (groupFileListResult: onGroupFileInfoUpdateParamType) => { + >( + 'NodeIKernelRichMediaService/getGroupFileList', + 'NodeIKernelMsgListener/onGroupFileInfoUpdate', + 1, + 5000, + (groupFileListResult: onGroupFileInfoUpdateParamType) => { //Developer Mlikiowa Todo: 此处有问题 无法判断是否成功 - return true; - }, - GroupCode, - params, - ); + return true; + }, + GroupCode, + params, + ); return data[1].item; } @@ -129,61 +129,6 @@ export class NTQQMsgApi { peerUid: peer.peerUid, }, msgIds); } - - async sendMsgV2(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { - function generateMsgId() { - const timestamp = Math.floor(Date.now() / 1000); - const random = Math.floor(Math.random() * Math.pow(2, 32)); - const buffer = Buffer.alloc(8); - buffer.writeUInt32BE(timestamp, 0); - buffer.writeUInt32BE(random, 4); - const msgId = BigInt('0x' + buffer.toString('hex')).toString(); - return msgId; - } - - // 此处有采用Hack方法 利用数据返回正确得到对应消息 - // 与之前 Peer队列 MsgSeq队列 真正的MsgId并发不同 - // 谨慎采用 目前测试暂无问题 Developer.Mlikiowa - let msgId: string; - try { - msgId = await this.getMsgUnique(peer.chatType, await this.getServerTime()); - } catch (error) { - //if (!napCatCore.session.getMsgService()['generateMsgUniqueId']) - //兜底识别策略V2 - msgId = generateMsgId().toString(); - } - const data = await this.core.eventWrapper.CallNormalEvent< - (msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map) => Promise, - (msgList: RawMessage[]) => void - >( - 'NodeIKernelMsgService/sendMsg', - 'NodeIKernelMsgListener/onMsgInfoListUpdate', - 1, - timeout, - (msgRecords: RawMessage[]) => { - for (const msgRecord of msgRecords) { - if (msgRecord.msgId === msgId && msgRecord.sendStatus === 2) { - return true; - } - } - return false; - }, - msgId, - peer, - msgElements, - new Map(), - ); - const retMsg = data[1].find(msgRecord => { - if (msgRecord.msgId === msgId) { - return true; - } - }); - return retMsg; - } - - sendMsgEx(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { - //return NTQQMsgApi.sendMsgV1(peer, msgElements, waitComplete, timeout); - } async PrepareTempChat(toUserUid: string, GroupCode: string, nickname: string) { //By Jadx/Ida Mlikiowa const TempGameSession = { @@ -215,29 +160,29 @@ export class NTQQMsgApi { await this.PrepareTempChat(peer.peerUid, peer.guildId, member.nick); } } - const msgId = await this.getMsgUnique(peer.chatType, await this.getServerTime()); + const msgId = await this.generateMsgUniqueId(peer.chatType, await this.getServerTime()); peer.guildId = msgId; const data = await this.core.eventWrapper.CallNormalEvent< (msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map) => Promise, (msgList: RawMessage[]) => void - >( - 'NodeIKernelMsgService/sendMsg', - 'NodeIKernelMsgListener/onMsgInfoListUpdate', - 1, - timeout, - (msgRecords: RawMessage[]) => { - for (const msgRecord of msgRecords) { - if (msgRecord.guildId === msgId && msgRecord.sendStatus === 2) { - return true; - } + >( + 'NodeIKernelMsgService/sendMsg', + 'NodeIKernelMsgListener/onMsgInfoListUpdate', + 1, + timeout, + (msgRecords: RawMessage[]) => { + for (const msgRecord of msgRecords) { + if (msgRecord.guildId === msgId && msgRecord.sendStatus === 2) { + return true; } - return false; - }, - '0', - peer, - msgElements, - new Map(), - ); + } + return false; + }, + '0', + peer, + msgElements, + new Map(), + ); const retMsg = data[1].find(msgRecord => { if (msgRecord.guildId === msgId) { return true; @@ -246,11 +191,8 @@ export class NTQQMsgApi { return retMsg; } - async getMsgUnique(chatType: number, time: string) { - if (this.context.basicInfoWrapper.requireMinNTQQBuild('26702')) { - return this.context.session.getMsgService().generateMsgUniqueId(chatType, time); - } - return this.context.session.getMsgService().getMsgUniqueId(time); + async generateMsgUniqueId(chatType: number, time: string) { + return this.context.session.getMsgService().generateMsgUniqueId(chatType, time); } async getServerTime() { @@ -272,25 +214,25 @@ export class NTQQMsgApi { const data = await this.core.eventWrapper.CallNormalEvent< (msgInfo: typeof msgInfos, srcPeer: Peer, destPeer: Peer, comment: Array, attr: Map) => Promise, (msgList: RawMessage[]) => void - >( - 'NodeIKernelMsgService/multiForwardMsgWithComment', - 'NodeIKernelMsgListener/onMsgInfoListUpdate', - 1, - 5000, - (msgRecords: RawMessage[]) => { - for (const msgRecord of msgRecords) { - if (msgRecord.peerUid == destPeer.peerUid && msgRecord.senderUid == this.core.selfInfo.uid) { - return true; - } + >( + 'NodeIKernelMsgService/multiForwardMsgWithComment', + 'NodeIKernelMsgListener/onMsgInfoListUpdate', + 1, + 5000, + (msgRecords: RawMessage[]) => { + for (const msgRecord of msgRecords) { + if (msgRecord.peerUid == destPeer.peerUid && msgRecord.senderUid == this.core.selfInfo.uid) { + return true; } - return false; - }, - msgInfos, - srcPeer, - destPeer, - [], - new Map(), - ); + } + return false; + }, + msgInfos, + srcPeer, + destPeer, + [], + new Map(), + ); for (const msg of data[1]) { const arkElement = msg.elements.find(ele => ele.arkElement); if (!arkElement) { diff --git a/src/core/apis/user.ts b/src/core/apis/user.ts index d8f79449..eeae246a 100644 --- a/src/core/apis/user.ts +++ b/src/core/apis/user.ts @@ -231,11 +231,6 @@ export class NTQQUserApi { if (uid) return uid; uid = (await this.context.session.getUixConvertService().getUid([Uin])).uidInfo.get(Uin); if (uid) return uid; - // console.log((await this.core.getApiContext().FriendApi.getBuddyIdMapCache(true))); - uid = (await this.core.apis.FriendApi.getBuddyIdMapCache(true)).getValue(Uin);//从Buddy缓存获取Uid - if (uid) return uid; - uid = (await this.core.apis.FriendApi.getBuddyIdMap(true)).getValue(Uin); - if (uid) return uid; const unveifyUid = (await this.getUserDetailInfoByUinV2(Uin)).detail.uid;//从QQ Native 特殊转换 if (unveifyUid.indexOf('*') == -1) uid = unveifyUid; //if (uid) return uid; @@ -250,8 +245,6 @@ export class NTQQUserApi { if (uin) return uin; uin = (await this.context.session.getUixConvertService().getUin([Uid])).uinInfo.get(Uid); if (uin) return uin; - uin = (await this.core.apis.FriendApi.getBuddyIdMapCache(true)).getKey(Uid);//从Buddy缓存获取Uin - if (uin) return uin; uin = (await this.core.apis.FriendApi.getBuddyIdMap(true)).getKey(Uid); if (uin) return uin; uin = (await this.getUserDetailInfo(Uid)).uin; //从QQ Native 转换 diff --git a/src/onebot/action/extends/GetProfileLike.ts b/src/onebot/action/extends/GetProfileLike.ts index b6a7a47a..d9312bb6 100644 --- a/src/onebot/action/extends/GetProfileLike.ts +++ b/src/onebot/action/extends/GetProfileLike.ts @@ -9,7 +9,7 @@ export class GetProfileLike extends BaseAction { const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid); const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos; for (let i = 0; i < listdata.length; i++) { - listdata[i].uin = parseInt((await NTQQUserApi.getUinByUid(listdata[i].uid)) || ''); + listdata[i].uin = parseInt((await NTQQUserApi.getUinByUidV2(listdata[i].uid)) || ''); } return listdata; } diff --git a/src/onebot/action/group/GetGroupSystemMsg.ts b/src/onebot/action/group/GetGroupSystemMsg.ts index 00a2a626..53a04dbf 100644 --- a/src/onebot/action/group/GetGroupSystemMsg.ts +++ b/src/onebot/action/group/GetGroupSystemMsg.ts @@ -24,22 +24,22 @@ export class GetGroupSystemMsg extends BaseAction { if (SSNotify.type == 1) { retData.InvitedRequest.push({ request_id: SSNotify.seq, - invitor_uin: await NTQQUserApi.getUinByUid(SSNotify.user1?.uid), + invitor_uin: await NTQQUserApi.getUinByUidV2(SSNotify.user1?.uid), invitor_nick: SSNotify.user1?.nickName, group_id: SSNotify.group?.groupCode, group_name: SSNotify.group?.groupName, checked: SSNotify.status === 1 ? false : true, - actor: await NTQQUserApi.getUinByUid(SSNotify.user2?.uid) || 0, + actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0, }); } else if (SSNotify.type == 7) { retData.join_requests.push({ request_id: SSNotify.seq, - requester_uin: await NTQQUserApi.getUinByUid(SSNotify.user1?.uid), + requester_uin: await NTQQUserApi.getUinByUidV2(SSNotify.user1?.uid), requester_nick: SSNotify.user1?.nickName, group_id: SSNotify.group?.groupCode, group_name: SSNotify.group?.groupName, checked: SSNotify.status === 1 ? false : true, - actor: await NTQQUserApi.getUinByUid(SSNotify.user2?.uid) || 0, + actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0, }); } } diff --git a/src/onebot/helper/data.ts b/src/onebot/helper/data.ts index ebcf7585..b1e44cc3 100644 --- a/src/onebot/helper/data.ts +++ b/src/onebot/helper/data.ts @@ -119,7 +119,7 @@ export class OB11Constructor { const { atNtUid, content } = element.textElement; let atQQ = element.textElement.atUid; if (!atQQ || atQQ === '0') { - atQQ = await NTQQUserApi.getUinByUid(atNtUid); + atQQ = await NTQQUserApi.getUinByUidV2(atNtUid); } if (atQQ) { qq = atQQ as `${number}`;