mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
optimize
This commit is contained in:
@@ -137,21 +137,21 @@ export function invoke<
|
|||||||
S extends keyof NTService = any,
|
S extends keyof NTService = any,
|
||||||
M extends keyof NTService[S] & string = any,
|
M extends keyof NTService[S] & string = any,
|
||||||
O = string
|
O = string
|
||||||
>(method: `${O extends `${S}/${M}` ? `${S}/${M}` : string}`, args?: unknown[], options?: InvokeOptions<R>) {
|
>(method: `${O extends `${S}/${M}` ? `${S}/${M}` : string}`, args?: unknown[], options: InvokeOptions<R> = {}) {
|
||||||
const className = options?.className ?? NTClass.NT_API
|
const className = options.className ?? NTClass.NT_API
|
||||||
const channel = options?.channel ?? NTChannel.IPC_UP_2
|
const channel = options.channel ?? NTChannel.IPC_UP_2
|
||||||
const timeout = options?.timeout ?? 5000
|
const timeout = options.timeout ?? 5000
|
||||||
const afterFirstCmd = options?.afterFirstCmd ?? true
|
const afterFirstCmd = options.afterFirstCmd ?? true
|
||||||
const uuid = randomUUID()
|
const uuid = randomUUID()
|
||||||
let eventName = className + '-' + channel[channel.length - 1]
|
let eventName = className + '-' + channel[channel.length - 1]
|
||||||
if (options?.classNameIsRegister) {
|
if (options.classNameIsRegister) {
|
||||||
eventName += '-register'
|
eventName += '-register'
|
||||||
}
|
}
|
||||||
const apiArgs = [method, ...(args ?? [])]
|
const apiArgs = [method, ...(args ?? [])]
|
||||||
//log('callNTQQApi', channel, eventName, apiArgs, uuid)
|
//log('callNTQQApi', channel, eventName, apiArgs, uuid)
|
||||||
return new Promise((resolve: (data: R) => void, reject) => {
|
return new Promise((resolve: (data: R) => void, reject) => {
|
||||||
let success = false
|
let success = false
|
||||||
if (!options?.cbCmd) {
|
if (!options.cbCmd) {
|
||||||
// QQ后端会返回结果,并且可以根据uuid识别
|
// QQ后端会返回结果,并且可以根据uuid识别
|
||||||
hookApiCallbacks[uuid] = (r: R) => {
|
hookApiCallbacks[uuid] = (r: R) => {
|
||||||
success = true
|
success = true
|
||||||
|
Reference in New Issue
Block a user