From 40f03e6401626881308e5796d73474d08bdc3e94 Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 10 Aug 2024 21:34:28 +0800 Subject: [PATCH] sync --- src/common/data.ts | 13 +-- src/common/utils/helper.ts | 23 ++++++ src/main/main.ts | 6 -- src/ntqqapi/api/friend.ts | 22 ++++++ src/ntqqapi/api/msg.ts | 8 +- src/ntqqapi/api/user.ts | 47 ++++------- src/ntqqapi/api/webapi.ts | 79 ++++++++----------- src/ntqqapi/hook.ts | 29 +------ .../services/NodeIKernelTicketService.ts | 11 +++ .../services/NodeIKernelTipOffService.ts | 19 +++++ src/ntqqapi/services/index.ts | 4 +- src/ntqqapi/types/msg.ts | 44 +++++++++++ src/ntqqapi/wrapper.ts | 6 +- src/onebot11/action/user/GetCookie.ts | 16 +++- src/onebot11/action/user/GetFriendList.ts | 18 +++-- src/onebot11/constructor.ts | 17 ++-- 16 files changed, 222 insertions(+), 140 deletions(-) create mode 100644 src/ntqqapi/services/NodeIKernelTicketService.ts create mode 100644 src/ntqqapi/services/NodeIKernelTipOffService.ts diff --git a/src/common/data.ts b/src/common/data.ts index 5eaebc2..42186b8 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -1,7 +1,5 @@ import { - CategoryFriend, type Friend, - type FriendRequest, type Group, type GroupMember, type SelfInfo, @@ -11,7 +9,6 @@ import { NTQQGroupApi } from '../ntqqapi/api/group' import { log } from './utils/log' import { isNumeric } from './utils/helper' import { NTQQFriendApi } from '../ntqqapi/api' -import { WebApiGroupMember } from '@/ntqqapi/api/webapi' export const selfInfo: SelfInfo = { uid: '', @@ -19,10 +16,6 @@ export const selfInfo: SelfInfo = { nick: '', online: true, } -export const WebGroupData = { - GroupData: new Map>(), - GroupTime: new Map(), -} export let groups: Group[] = [] export let friends: Friend[] = [] export const llonebotError: LLOneBotError = { @@ -115,8 +108,4 @@ export function getUidByUin(uin: string) { return uid } } -} - -export let tempGroupCodeMap: Record = {} // peerUid => 群号 - -export let rawFriends: CategoryFriend[] = [] \ No newline at end of file +} \ No newline at end of file diff --git a/src/common/utils/helper.ts b/src/common/utils/helper.ts index 1dbbd0a..10388b8 100644 --- a/src/common/utils/helper.ts +++ b/src/common/utils/helper.ts @@ -96,6 +96,29 @@ export function cacheFunc(ttl: number, customKey: string = '') { } } +export function CacheClassFuncAsync(ttl = 3600 * 1000, customKey = '') { + function logExecutionTime(target: any, methodName: string, descriptor: PropertyDescriptor) { + const cache = new Map() + const originalMethod = descriptor.value + descriptor.value = async function (...args: any[]) { + const key = `${customKey}${String(methodName)}.(${args.map(arg => JSON.stringify(arg)).join(', ')})` + cache.forEach((value, key) => { + if (value.expiry < Date.now()) { + cache.delete(key) + } + }) + const cachedValue = cache.get(key) + if (cachedValue && cachedValue.expiry > Date.now()) { + return cachedValue.value + } + const result = await originalMethod.apply(this, args) + cache.set(key, { expiry: Date.now() + ttl, value: result }) + return result + } + } + return logExecutionTime +} + export function CacheClassFuncAsyncExtend(ttl: number = 3600 * 1000, customKey: string = '', checker: any = (...data: any[]) => { return true }) { function logExecutionTime(target: any, methodName: string, descriptor: PropertyDescriptor) { const cache = new Map() diff --git a/src/main/main.ts b/src/main/main.ts index 8cfcc60..33cf743 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -18,7 +18,6 @@ import { getGroupMember, llonebotError, selfInfo, - uidMaps, } from '../common/data' import { hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook, startHook } from '../ntqqapi/hook' import { OB11Constructor } from '../onebot11/constructor' @@ -433,11 +432,6 @@ function onLoad() { } llonebotError.otherError = '' startTime = Date.now() - dbUtil.getReceivedTempUinMap().then((m) => { - for (const [key, value] of Object.entries(m)) { - uidMaps[value] = key - } - }) NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! }) log('start activate group member info') NTQQGroupApi.activateMemberInfoChange().then().catch(log) diff --git a/src/ntqqapi/api/friend.ts b/src/ntqqapi/api/friend.ts index a146b74..48d6f12 100644 --- a/src/ntqqapi/api/friend.ts +++ b/src/ntqqapi/api/friend.ts @@ -96,6 +96,28 @@ export class NTQQFriendApi { return retMap } + static async getBuddyV2ExWithCate(refresh = false) { + const uids: string[] = [] + const categoryMap: Map = new Map() + const session = getSession() + const buddyService = session?.getBuddyService() + const buddyListV2 = refresh ? (await buddyService?.getBuddyListV2('0', BuddyListReqType.KNOMAL))?.data : (await buddyService?.getBuddyListV2('0', BuddyListReqType.KNOMAL))?.data + uids.push( + ...buddyListV2?.flatMap(item => { + item.buddyUids.forEach(uid => { + categoryMap.set(uid, { categoryId: item.categoryId, categroyName: item.categroyName }) + }) + return item.buddyUids + })!) + const data = await NTEventDispatch.CallNoListenerEvent( + 'NodeIKernelProfileService/getCoreAndBaseInfo', 5000, 'nodeStore', uids + ) + return Array.from(data).map(([key, value]) => { + const category = categoryMap.get(key) + return category ? { ...value, categoryId: category.categoryId, categroyName: category.categroyName } : value + }) + } + static async isBuddy(uid: string): Promise { const session = getSession() return session?.getBuddyService().isBuddy(uid)! diff --git a/src/ntqqapi/api/msg.ts b/src/ntqqapi/api/msg.ts index b35374c..f01de90 100644 --- a/src/ntqqapi/api/msg.ts +++ b/src/ntqqapi/api/msg.ts @@ -1,5 +1,5 @@ import { callNTQQApi, GeneralCallResult, NTQQApiMethod } from '../ntcall' -import { ChatType, RawMessage, SendMessageElement, Peer } from '../types' +import { ChatType, RawMessage, SendMessageElement, Peer, ChatType2 } from '../types' import { dbUtil } from '../../common/db' import { selfInfo } from '../../common/data' import { ReceiveCmdS, registerReceiveHook } from '../hook' @@ -67,6 +67,11 @@ async function sendWaiter(peer: Peer, waitComplete = true, timeout: number = 100 } export class NTQQMsgApi { + static async getTempChatInfo(chatType: ChatType2, peerUid: string) { + const session = getSession() + return session?.getMsgService().getTempChatInfo(chatType, peerUid)! + } + static enterOrExitAIO(peer: Peer, enter: boolean) { return callNTQQApi({ methodName: NTQQApiMethod.ENTER_OR_EXIT_AIO, @@ -85,6 +90,7 @@ export class NTQQMsgApi { ], }) } + static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) { // nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览 // nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index 8630e24..bdc0f3b 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -1,8 +1,8 @@ import { callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod } from '../ntcall' import { SelfInfo, User, UserDetailInfoByUin, UserDetailInfoByUinV2 } from '../types' import { ReceiveCmdS } from '../hook' -import { selfInfo, uidMaps, friends, groupMembers } from '@/common/data' -import { cacheFunc, isQQ998, log, sleep, getBuildVersion } from '@/common/utils' +import { selfInfo, friends, groupMembers } from '@/common/data' +import { CacheClassFuncAsync, isQQ998, log, sleep, getBuildVersion } from '@/common/utils' import { getSession } from '@/ntqqapi/wrapper' import { RequestUtil } from '@/common/utils/request' import { NodeIKernelProfileService, UserDetailSource, ProfileBizType } from '../services' @@ -12,13 +12,6 @@ import { NTQQFriendApi } from './friend' const userInfoCache: Record = {} // uid: User -export interface ClientKeyData extends GeneralCallResult { - url: string - keyIndex: string - clientKey: string - expireTime: string -} - export class NTQQUserApi { static async setQQAvatar(filePath: string) { return await callNTQQApi({ @@ -115,9 +108,6 @@ export class NTQQUserApi { ], }) const info = result.info - if (info?.uin) { - uidMaps[info.uid] = info.uin - } return info } // 首次请求两次才能拿到的等级信息 @@ -165,21 +155,12 @@ export class NTQQUserApi { return (await RequestUtil.HttpsGetCookies(url))?.skey } - @cacheFunc(60 * 30 * 1000) + @CacheClassFuncAsync(1800 * 1000) static async getCookies(domain: string) { - if (domain.endsWith("qzone.qq.com")) { - let data = (await NTQQUserApi.getQzoneCookies()) - const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin - return { bkn: NTQQUserApi.genBkn(data.p_skey), cookies: CookieValue } - } - const skey = await this.getSkey() - const pskey = (await this.getPSkey([domain])).get(domain) - if (!pskey || !skey) { - throw new Error('获取Cookies失败') - } - const bkn = NTQQUserApi.genBkn(skey) - const cookies = `p_skey=${pskey}; skey=${skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}` - return { cookies, bkn } + const ClientKeyData = await NTQQUserApi.forceFetchClientKey() + const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + ClientKeyData.clientKey + '&u1=https%3A%2F%2F' + domain + '%2F' + selfInfo.uin + '%2Finfocenter&keyindex=19%27' + const cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl) + return cookies } static genBkn(sKey: string) { @@ -197,15 +178,15 @@ export class NTQQUserApi { static async getPSkey(domains: string[]): Promise> { const session = getSession() const res = await session?.getTipOffService().getPskey(domains, true) - if (res.result !== 0) { - throw new Error(`获取Pskey失败: ${res.errMsg}`) + if (res?.result !== 0) { + throw new Error(`获取Pskey失败: ${res?.errMsg}`) } return res.domainPskeyMap } - static async getClientKey(): Promise { + static async getClientKey() { const session = getSession() - return await session?.getTicketService().forceFetchClientKey('') + return await session?.getTicketService().forceFetchClientKey('')! } static async like(uid: string, count = 1): Promise<{ result: number, errMsg: string, succCounts: number }> { @@ -336,4 +317,10 @@ export class NTQQUserApi { } return await NTQQUserApi.getUinByUidV1(Uid) } + + @CacheClassFuncAsync(3600 * 1000, 'ClientKey') + static async forceFetchClientKey() { + const session = getSession() + return await session?.getTicketService().forceFetchClientKey('')! + } } diff --git a/src/ntqqapi/api/webapi.ts b/src/ntqqapi/api/webapi.ts index 44c5063..748eb36 100644 --- a/src/ntqqapi/api/webapi.ts +++ b/src/ntqqapi/api/webapi.ts @@ -1,7 +1,8 @@ -import { WebGroupData, groups, selfInfo } from '@/common/data' +import { selfInfo } from '@/common/data' import { log } from '@/common/utils/log' import { NTQQUserApi } from './user' import { RequestUtil } from '@/common/utils/request' +import { CacheClassFuncAsync } from '@/common/utils/helper' export enum WebHonorType { ALL = 'all', @@ -137,56 +138,44 @@ export class WebApi { return ret } + @CacheClassFuncAsync(3600 * 1000, 'webapi_get_group_members') static async getGroupMembers(GroupCode: string, cached: boolean = true): Promise { - log('webapi 获取群成员', GroupCode); - let MemberData: Array = new Array(); + //logDebug('webapi 获取群成员', GroupCode) + let MemberData: Array = new Array() try { - let cachedData = WebGroupData.GroupData.get(GroupCode); - let cachedTime = WebGroupData.GroupTime.get(GroupCode); - - if (!cachedTime || Date.now() - cachedTime > 1800 * 1000 || !cached) { - const _Pskey = (await NTQQUserApi.getPSkey(['qun.qq.com']))['qun.qq.com']; - const _Skey = await NTQQUserApi.getSkey(); - const CookieValue = 'p_skey=' + _Pskey + '; skey=' + _Skey + '; p_uin=o' + selfInfo.uin; - if (!_Skey || !_Pskey) { - return MemberData; - } - const Bkn = WebApi.genBkn(_Skey); - const retList: Promise[] = []; - const fastRet = await RequestUtil.HttpGetJson('https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?st=0&end=40&sort=1&gc=' + GroupCode + '&bkn=' + Bkn, 'POST', '', { 'Cookie': CookieValue }); - if (!fastRet?.count || fastRet?.errcode !== 0 || !fastRet?.mems) { - return []; - } else { - for (const key in fastRet.mems) { - MemberData.push(fastRet.mems[key]); - } - } - //初始化获取PageNum - const PageNum = Math.ceil(fastRet.count / 40); - //遍历批量请求 - for (let i = 2; i <= PageNum; i++) { - const ret: Promise = RequestUtil.HttpGetJson('https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?st=' + (i - 1) * 40 + '&end=' + i * 40 + '&sort=1&gc=' + GroupCode + '&bkn=' + Bkn, 'POST', '', { 'Cookie': CookieValue }); - retList.push(ret); - } - //批量等待 - for (let i = 1; i <= PageNum; i++) { - const ret = await (retList[i]); - if (!ret?.count || ret?.errcode !== 0 || !ret?.mems) { - continue; - } - for (const key in ret.mems) { - MemberData.push(ret.mems[key]); - } - } - WebGroupData.GroupData.set(GroupCode, MemberData); - WebGroupData.GroupTime.set(GroupCode, Date.now()); + const CookiesObject = await NTQQUserApi.getCookies('qun.qq.com') + const CookieValue = Object.entries(CookiesObject).map(([key, value]) => `${key}=${value}`).join('; ') + const Bkn = WebApi.genBkn(CookiesObject.skey) + const retList: Promise[] = [] + const fastRet = await RequestUtil.HttpGetJson('https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?st=0&end=40&sort=1&gc=' + GroupCode + '&bkn=' + Bkn, 'POST', '', { 'Cookie': CookieValue }); + if (!fastRet?.count || fastRet?.errcode !== 0 || !fastRet?.mems) { + return [] } else { - MemberData = cachedData as Array; + for (const key in fastRet.mems) { + MemberData.push(fastRet.mems[key]) + } + } + //初始化获取PageNum + const PageNum = Math.ceil(fastRet.count / 40) + //遍历批量请求 + for (let i = 2; i <= PageNum; i++) { + const ret: Promise = RequestUtil.HttpGetJson('https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?st=' + (i - 1) * 40 + '&end=' + i * 40 + '&sort=1&gc=' + GroupCode + '&bkn=' + Bkn, 'POST', '', { 'Cookie': CookieValue }); + retList.push(ret) + } + //批量等待 + for (let i = 1; i <= PageNum; i++) { + const ret = await (retList[i]) + if (!ret?.count || ret?.errcode !== 0 || !ret?.mems) { + continue + } + for (const key in ret.mems) { + MemberData.push(ret.mems[key]) + } } } catch { - return MemberData; + return MemberData } - return MemberData; + return MemberData } // public static async addGroupDigest(groupCode: string, msgSeq: string) { // const url = `https://qun.qq.com/cgi-bin/group_digest/cancel_digest?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&msg_seq=${msgSeq}&msg_random=444021292`; diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts index b8d651d..b9eea90 100644 --- a/src/ntqqapi/hook.ts +++ b/src/ntqqapi/hook.ts @@ -1,16 +1,14 @@ import type { BrowserWindow } from 'electron' import { NTQQApiClass, NTQQApiMethod } from './ntcall' import { NTQQMsgApi, sendMessagePool } from './api/msg' -import { CategoryFriend, ChatType, Group, GroupMember, GroupMemberRole, RawMessage, User } from './types' +import { CategoryFriend, ChatType, Group, GroupMember, GroupMemberRole, RawMessage } from './types' import { deleteGroup, friends, getFriend, getGroupMember, - groups, rawFriends, + groups, selfInfo, - tempGroupCodeMap, - uidMaps, } from '@/common/data' import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent' import { postOb11Event } from '../onebot11/server/post-ob11-event' @@ -402,8 +400,6 @@ export async function startHook() { registerReceiveHook<{ data: CategoryFriend[] }>(ReceiveCmdS.FRIENDS, (payload) => { - rawFriends.length = 0; - rawFriends.push(...payload.data); for (const fData of payload.data) { const _friends = fData.buddyList for (let friend of _friends) { @@ -420,23 +416,6 @@ export async function startHook() { }) registerReceiveHook<{ msgList: Array }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => { - // 保存一下uid - for (const message of payload.msgList) { - const uid = message.senderUid - const uin = message.senderUin - if (uid && uin) { - if (message.chatType === ChatType.temp) { - dbUtil.getReceivedTempUinMap().then((receivedTempUinMap) => { - if (!receivedTempUinMap[uin]) { - receivedTempUinMap[uin] = uid - dbUtil.setReceivedTempUinMap(receivedTempUinMap) - } - }) - } - uidMaps[uid] = uin - } - } - // 自动清理新消息文件 const { autoDeleteFile } = getConfigUtil().getConfig() if (!autoDeleteFile) { @@ -459,10 +438,6 @@ export async function startHook() { if (msgElement.picElement) { pathList.push(...Object.values(msgElement.picElement.thumbPath)) } - const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement - if (aioOpGrayTipElement) { - tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat - } // log("需要清理的文件", pathList); for (const path of pathList) { diff --git a/src/ntqqapi/services/NodeIKernelTicketService.ts b/src/ntqqapi/services/NodeIKernelTicketService.ts new file mode 100644 index 0000000..f1ab0e5 --- /dev/null +++ b/src/ntqqapi/services/NodeIKernelTicketService.ts @@ -0,0 +1,11 @@ +import { forceFetchClientKeyRetType } from './common' + +export interface NodeIKernelTicketService { + addKernelTicketListener(listener: unknown): void + + removeKernelTicketListener(listenerId: unknown): void + + forceFetchClientKey(arg: string): Promise + + isNull(): boolean +} \ No newline at end of file diff --git a/src/ntqqapi/services/NodeIKernelTipOffService.ts b/src/ntqqapi/services/NodeIKernelTipOffService.ts new file mode 100644 index 0000000..62f87ce --- /dev/null +++ b/src/ntqqapi/services/NodeIKernelTipOffService.ts @@ -0,0 +1,19 @@ +import { GeneralCallResult } from './common' + +export interface NodeIKernelTipOffService { + addKernelTipOffListener(listener: unknown): void + + removeKernelTipOffListener(listenerId: unknown): void + + tipOffSendJsData(args: unknown[]): Promise //2 + + getPskey(domainList: string[], nocache: boolean): Promise }> //2 + + tipOffSendJsData(args: unknown[]): Promise //2 + + tipOffMsgs(args: unknown[]): Promise //1 + + encodeUinAesInfo(args: unknown[]): Promise //2 + + isNull(): boolean +} \ No newline at end of file diff --git a/src/ntqqapi/services/index.ts b/src/ntqqapi/services/index.ts index 0fa9633..8d518da 100644 --- a/src/ntqqapi/services/index.ts +++ b/src/ntqqapi/services/index.ts @@ -5,4 +5,6 @@ export * from './NodeIKernelProfileLikeService' export * from './NodeIKernelMsgService' export * from './NodeIKernelMSFService' export * from './NodeIKernelUixConvertService' -export * from './NodeIKernelRichMediaService' \ No newline at end of file +export * from './NodeIKernelRichMediaService' +export * from './NodeIKernelTicketService' +export * from './NodeIKernelTipOffService' \ No newline at end of file diff --git a/src/ntqqapi/types/msg.ts b/src/ntqqapi/types/msg.ts index 540aa88..397c897 100644 --- a/src/ntqqapi/types/msg.ts +++ b/src/ntqqapi/types/msg.ts @@ -190,6 +190,50 @@ export enum ChatType { temp = 100, } +// 来自Android分析 +export enum ChatType2 { + KCHATTYPEADELIE = 42, + KCHATTYPEBUDDYNOTIFY = 5, + KCHATTYPEC2C = 1, + KCHATTYPECIRCLE = 113, + KCHATTYPEDATALINE = 8, + KCHATTYPEDATALINEMQQ = 134, + KCHATTYPEDISC = 3, + KCHATTYPEFAV = 41, + KCHATTYPEGAMEMESSAGE = 105, + KCHATTYPEGAMEMESSAGEFOLDER = 116, + KCHATTYPEGROUP = 2, + KCHATTYPEGROUPBLESS = 133, + KCHATTYPEGROUPGUILD = 9, + KCHATTYPEGROUPHELPER = 7, + KCHATTYPEGROUPNOTIFY = 6, + KCHATTYPEGUILD = 4, + KCHATTYPEGUILDMETA = 16, + KCHATTYPEMATCHFRIEND = 104, + KCHATTYPEMATCHFRIENDFOLDER = 109, + KCHATTYPENEARBY = 106, + KCHATTYPENEARBYASSISTANT = 107, + KCHATTYPENEARBYFOLDER = 110, + KCHATTYPENEARBYHELLOFOLDER = 112, + KCHATTYPENEARBYINTERACT = 108, + KCHATTYPEQQNOTIFY = 132, + KCHATTYPERELATEACCOUNT = 131, + KCHATTYPESERVICEASSISTANT = 118, + KCHATTYPESERVICEASSISTANTSUB = 201, + KCHATTYPESQUAREPUBLIC = 115, + KCHATTYPESUBSCRIBEFOLDER = 30, + KCHATTYPETEMPADDRESSBOOK = 111, + KCHATTYPETEMPBUSSINESSCRM = 102, + KCHATTYPETEMPC2CFROMGROUP = 100, + KCHATTYPETEMPC2CFROMUNKNOWN = 99, + KCHATTYPETEMPFRIENDVERIFY = 101, + KCHATTYPETEMPNEARBYPRO = 119, + KCHATTYPETEMPPUBLICACCOUNT = 103, + KCHATTYPETEMPWPA = 117, + KCHATTYPEUNKNOWN = 0, + KCHATTYPEWEIYUN = 40, +} + export interface PttElement { canConvert2Text: boolean duration: number // 秒数 diff --git a/src/ntqqapi/wrapper.ts b/src/ntqqapi/wrapper.ts index 726a4e1..a96fcaa 100644 --- a/src/ntqqapi/wrapper.ts +++ b/src/ntqqapi/wrapper.ts @@ -6,7 +6,9 @@ import { NodeIKernelMSFService, NodeIKernelMsgService, NodeIKernelUixConvertService, - NodeIKernelRichMediaService + NodeIKernelRichMediaService, + NodeIKernelTicketService, + NodeIKernelTipOffService } from './services' import os from 'node:os' const Process = require('node:process') @@ -21,6 +23,8 @@ export interface NodeIQQNTWrapperSession { getMSFService(): NodeIKernelMSFService getUixConvertService(): NodeIKernelUixConvertService getRichMediaService(): NodeIKernelRichMediaService + getTicketService(): NodeIKernelTicketService + getTipOffService(): NodeIKernelTipOffService } export interface WrapperApi { diff --git a/src/onebot11/action/user/GetCookie.ts b/src/onebot11/action/user/GetCookie.ts index 55b4115..968759c 100644 --- a/src/onebot11/action/user/GetCookie.ts +++ b/src/onebot11/action/user/GetCookie.ts @@ -1,16 +1,24 @@ import BaseAction from '../BaseAction' -import { NTQQUserApi } from '@/ntqqapi/api' +import { NTQQUserApi, WebApi } from '@/ntqqapi/api' import { ActionName } from '../types' +interface Response { + cookies: string + bkn: string +} + interface Payload { domain: string } -export class GetCookies extends BaseAction { +export class GetCookies extends BaseAction { actionName = ActionName.GetCookies protected async _handle(payload: Payload) { - const domain = payload.domain || 'qun.qq.com' - return NTQQUserApi.getCookies(domain); + const cookiesObject = await NTQQUserApi.getCookies(payload.domain) + //把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起 + const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ') + const bkn = WebApi.genBkn(cookiesObject.p_skey) + return { cookies, bkn } } } diff --git a/src/onebot11/action/user/GetFriendList.ts b/src/onebot11/action/user/GetFriendList.ts index bab6ea2..99fa97c 100644 --- a/src/onebot11/action/user/GetFriendList.ts +++ b/src/onebot11/action/user/GetFriendList.ts @@ -1,11 +1,10 @@ import { OB11User } from '../../types' import { OB11Constructor } from '../../constructor' -import { friends, rawFriends } from '@/common/data' +import { friends } from '@/common/data' import BaseAction from '../BaseAction' import { ActionName } from '../types' import { NTQQFriendApi } from '@/ntqqapi/api' -import { CategoryFriend } from '@/ntqqapi/types' -import { qqPkgInfo } from '@/common/utils/QQBasicInfo' +import { getBuildVersion } from '@/common/utils/QQBasicInfo' interface Payload { no_cache: boolean | string @@ -15,7 +14,7 @@ export class GetFriendList extends BaseAction { actionName = ActionName.GetFriendList protected async _handle(payload: Payload) { - if (+qqPkgInfo.buildVersion >= 26702) { + if (getBuildVersion() >= 26702) { return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true')) } if (friends.length === 0 || payload?.no_cache === true || payload?.no_cache === 'true') { @@ -30,11 +29,16 @@ export class GetFriendList extends BaseAction { } } - -export class GetFriendWithCategory extends BaseAction> { +// extend +export class GetFriendWithCategory extends BaseAction { actionName = ActionName.GetFriendsWithCategory; protected async _handle(payload: void) { - return rawFriends; + if (getBuildVersion() >= 26702) { + //全新逻辑 + return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2ExWithCate(true)) + } else { + throw new Error('this ntqq version not support, must be 26702 or later') + } } } \ No newline at end of file diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index e29ff36..590fbea 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -24,9 +24,10 @@ import { TipGroupElementType, User, VideoElement, - FriendV2 + FriendV2, + ChatType2 } from '../ntqqapi/types' -import { deleteGroup, getGroupMember, selfInfo, tempGroupCodeMap, uidMaps } from '../common/data' +import { deleteGroup, getGroupMember, selfInfo, uidMaps } from '../common/data' import { EventType } from './event/OB11BaseEvent' import { encodeCQCode } from './cqcode' import { dbUtil } from '../common/db' @@ -95,11 +96,15 @@ export class OB11Constructor { resMsg.sub_type = 'friend' resMsg.sender.nickname = (await NTQQUserApi.getUserDetailInfo(msg.senderUid)).nick } - else if (msg.chatType == ChatType.temp) { + else if (msg.chatType as unknown as ChatType2 == ChatType2.KCHATTYPETEMPC2CFROMGROUP) { resMsg.sub_type = 'group' - const tempGroupCode = tempGroupCodeMap[msg.peerUin] - if (tempGroupCode) { - resMsg.group_id = parseInt(tempGroupCode) + const ret = await NTQQMsgApi.getTempChatInfo(ChatType2.KCHATTYPETEMPC2CFROMGROUP, msg.senderUid) + if (ret.result === 0) { + resMsg.group_id = parseInt(ret.tmpChatInfo!.groupCode) + resMsg.sender.nickname = ret.tmpChatInfo!.fromNick + } else { + resMsg.group_id = 284840486 //兜底数据 + resMsg.sender.nickname = '临时会话' } }