From a2056a43f38162b79a0a728f0e401039e46a8cbe Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 31 Aug 2024 01:29:44 +0800 Subject: [PATCH 1/6] fix --- src/ntqqapi/api/user.ts | 4 ++-- src/ntqqapi/services/NodeIKernelRichMediaService.ts | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index d689fc6..00fe4dd 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -214,7 +214,7 @@ export class NTQQUserApi extends Service { if (uid) return uid uid = (await invoke('nodeIKernelProfileService/getUidByUin', [{ callFrom: 'FriendsServiceImpl', uin: [uin] }, null])).get(uin) if (uid) return uid - uid = (await invoke('nodeIKernelUixConvertService/getUid', [{ uin: [uin] }, null])).uidInfo.get(uin) + uid = (await invoke('nodeIKernelUixConvertService/getUid', [{ uins: [uin] }, null])).uidInfo.get(uin) if (uid) return uid } const unveifyUid = (await this.getUserDetailInfoByUinV2(uin)).detail.uid //从QQ Native 特殊转换 @@ -284,7 +284,7 @@ export class NTQQUserApi extends Service { if (uin) return uin uin = (await invoke('nodeIKernelProfileService/getUinByUid', [{ callFrom: 'FriendsServiceImpl', uid: [uid] }, null])).get(uid) if (uin) return uin - uin = (await invoke('nodeIKernelUixConvertService/getUin', [{ uid: [uid] }, null])).uinInfo.get(uid) + uin = (await invoke('nodeIKernelUixConvertService/getUin', [{ uids: [uid] }, null])).uinInfo.get(uid) if (uin) return uin } let uin = (await this.ctx.ntFriendApi.getBuddyIdMap(true)).getKey(uid) diff --git a/src/ntqqapi/services/NodeIKernelRichMediaService.ts b/src/ntqqapi/services/NodeIKernelRichMediaService.ts index 5e0b433..1dfa8e5 100644 --- a/src/ntqqapi/services/NodeIKernelRichMediaService.ts +++ b/src/ntqqapi/services/NodeIKernelRichMediaService.ts @@ -177,8 +177,6 @@ export interface NodeIKernelRichMediaService { renameGroupFolder(arg1: unknown, arg2: unknown, arg3: unknown): unknown - deleteGroupFolder(arg1: unknown, arg2: unknown): unknown - deleteTransferInfo(arg1: unknown, arg2: unknown): unknown cancelTransferTask(arg1: unknown, arg2: unknown, arg3: unknown): unknown From 388e01636507b9e7b4a6ba3aeab19d4c29875589 Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 31 Aug 2024 19:41:48 +0800 Subject: [PATCH 2/6] optimize --- src/ntqqapi/api/friend.ts | 20 +++++++++++++------- src/ntqqapi/api/user.ts | 14 +++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/ntqqapi/api/friend.ts b/src/ntqqapi/api/friend.ts index 2c84522..21b6eb0 100644 --- a/src/ntqqapi/api/friend.ts +++ b/src/ntqqapi/api/friend.ts @@ -4,7 +4,6 @@ import { invoke, NTMethod, NTClass } from '../ntcall' import { getSession } from '@/ntqqapi/wrapper' import { BuddyListReqType, NodeIKernelProfileService } from '../services' import { NTEventDispatch } from '@/common/utils/eventTask' -import { LimitedHashTable } from '@/common/utils/table' import { pick } from 'cosmokit' import { Service, Context } from 'cordis' @@ -101,8 +100,9 @@ export class NTQQFriendApi extends Service { } } - async getBuddyIdMap(refresh = false): Promise> { - const retMap: LimitedHashTable = new LimitedHashTable(5000) + /** uid => uin */ + async getBuddyIdMap(refresh = false): Promise> { + const retMap: Map = new Map() const session = getSession() if (session) { const uids: string[] = [] @@ -112,9 +112,12 @@ export class NTQQFriendApi extends Service { const data = await NTEventDispatch.CallNoListenerEvent( 'NodeIKernelProfileService/getCoreAndBaseInfo', 5000, 'nodeStore', uids ) - data.forEach((value, key) => { - retMap.set(value.uin!, value.uid!) - }) + for (const [, item] of data) { + if (retMap.size > 5000) { + break + } + retMap.set(item.uid!, item.uin!) + } } else { const data = await invoke<{ buddyCategory: CategoryFriend[] @@ -129,7 +132,10 @@ export class NTQQFriendApi extends Service { } ) for (const item of Object.values(data.userSimpleInfos)) { - retMap.set(item.uin!, item.uid!) + if (retMap.size > 5000) { + break + } + retMap.set(item.uid!, item.uin!) } } return retMap diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index 00fe4dd..1f15688 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -210,11 +210,11 @@ export class NTQQUserApi extends Service { uid = (await session.getUixConvertService().getUid([uin])).uidInfo.get(uin) if (uid) return uid } else { - let uid = (await invoke('nodeIKernelGroupService/getUidByUins', [{ uin: [uin] }, null])).uids.get(uin) + let uid = (await invoke('nodeIKernelGroupService/getUidByUins', [{ uin: [uin] }])).uids.get(uin) if (uid) return uid - uid = (await invoke('nodeIKernelProfileService/getUidByUin', [{ callFrom: 'FriendsServiceImpl', uin: [uin] }, null])).get(uin) + uid = (await invoke('nodeIKernelProfileService/getUidByUin', [{ callFrom: 'FriendsServiceImpl', uin: [uin] }])).get(uin) if (uid) return uid - uid = (await invoke('nodeIKernelUixConvertService/getUid', [{ uins: [uin] }, null])).uidInfo.get(uin) + uid = (await invoke('nodeIKernelUixConvertService/getUid', [{ uins: [uin] }])).uidInfo.get(uin) if (uid) return uid } const unveifyUid = (await this.getUserDetailInfoByUinV2(uin)).detail.uid //从QQ Native 特殊转换 @@ -280,14 +280,14 @@ export class NTQQUserApi extends Service { uin = (await session.getUixConvertService().getUin([uid])).uinInfo.get(uid) if (uin) return uin } else { - let uin = (await invoke('nodeIKernelGroupService/getUinByUids', [{ uid: [uid] }, null])).uins.get(uid) + let uin = (await invoke('nodeIKernelGroupService/getUinByUids', [{ uid: [uid] }])).uins.get(uid) if (uin) return uin - uin = (await invoke('nodeIKernelProfileService/getUinByUid', [{ callFrom: 'FriendsServiceImpl', uid: [uid] }, null])).get(uid) + uin = (await invoke('nodeIKernelProfileService/getUinByUid', [{ callFrom: 'FriendsServiceImpl', uid: [uid] }])).get(uid) if (uin) return uin - uin = (await invoke('nodeIKernelUixConvertService/getUin', [{ uids: [uid] }, null])).uinInfo.get(uid) + uin = (await invoke('nodeIKernelUixConvertService/getUin', [{ uids: [uid] }])).uinInfo.get(uid) if (uin) return uin } - let uin = (await this.ctx.ntFriendApi.getBuddyIdMap(true)).getKey(uid) + let uin = (await this.ctx.ntFriendApi.getBuddyIdMap(true)).get(uid) if (uin) return uin uin = (await this.getUserDetailInfo(uid)).uin //从QQ Native 转换 return uin From 44921e85ad4454dc14f7085d47fcba6b68996ffa Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 31 Aug 2024 19:46:35 +0800 Subject: [PATCH 3/6] chore --- src/ntqqapi/api/user.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index 1f15688..b686f0e 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -144,7 +144,7 @@ export class NTQQUserApi extends Service { } const uin = selfInfo.uin const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + uin + '&clientkey=' + clientKeyData.clientKey + '&u1=https%3A%2F%2F' + domain + '%2F' + uin + '%2Finfocenter&keyindex=19%27' - const cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl) + const cookies: { [key: string]: string } = await RequestUtil.HttpsGetCookies(requestUrl) return cookies } @@ -192,7 +192,7 @@ export class NTQQUserApi extends Service { // 通用转换开始尝试 let uid = (await session?.getUixConvertService().getUid([Uin]))?.uidInfo.get(Uin) if (!uid) { - let unveifyUid = (await this.getUserDetailInfoByUin(Uin)).info.uid;//从QQ Native 特殊转换 方法三 + let unveifyUid = (await this.getUserDetailInfoByUin(Uin)).info.uid //从QQ Native 特殊转换 方法三 if (unveifyUid.indexOf('*') == -1) { uid = unveifyUid } From f8b2be246f04fb0ed87cc9f89d1c32062124d34e Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 31 Aug 2024 22:55:26 +0800 Subject: [PATCH 4/6] optimize --- src/common/utils/messageUnique.ts | 2 +- src/ntqqapi/ntcall.ts | 17 +++++++-------- src/onebot11/entities.ts | 35 ++++++++++++++----------------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/common/utils/messageUnique.ts b/src/common/utils/messageUnique.ts index c733a76..3df7330 100644 --- a/src/common/utils/messageUnique.ts +++ b/src/common/utils/messageUnique.ts @@ -82,7 +82,7 @@ class MessageUniqueWrapper { return ret.map((t) => t?.MsgId).filter((t) => t !== undefined) } - createMsg(peer: Peer, msgId: string): number | undefined { + createMsg(peer: Peer, msgId: string): number { const key = `${msgId}|${peer.chatType}|${peer.peerUid}` const hash = createHash('md5').update(key).digest() //设置第一个bit为0 保证shortId为正数 diff --git a/src/ntqqapi/ntcall.ts b/src/ntqqapi/ntcall.ts index ea8248b..ee04296 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -136,25 +136,24 @@ export function invoke< R extends Awaited any ? NTService[S][M] : any>>, S extends keyof NTService = any, M extends keyof NTService[S] & string = any ->(method: `${unknown extends `${S}/${M}` ? `${S}/${M}` : string}`, args?: unknown[], options: InvokeOptions = {}) { +>(method: `${unknown extends `${S}/${M}` ? `${S}/${M}` : string}`, args: unknown[], options: InvokeOptions = {}) { const className = options.className ?? NTClass.NT_API const channel = options.channel ?? NTChannel.IPC_UP_2 const timeout = options.timeout ?? 5000 const afterFirstCmd = options.afterFirstCmd ?? true - const uuid = randomUUID() let eventName = className + '-' + channel[channel.length - 1] if (options.classNameIsRegister) { eventName += '-register' } - const apiArgs = [method, ...(args ?? [])] - //log('callNTQQApi', channel, eventName, apiArgs, uuid) - return new Promise((resolve: (data: R) => void, reject) => { + return new Promise((resolve, reject) => { + const apiArgs = [method, ...args] + const callbackId = randomUUID() let success = false if (!options.cbCmd) { // QQ后端会返回结果,并且可以根据uuid识别 - hookApiCallbacks[uuid] = (r: R) => { + hookApiCallbacks[callbackId] = res => { success = true - resolve(r) + resolve(res) } } else { @@ -177,7 +176,7 @@ export function invoke< }) } !afterFirstCmd && secondCallback() - hookApiCallbacks[uuid] = (result: GeneralCallResult) => { + hookApiCallbacks[callbackId] = (result: GeneralCallResult) => { if (result?.result === 0 || result === undefined) { //log(`${params.methodName} callback`, result) afterFirstCmd && secondCallback() @@ -203,7 +202,7 @@ export function invoke< }, }, }, - { type: 'request', callbackId: uuid, eventName }, + { type: 'request', callbackId, eventName }, apiArgs, ) }) diff --git a/src/onebot11/entities.ts b/src/onebot11/entities.ts index 003738e..fb9fad2 100644 --- a/src/onebot11/entities.ts +++ b/src/onebot11/entities.ts @@ -146,34 +146,31 @@ export namespace OB11Entities { message_data['data']['text'] = text } else if (element.replyElement) { - message_data['type'] = OB11MessageDataType.reply + const { replyElement } = element + const peer = { + chatType: msg.chatType, + peerUid: msg.peerUid, + guildId: '' + } try { - const records = msg.records.find(msgRecord => msgRecord.msgId === element.replyElement.sourceMsgIdInRecords) + const records = msg.records.find(msgRecord => msgRecord.msgId === replyElement.sourceMsgIdInRecords) if (!records) throw new Error('找不到回复消息') - let replyMsg = (await ctx.ntMsgApi.getMsgsBySeqAndCount({ - peerUid: msg.peerUid, - guildId: '', - chatType: msg.chatType, - }, element.replyElement.replayMsgSeq, 1, true, true))?.msgList[0] + let replyMsg = (await ctx.ntMsgApi.getMsgsBySeqAndCount(peer, replyElement.replayMsgSeq, 1, true, true)).msgList[0] if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) { - const peer = { - chatType: msg.chatType, - peerUid: msg.peerUid, - guildId: '', - } - replyMsg = (await ctx.ntMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq))?.msgList[0] + replyMsg = (await ctx.ntMsgApi.getSingleMsg(peer, replyElement.replayMsgSeq)).msgList[0] } // 284840486: 合并消息内侧 消息具体定位不到 if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') { throw new Error('回复消息消息验证失败') } - message_data['data']['id'] = replyMsg && MessageUnique.createMsg({ - peerUid: msg.peerUid, - guildId: '', - chatType: msg.chatType, - }, replyMsg.msgId)?.toString() + message_data = { + type: OB11MessageDataType.reply, + data: { + id: MessageUnique.createMsg(peer, replyMsg ? replyMsg.msgId : records.msgId).toString() + } + } } catch (e: any) { - ctx.logger.error('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq) + ctx.logger.error('获取不到引用的消息', replyElement.replayMsgSeq, e.stack) continue } } From 2637a5da6de9fcf57816223c6370e86562c9fd30 Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 31 Aug 2024 22:59:42 +0800 Subject: [PATCH 5/6] chore --- src/global.d.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/global.d.ts b/src/global.d.ts index d378e52..dfe6aa2 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -2,9 +2,6 @@ import type { LLOneBot } from './preload' import { Dict } from 'cosmokit' declare global { - interface Window { - llonebot: LLOneBot - LiteLoader: Dict - } + var llonebot: LLOneBot var LiteLoader: Dict } \ No newline at end of file From 2dac109e58a0dfa9d75ee0388bc8b75a1ec4d660 Mon Sep 17 00:00:00 2001 From: idranme Date: Sun, 1 Sep 2024 00:34:08 +0800 Subject: [PATCH 6/6] chore: v3.31.3 --- manifest.json | 2 +- src/version.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 5030073..e8f3fb5 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "LLOneBot", "slug": "LLOneBot", "description": "实现 OneBot 11 协议,用于 QQ 机器人开发", - "version": "3.31.2", + "version": "3.31.3", "icon": "./icon.webp", "authors": [ { diff --git a/src/version.ts b/src/version.ts index 16409c1..8178874 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = '3.31.2' +export const version = '3.31.3'