diff --git a/src/common/utils/audio.ts b/src/common/utils/audio.ts index c11c30f..919766b 100644 --- a/src/common/utils/audio.ts +++ b/src/common/utils/audio.ts @@ -16,8 +16,8 @@ type Input = string | Readable function convert(ctx: Context, input: Input, options: FFmpegOptions): Promise function convert(ctx: Context, input: Input, options: FFmpegOptions, outputPath: string): Promise -function convert(ctx: Context, input: Input, options: FFmpegOptions, outputPath?: string): Promise | Promise { - return new Promise((resolve, reject) => { +function convert(ctx: Context, input: Input, options: FFmpegOptions, outputPath?: string): Promise { + return new Promise((resolve, reject) => { const chunks: Buffer[] = [] let command = ffmpeg(input) .on('error', err => { @@ -84,8 +84,8 @@ export async function encodeSilk(ctx: Context, filePath: string) { let duration = 1 try { duration = getDuration(silk) / 1000 - } catch (e: any) { - ctx.logger.warn('获取语音文件时长失败, 默认为1秒', filePath, e.stack) + } catch (e) { + ctx.logger.warn('获取语音文件时长失败, 默认为1秒', filePath, (e as Error).stack) } return { converted: false, @@ -93,8 +93,8 @@ export async function encodeSilk(ctx: Context, filePath: string) { duration, } } - } catch (error: any) { - ctx.logger.error('convert silk failed', error.stack) + } catch (err) { + ctx.logger.error('convert silk failed', (err as Error).stack) return {} } } diff --git a/src/common/utils/eventTask.ts b/src/common/utils/eventTask.ts index a7279fe..2c84e03 100644 --- a/src/common/utils/eventTask.ts +++ b/src/common/utils/eventTask.ts @@ -4,8 +4,8 @@ import { randomUUID } from 'node:crypto' interface Internal_MapKey { timeout: number createtime: number - func: (...arg: any[]) => any - checker: ((...args: any[]) => boolean) | undefined + func: (...arg: any[]) => unknown + checker?: (...args: any[]) => boolean } export class ListenerClassBase { @@ -13,7 +13,7 @@ export class ListenerClassBase { } export interface ListenerIBase { - new(listener: any): ListenerClassBase + new(listener: unknown): ListenerClassBase } // forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/common/utils/EventTask.ts#L20 @@ -30,11 +30,11 @@ export class NTEventWrapper { createProxyDispatch(ListenerMainName: string) { const current = this return new Proxy({}, { - get(target: any, prop: any, receiver: any) { + get(target: any, prop: string, receiver: unknown) { // console.log('get', prop, typeof target[prop]) if (typeof target[prop] === 'undefined') { // 如果方法不存在,返回一个函数,这个函数调用existentMethod - return (...args: any[]) => { + return (...args: unknown[]) => { current.dispatcherListener.apply(current, [ListenerMainName, prop, ...args]).then() } } @@ -50,7 +50,7 @@ export class NTEventWrapper { this.initialised = true } - createEventFunction any>(eventName: string): T | undefined { + createEventFunction unknown>(eventName: string): T | undefined { const eventNameArr = eventName.split('/') type eventType = { [key: string]: () => { [key: string]: (...params: Parameters) => Promise> } @@ -87,7 +87,7 @@ export class NTEventWrapper { } //统一回调清理事件 - async dispatcherListener(ListenerMainName: string, ListenerSubName: string, ...args: any[]) { + async dispatcherListener(ListenerMainName: string, ListenerSubName: string, ...args: unknown[]) { //console.log("[EventDispatcher]",ListenerMainName, ListenerSubName, ...args) this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.forEach((task, uuid) => { //console.log(task.func, uuid, task.createtime, task.timeout) @@ -101,7 +101,7 @@ export class NTEventWrapper { }) } - async CallNoListenerEvent Promise | any>(EventName = '', timeout: number = 3000, ...args: Parameters) { + async CallNoListenerEvent Promise>(EventName = '', timeout: number = 3000, ...args: Parameters) { return new Promise>>(async (resolve, reject) => { const EventFunc = this.createEventFunction(EventName) let complete = false @@ -162,7 +162,7 @@ export class NTEventWrapper { const id = randomUUID() let complete = 0 let retData: Parameters | undefined = undefined - let retEvent: any = {} + let retEvent = {} const databack = () => { if (complete == 0) { reject(new Error('Timeout: NTEvent EventName:' + EventName + ' ListenerName:' + ListenerName + ' EventRet:\n' + JSON.stringify(retEvent, null, 4) + '\n')) @@ -181,7 +181,7 @@ export class NTEventWrapper { timeout: timeout, createtime: Date.now(), checker: checker, - func: (...args: any[]) => { + func: (...args: unknown[]) => { complete++ //console.log('func', ...args) retData = args as Parameters @@ -200,7 +200,7 @@ export class NTEventWrapper { this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.set(id, eventCallbak) this.createListenerFunction(ListenerMainName) const EventFunc = this.createEventFunction(EventName) - retEvent = await EventFunc!(...(args as any[])) + retEvent = await EventFunc!(...args) }) } } diff --git a/src/common/utils/request.ts b/src/common/utils/request.ts index 164b057..0b734f2 100644 --- a/src/common/utils/request.ts +++ b/src/common/utils/request.ts @@ -1,106 +1,104 @@ import https from 'node:https' import http from 'node:http' +import { Dict } from 'cosmokit' export class RequestUtil { // 适用于获取服务器下发cookies时获取,仅GET static async HttpsGetCookies(url: string): Promise<{ [key: string]: string }> { - const client = url.startsWith('https') ? https : http; + const client = url.startsWith('https') ? https : http return new Promise((resolve, reject) => { client.get(url, (res) => { - let cookies: { [key: string]: string } = {}; + let cookies: { [key: string]: string } = {} const handleRedirect = (res: http.IncomingMessage) => { - //console.log(res.headers.location); if (res.statusCode === 301 || res.statusCode === 302) { if (res.headers.location) { - const redirectUrl = new URL(res.headers.location, url); + const redirectUrl = new URL(res.headers.location, url) RequestUtil.HttpsGetCookies(redirectUrl.href).then((redirectCookies) => { // 合并重定向过程中的cookies //log('redirectCookies', redirectCookies) - cookies = { ...cookies, ...redirectCookies }; - resolve(cookies); - }); + cookies = { ...cookies, ...redirectCookies } + resolve(cookies) + }) } else { - resolve(cookies); + resolve(cookies) } } else { - resolve(cookies); + resolve(cookies) } - }; - res.on('data', () => { }); // Necessary to consume the stream + } + res.on('data', () => { }) // Necessary to consume the stream res.on('end', () => { - handleRedirect(res); - }); + handleRedirect(res) + }) if (res.headers['set-cookie']) { - // console.log(res.headers['set-cookie']); - //log('set-cookie', url, res.headers['set-cookie']); + //log('set-cookie', url, res.headers['set-cookie']) res.headers['set-cookie'].forEach((cookie) => { - const parts = cookie.split(';')[0].split('='); - const key = parts[0]; - const value = parts[1]; + const parts = cookie.split(';')[0].split('=') + const key = parts[0] + const value = parts[1] if (key && value && key.length > 0 && value.length > 0) { - cookies[key] = value; + cookies[key] = value } - }); + }) } }).on('error', (err) => { - reject(err); - }); - }); + reject(err) + }) + }) } // 请求和回复都是JSON data传原始内容 自动编码json - static async HttpGetJson(url: string, method: string = 'GET', data?: any, headers: Record = {}, isJsonRet: boolean = true, isArgJson: boolean = true): Promise { - let option = new URL(url); - const protocol = url.startsWith('https://') ? https : http; + static async HttpGetJson(url: string, method: string = 'GET', data?: unknown, headers: Record = {}, isJsonRet: boolean = true, isArgJson: boolean = true): Promise { + const option = new URL(url) + const protocol = url.startsWith('https://') ? https : http const options = { hostname: option.hostname, port: option.port, path: option.href, method: method, headers: headers - }; + } return new Promise((resolve, reject) => { - const req = protocol.request(options, (res: any) => { - let responseBody = ''; + const req = protocol.request(options, (res: Dict) => { + let responseBody = '' res.on('data', (chunk: string | Buffer) => { - responseBody += chunk.toString(); - }); + responseBody += chunk.toString() + }) res.on('end', () => { try { if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) { if (isJsonRet) { - const responseJson = JSON.parse(responseBody); - resolve(responseJson as T); + const responseJson = JSON.parse(responseBody) + resolve(responseJson as T) } else { - resolve(responseBody as T); + resolve(responseBody as T) } } else { - reject(new Error(`Unexpected status code: ${res.statusCode}`)); + reject(new Error(`Unexpected status code: ${res.statusCode}`)) } } catch (parseError) { - reject(parseError); + reject(parseError) } - }); - }); + }) + }) - req.on('error', (error: any) => { - reject(error); - }); + req.on('error', (error) => { + reject(error) + }) if (method === 'POST' || method === 'PUT' || method === 'PATCH') { if (isArgJson) { - req.write(JSON.stringify(data)); + req.write(JSON.stringify(data)) } else { - req.write(data); + req.write(data) } - } - req.end(); - }); + req.end() + }) } // 请求返回都是原始内容 - static async HttpGetText(url: string, method: string = 'GET', data?: any, headers: Record = {}) { - return this.HttpGetJson(url, method, data, headers, false, false); + static async HttpGetText(url: string, method: string = 'GET', data?: unknown, headers: Record = {}) { + return this.HttpGetJson(url, method, data, headers, false, false) } } \ No newline at end of file diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index a655214..949e171 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -4,8 +4,7 @@ import { invoke, NTClass, NTMethod } from '../ntcall' import { GeneralCallResult } from '../services' import { NTQQWindows } from './window' import { getSession } from '../wrapper' -import { NTEventDispatch } from '@/common/utils/eventTask' -import { NodeIKernelGroupListener, OnGroupFileInfoUpdateParams } from '../listeners' +import { OnGroupFileInfoUpdateParams } from '../listeners' import { NodeIKernelGroupService } from '../services' import { Service, Context } from 'cordis' import { isNumeric } from '@/common/utils/misc' diff --git a/src/ntqqapi/api/msg.ts b/src/ntqqapi/api/msg.ts index 95da82f..f19a693 100644 --- a/src/ntqqapi/api/msg.ts +++ b/src/ntqqapi/api/msg.ts @@ -2,7 +2,6 @@ import { invoke, NTMethod } from '../ntcall' import { GeneralCallResult } from '../services' import { RawMessage, SendMessageElement, Peer, ChatType2 } from '../types' import { getSession } from '@/ntqqapi/wrapper' -import { NTEventDispatch } from '@/common/utils/eventTask' import { Service, Context } from 'cordis' import { selfInfo } from '@/common/globalVars' diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index 57401d8..52cb1f5 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -1,11 +1,9 @@ -import { invoke, NTMethod } from '../ntcall' +import { invoke } from '../ntcall' import { User, UserDetailInfoByUin, UserDetailInfoByUinV2, UserDetailInfoListenerArg } from '../types' import { getBuildVersion } from '@/common/utils' import { getSession } from '@/ntqqapi/wrapper' import { RequestUtil } from '@/common/utils/request' -import { NodeIKernelProfileService, UserDetailSource, ProfileBizType } from '../services' -import { NodeIKernelProfileListener } from '../listeners' -import { NTEventDispatch } from '@/common/utils/eventTask' +import { UserDetailSource, ProfileBizType } from '../services' import { Time } from 'cosmokit' import { Service, Context } from 'cordis' import { selfInfo } from '@/common/globalVars' diff --git a/src/ntqqapi/listeners/NodeIKernelGroupListener.ts b/src/ntqqapi/listeners/NodeIKernelGroupListener.ts index bd302d0..873265f 100644 --- a/src/ntqqapi/listeners/NodeIKernelGroupListener.ts +++ b/src/ntqqapi/listeners/NodeIKernelGroupListener.ts @@ -52,6 +52,7 @@ interface IGroupListener { onJoinGroupNoVerifyFlag(...args: unknown[]): void onGroupArkInviteStateResult(...args: unknown[]): void + // 发现于Win 9.9.9 23159 onGroupMemberLevelInfoChange(...args: unknown[]): void } @@ -59,182 +60,4 @@ interface IGroupListener { export interface NodeIKernelGroupListener extends IGroupListener { // eslint-disable-next-line @typescript-eslint/no-misused-new new(listener: IGroupListener): NodeIKernelGroupListener -} - -export class GroupListener implements IGroupListener { - // 发现于Win 9.9.9 23159 - onGroupMemberLevelInfoChange(...args: unknown[]): void { - - } - onGetGroupBulletinListResult(...args: unknown[]) { - } - - onGroupAllInfoChange(...args: unknown[]) { - } - - onGroupBulletinChange(...args: unknown[]) { - } - - onGroupBulletinRemindNotify(...args: unknown[]) { - } - - onGroupArkInviteStateResult(...args: unknown[]) { - } - - onGroupBulletinRichMediaDownloadComplete(...args: unknown[]) { - } - - onGroupConfMemberChange(...args: unknown[]) { - } - - onGroupDetailInfoChange(...args: unknown[]) { - } - - onGroupExtListUpdate(...args: unknown[]) { - } - - onGroupFirstBulletinNotify(...args: unknown[]) { - } - - onGroupListUpdate(updateType: GroupListUpdateType, groupList: Group[]) { - } - - onGroupNotifiesUpdated(dboubt: boolean, notifies: GroupNotify[]) { - } - - onGroupBulletinRichMediaProgressUpdate(...args: unknown[]) { - } - - onGroupNotifiesUnreadCountUpdated(...args: unknown[]) { - } - - onGroupSingleScreenNotifies(doubt: boolean, seq: string, notifies: GroupNotify[]) { - } - - onGroupsMsgMaskResult(...args: unknown[]) { - } - - onGroupStatisticInfoChange(...args: unknown[]) { - } - - onJoinGroupNotify(...args: unknown[]) { - } - - onJoinGroupNoVerifyFlag(...args: unknown[]) { - } - - onMemberInfoChange(groupCode: string, changeType: number, members: Map) { - } - - onMemberListChange(arg: { - sceneId: string, - ids: string[], - infos: Map, // uid -> GroupMember - finish: boolean, - hasRobot: boolean - }) { - } - - onSearchMemberChange(...args: unknown[]) { - } - - onShutUpMemberListChanged(...args: unknown[]) { - } -} - -export class DebugGroupListener implements IGroupListener { - onGroupMemberLevelInfoChange(...args: unknown[]): void { - console.log('onGroupMemberLevelInfoChange:', ...args) - } - onGetGroupBulletinListResult(...args: unknown[]) { - console.log('onGetGroupBulletinListResult:', ...args) - } - - onGroupAllInfoChange(...args: unknown[]) { - console.log('onGroupAllInfoChange:', ...args) - } - - onGroupBulletinChange(...args: unknown[]) { - console.log('onGroupBulletinChange:', ...args) - } - - onGroupBulletinRemindNotify(...args: unknown[]) { - console.log('onGroupBulletinRemindNotify:', ...args) - } - - onGroupArkInviteStateResult(...args: unknown[]) { - console.log('onGroupArkInviteStateResult:', ...args) - } - - onGroupBulletinRichMediaDownloadComplete(...args: unknown[]) { - console.log('onGroupBulletinRichMediaDownloadComplete:', ...args) - } - - onGroupConfMemberChange(...args: unknown[]) { - console.log('onGroupConfMemberChange:', ...args) - } - - onGroupDetailInfoChange(...args: unknown[]) { - console.log('onGroupDetailInfoChange:', ...args) - } - - onGroupExtListUpdate(...args: unknown[]) { - console.log('onGroupExtListUpdate:', ...args) - } - - onGroupFirstBulletinNotify(...args: unknown[]) { - console.log('onGroupFirstBulletinNotify:', ...args) - } - - onGroupListUpdate(...args: unknown[]) { - console.log('onGroupListUpdate:', ...args) - } - - onGroupNotifiesUpdated(...args: unknown[]) { - console.log('onGroupNotifiesUpdated:', ...args) - } - - onGroupBulletinRichMediaProgressUpdate(...args: unknown[]) { - console.log('onGroupBulletinRichMediaProgressUpdate:', ...args) - } - - onGroupNotifiesUnreadCountUpdated(...args: unknown[]) { - console.log('onGroupNotifiesUnreadCountUpdated:', ...args) - } - - onGroupSingleScreenNotifies(doubt: boolean, seq: string, notifies: GroupNotify[]) { - console.log('onGroupSingleScreenNotifies:') - } - - onGroupsMsgMaskResult(...args: unknown[]) { - console.log('onGroupsMsgMaskResult:', ...args) - } - - onGroupStatisticInfoChange(...args: unknown[]) { - console.log('onGroupStatisticInfoChange:', ...args) - } - - onJoinGroupNotify(...args: unknown[]) { - console.log('onJoinGroupNotify:', ...args) - } - - onJoinGroupNoVerifyFlag(...args: unknown[]) { - console.log('onJoinGroupNoVerifyFlag:', ...args) - } - - onMemberInfoChange(groupCode: string, changeType: number, members: Map) { - console.log('onMemberInfoChange:', groupCode, changeType, members) - } - - onMemberListChange(...args: unknown[]) { - console.log('onMemberListChange:', ...args) - } - - onSearchMemberChange(...args: unknown[]) { - console.log('onSearchMemberChange:', ...args) - } - - onShutUpMemberListChanged(...args: unknown[]) { - console.log('onShutUpMemberListChanged:', ...args) - } } \ No newline at end of file diff --git a/src/ntqqapi/services/NodeIKernelGroupService.ts b/src/ntqqapi/services/NodeIKernelGroupService.ts index 801bd50..f8c5449 100644 --- a/src/ntqqapi/services/NodeIKernelGroupService.ts +++ b/src/ntqqapi/services/NodeIKernelGroupService.ts @@ -7,8 +7,7 @@ import { GroupRequestOperateTypes, } from '@/ntqqapi/types' import { GeneralCallResult } from './common' - -//高版本的接口不应该随意使用 使用应该严格进行pr审核 同时部分ipc中未出现的接口不要过于依赖 应该做好数据兜底 +import { Dict } from 'cosmokit' export interface NodeIKernelGroupService { getMemberCommonInfo(Req: { @@ -29,8 +28,10 @@ export interface NodeIKernelGroupService { onlineFlag: string, realSpecialTitleFlag: number }): Promise + //26702 getGroupMemberLevelInfo(groupCode: string): Promise + //26702 getGroupHonorList(groupCodes: Array): unknown @@ -45,6 +46,7 @@ export interface NodeIKernelGroupService { errMsg: string, uids: Map }> + //26702(其实更早 但是我不知道) checkGroupMemberCache(arrayList: Array): Promise @@ -70,12 +72,16 @@ export interface NodeIKernelGroupService { brief: string } }): Promise + //26702(其实更早 但是我不知道) isEssenceMsg(Req: { groupCode: string, msgRandom: number, msgSeq: number }): Promise + //26702(其实更早 但是我不知道) queryCachedEssenceMsg(Req: { groupCode: string, msgRandom: number, msgSeq: number }): Promise + //26702(其实更早 但是我不知道) fetchGroupEssenceList(Req: { groupCode: string, pageStart: number, pageLimit: number }, Arg: unknown): Promise + //26702 getAllMemberList(groupCode: string, forceFetch: boolean): Promise<{ errCode: number, @@ -85,7 +91,7 @@ export interface NodeIKernelGroupService { uid: string, index: number//0 }>, - infos: {}, + infos: Dict, finish: true, hasRobot: false } @@ -171,7 +177,7 @@ export interface NodeIKernelGroupService { clearGroupNotifies(groupCode: string): void - getGroupNotifiesUnreadCount(unknown: Boolean): Promise + getGroupNotifiesUnreadCount(unknown: boolean): Promise clearGroupNotifiesUnreadCount(groupCode: string): void @@ -193,7 +199,7 @@ export interface NodeIKernelGroupService { deleteGroupBulletin(groupCode: string, seq: string): void - publishGroupBulletin(groupCode: string, pskey: string, data: any): Promise + publishGroupBulletin(groupCode: string, pskey: string, data: unknown): Promise publishInstructionForNewcomers(groupCode: string, arg: unknown): void diff --git a/src/ntqqapi/services/NodeIKernelMsgService.ts b/src/ntqqapi/services/NodeIKernelMsgService.ts index 1b9d75e..bb0f92c 100644 --- a/src/ntqqapi/services/NodeIKernelMsgService.ts +++ b/src/ntqqapi/services/NodeIKernelMsgService.ts @@ -30,7 +30,6 @@ export interface TmpChatInfo { } export interface NodeIKernelMsgService { - generateMsgUniqueId(chatType: number, time: string): string addKernelMsgListener(nodeIKernelMsgListener: NodeIKernelMsgListener): number diff --git a/src/ntqqapi/services/NodeIKernelRichMediaService.ts b/src/ntqqapi/services/NodeIKernelRichMediaService.ts index 1dfa8e5..b16ab18 100644 --- a/src/ntqqapi/services/NodeIKernelRichMediaService.ts +++ b/src/ntqqapi/services/NodeIKernelRichMediaService.ts @@ -169,7 +169,7 @@ export interface NodeIKernelRichMediaService { downloadFileForFileInfo(fileInfo: CommonFileInfo[], savePath: string): unknown - createGroupFolder(GroupCode: string, FolderName: string): Promise } }> + createGroupFolder(GroupCode: string, FolderName: string): Promise } }> downloadFile(commonFile: CommonFileInfo, arg2: unknown, arg3: unknown, savePath: string): unknown @@ -222,9 +222,9 @@ export interface NodeIKernelRichMediaService { deleteGroupFile(GroupCode: string, params: Array, Files: Array): Promise - failFileIdList: Array + result: unknown + successFileIdList: Array + failFileIdList: Array } }> diff --git a/src/ntqqapi/types/user.ts b/src/ntqqapi/types/user.ts index d899bc8..2ba6212 100644 --- a/src/ntqqapi/types/user.ts +++ b/src/ntqqapi/types/user.ts @@ -241,7 +241,7 @@ interface CommonExt { address: string regTime: number interest: string - labels: unknown[] + labels: string[] qqLevel: QQLevel } diff --git a/src/ntqqapi/wrapper.ts b/src/ntqqapi/wrapper.ts index 727c2db..9250c9b 100644 --- a/src/ntqqapi/wrapper.ts +++ b/src/ntqqapi/wrapper.ts @@ -16,7 +16,6 @@ import { Dict } from 'cosmokit' const Process = require('node:process') export interface NodeIQQNTWrapperSession { - [key: string]: any getBuddyService(): NodeIKernelBuddyService getGroupService(): NodeIKernelGroupService getProfileService(): NodeIKernelProfileService @@ -36,19 +35,6 @@ export interface WrapperApi { export interface WrapperConstructor { [key: string]: any - NodeIKernelBuddyListener?: any - NodeIKernelGroupListener?: any - NodeQQNTWrapperUtil?: any - NodeIKernelMsgListener?: any - NodeIQQNTWrapperEngine?: any - NodeIGlobalAdapter?: any - NodeIDependsAdapter?: any - NodeIDispatcherAdapter?: any - NodeIKernelSessionListener?: any - NodeIKernelLoginService?: any - NodeIKernelLoginListener?: any - NodeIKernelProfileService?: any - NodeIKernelProfileListener?: any } const wrapperApi: WrapperApi = {} @@ -75,9 +61,9 @@ Process.dlopenOrig = Process.dlopen Process.dlopen = function (module: Dict, filename: string, flags = constants.dlopen.RTLD_LAZY) { const dlopenRet = this.dlopenOrig(module, filename, flags) - for (let export_name in module.exports) { + for (const export_name in module.exports) { module.exports[export_name] = new Proxy(module.exports[export_name], { - construct: (target, args, _newTarget) => { + construct: (target, args) => { const ret = new target(...args) if (export_name === 'NodeIQQNTWrapperSession') wrapperApi.NodeIQQNTWrapperSession = ret return ret