This commit is contained in:
idranme 2024-08-19 17:29:58 +08:00
parent 65d02d7f21
commit ff18937828
No known key found for this signature in database
GPG Key ID: 926F7B5B668E495F
4 changed files with 13 additions and 36 deletions

View File

@ -34,7 +34,7 @@
"@types/fluent-ffmpeg": "^2.1.25", "@types/fluent-ffmpeg": "^2.1.25",
"@types/node": "^20.14.15", "@types/node": "^20.14.15",
"@types/ws": "^8.5.12", "@types/ws": "^8.5.12",
"electron": "^29.1.4", "electron": "^31.4.0",
"electron-vite": "^2.3.0", "electron-vite": "^2.3.0",
"typescript": "^5.5.4", "typescript": "^5.5.4",
"vite": "^5.4.1", "vite": "^5.4.1",

View File

@ -5,9 +5,7 @@ import path from 'node:path'
import { getSelfUin } from './data' import { getSelfUin } from './data'
import { DATA_DIR } from './utils' import { DATA_DIR } from './utils'
export const HOOK_LOG = false //export const HOOK_LOG = false
export const ALLOW_SEND_TEMP_MSG = false
export class ConfigUtil { export class ConfigUtil {
private readonly configPath: string private readonly configPath: string

View File

@ -16,7 +16,7 @@ import {
setSelfInfo setSelfInfo
} from '@/common/data' } from '@/common/data'
import { postOb11Event } from '../onebot11/server/post-ob11-event' import { postOb11Event } from '../onebot11/server/post-ob11-event'
import { getConfigUtil, HOOK_LOG } from '@/common/config' import { getConfigUtil } from '@/common/config'
import fs from 'node:fs' import fs from 'node:fs'
import { log } from '@/common/utils' import { log } from '@/common/utils'
import { randomUUID } from 'node:crypto' import { randomUUID } from 'node:crypto'
@ -81,7 +81,7 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
const originalSend = window.webContents.send const originalSend = window.webContents.send
const patchSend = (channel: string, ...args: NTQQApiReturnData) => { const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
// console.log("hookNTQQApiReceive", channel, args) // console.log("hookNTQQApiReceive", channel, args)
let isLogger = false /*let isLogger = false
try { try {
isLogger = args[0]?.eventName?.startsWith('ns-LoggerApi') isLogger = args[0]?.eventName?.startsWith('ns-LoggerApi')
} catch (e) { } } catch (e) { }
@ -91,7 +91,7 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
} catch (e) { } catch (e) {
log('hook log error', e, args) log('hook log error', e, args)
} }
} }*/
try { try {
if (args?.[1] instanceof Array) { if (args?.[1] instanceof Array) {
for (let receiveData of args?.[1]) { for (let receiveData of args?.[1]) {
@ -145,9 +145,9 @@ export function hookNTQQApiCall(window: BrowserWindow) {
isLogger = args[3][0].eventName.startsWith('ns-LoggerApi') isLogger = args[3][0].eventName.startsWith('ns-LoggerApi')
} catch (e) { } } catch (e) { }
if (!isLogger) { if (!isLogger) {
try { /*try {
HOOK_LOG && log('call NTQQ api', thisArg, args) HOOK_LOG && log('call NTQQ api', thisArg, args)
} catch (e) { } } catch (e) { }*/
try { try {
const _args: unknown[] = args[3][1] const _args: unknown[] = args[3][1]
const cmdName: NTQQApiMethod = _args[0] as NTQQApiMethod const cmdName: NTQQApiMethod = _args[0] as NTQQApiMethod
@ -181,16 +181,16 @@ export function hookNTQQApiCall(window: BrowserWindow) {
const proxyIpcInvoke = new Proxy(ipc_invoke_proxy, { const proxyIpcInvoke = new Proxy(ipc_invoke_proxy, {
apply(target, thisArg, args) { apply(target, thisArg, args) {
// console.log(args); // console.log(args);
HOOK_LOG && log('call NTQQ invoke api', thisArg, args) //HOOK_LOG && log('call NTQQ invoke api', thisArg, args)
args[0]['_replyChannel']['sendReply'] = new Proxy(args[0]['_replyChannel']['sendReply'], { args[0]['_replyChannel']['sendReply'] = new Proxy(args[0]['_replyChannel']['sendReply'], {
apply(sendtarget, sendthisArg, sendargs) { apply(sendtarget, sendthisArg, sendargs) {
sendtarget.apply(sendthisArg, sendargs) sendtarget.apply(sendthisArg, sendargs)
}, },
}) })
let ret = target.apply(thisArg, args) let ret = target.apply(thisArg, args)
try { /*try {
HOOK_LOG && log('call NTQQ invoke api return', ret) HOOK_LOG && log('call NTQQ invoke api return', ret)
} catch (e) { } } catch (e) { }*/
return ret return ret
}, },
}) })

View File

@ -1,7 +1,6 @@
import { ipcMain } from 'electron' import { ipcMain } from 'electron'
import { hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeReceiveHook } from './hook' import { hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeReceiveHook } from './hook'
import { log } from '../common/utils/log' import { log } from '../common/utils/log'
import { HOOK_LOG } from '../common/config'
import { randomUUID } from 'node:crypto' import { randomUUID } from 'node:crypto'
export enum NTQQApiClass { export enum NTQQApiClass {
@ -15,6 +14,7 @@ export enum NTQQApiClass {
SKEY_API = 'ns-SkeyApi', SKEY_API = 'ns-SkeyApi',
GROUP_HOME_WORK = 'ns-GroupHomeWork', GROUP_HOME_WORK = 'ns-GroupHomeWork',
GROUP_ESSENCE = 'ns-GroupEssence', GROUP_ESSENCE = 'ns-GroupEssence',
NODE_STORE_API = 'ns-NodeStoreApi'
} }
export enum NTQQApiMethod { export enum NTQQApiMethod {
@ -129,7 +129,7 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
timeout = timeout ?? 5 timeout = timeout ?? 5
afterFirstCmd = afterFirstCmd ?? true afterFirstCmd = afterFirstCmd ?? true
const uuid = randomUUID() const uuid = randomUUID()
HOOK_LOG && log('callNTQQApi', channel, className, methodName, args, uuid) //HOOK_LOG && log('callNTQQApi', channel, className, methodName, args, uuid)
return new Promise((resolve: (data: ReturnType) => void, reject) => { return new Promise((resolve: (data: ReturnType) => void, reject) => {
// log("callNTQQApiPromise", channel, className, methodName, args, uuid) // log("callNTQQApiPromise", channel, className, methodName, args, uuid)
const _timeout = timeout * 1000 const _timeout = timeout * 1000
@ -202,25 +202,4 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
export interface GeneralCallResult { export interface GeneralCallResult {
result: number // 0: success result: number // 0: success
errMsg: string errMsg: string
} }
export class NTQQApi {
static async call(className: NTQQApiClass, cmdName: string, args: any[]) {
return await callNTQQApi<GeneralCallResult>({
className,
methodName: cmdName,
args: [...args],
})
}
static async fetchUnitedCommendConfig() {
return await callNTQQApi<GeneralCallResult>({
methodName: NTQQApiMethod.FETCH_UNITED_COMMEND_CONFIG,
args: [
{
groups: ['100243'],
},
],
})
}
}