diff --git a/src/common/utils/EventTask.ts b/src/common/utils/EventTask.ts index 696973db..8bea2ba8 100644 --- a/src/common/utils/EventTask.ts +++ b/src/common/utils/EventTask.ts @@ -5,6 +5,7 @@ interface Internal_MapKey { timeout: number, createtime: number, func: (...arg: any[]) => any, + checker: ((...args: any[]) => boolean) | undefined, } export class ListenerClassBase { @@ -90,10 +91,12 @@ export class NTEventWrapper { this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.delete(uuid); return; } - task.func(...args); + if (task.checker && task.checker(...args)) { + task.func(...args); + } }); } - async CallNoListenerEvent Promise,>(EventName = '', timeout: number = 3000, ...args: Parameters) { + async CallNoListenerEvent Promise>(EventName = '', timeout: number = 3000, ...args: Parameters) { return new Promise>>(async (resolve, reject) => { const EventFunc = this.CreatEventFunction(EventName); let complete = false; @@ -107,14 +110,15 @@ export class NTEventWrapper { resolve(retData); }); } - async CallNormalEvent Promise, ListenerType extends (...args: any[]) => void>(EventName = '', ListenerName = '', waitTimes = 1, timeout: number = 3000, ...args: Parameters) { + async CallNormalEvent Promise, ListenerType extends (...args: any[]) => void> + (EventName = '', ListenerName = '', waitTimes = 1, timeout: number = 3000, checker: (...args: Parameters) => boolean, ...args: Parameters) { return new Promise<[EventRet: Awaited>, ...Parameters]>(async (resolve, reject) => { const id = randomUUID(); let complete = 0; let retData: Parameters | undefined = undefined; let retEvent: any = {}; const databack = () => { - if (complete < waitTimes) { + if (complete == 0) { reject(new Error('NTEvent EventName:' + EventName + ' ListenerName:' + ListenerName + ' timeout')); } else { resolve([retEvent as Awaited>, ...retData!]); @@ -128,6 +132,7 @@ export class NTEventWrapper { const eventCallbak = { timeout: timeout, createtime: Date.now(), + checker: checker, func: (...args: any[]) => { complete++; //console.log('func', ...args); diff --git a/src/core/src/apis/friend.ts b/src/core/src/apis/friend.ts index e6cb961e..01b9cb6a 100644 --- a/src/core/src/apis/friend.ts +++ b/src/core/src/apis/friend.ts @@ -14,6 +14,7 @@ export class NTQQFriendApi { 'NodeIKernelBuddyListener/onBuddyListChange', 1, 5000, + () => true, forced ); const friends: User[] = []; diff --git a/src/core/src/apis/group.ts b/src/core/src/apis/group.ts index 37614f26..459e98c5 100644 --- a/src/core/src/apis/group.ts +++ b/src/core/src/apis/group.ts @@ -15,6 +15,7 @@ export class NTQQGroupApi { 'NodeIKernelGroupListener/onGroupListUpdate', 1, 5000, + ()=>true, forced ); return groupList; @@ -63,6 +64,7 @@ export class NTQQGroupApi { 'NodeIKernelGroupListener/onGroupSingleScreenNotifies', 1, 5000, + ()=>true, false, '', num