Skip to content

Commit

Permalink
style: RegExec match->exec
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Aug 25, 2024
1 parent 5486ffc commit 5f1d8fb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common/framework/event-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class LegacyNTEventWrapper {
const existListener = this.listenerManager.get(listenerMainName + uniqueCode);
if (!existListener) {
const Listener = this.createProxyDispatch(listenerMainName);
const ServiceSubName = listenerMainName.match(/^NodeIKernel(.*?)Listener$/)![1];
const ServiceSubName = /^NodeIKernel(.*?)Listener$/.exec(listenerMainName)![1];
const Service = 'NodeIKernel' + ServiceSubName + 'Service/addKernel' + ServiceSubName + 'Listener';
const addfunc = this.createEventFunction<(listener: T) => number>(Service);
addfunc!(Listener as T);
Expand Down
2 changes: 1 addition & 1 deletion src/common/framework/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class NTEventChannel extends EventEmitter {
Listener = new ListenerType(this.createProxyDispatch(listenerMainName));
if (!Listener) throw new Error('Init Listener failed');
//实例化NTQQ Listener外包装
const ServiceSubName = listenerMainName.match(/^NodeIKernel(.*?)Listener$/)![1];
const ServiceSubName = /^NodeIKernel(.*?)Listener$/.exec(listenerMainName)![1];
const Service = 'NodeIKernel' + ServiceSubName + 'Service/addKernel' + ServiceSubName + 'Listener';
const addfunc = this.createEventFunction<(listener: T) => number>(Service);
//添加Listener到NTQQ
Expand Down
9 changes: 6 additions & 3 deletions src/common/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export async function solveProblem<T extends (...arg: any[]) => any>(func: T, ..
}

export async function solveAsyncProblem<T extends (...args: any[]) => Promise<any>>(func: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>> | undefined> {
return new Promise<Awaited<ReturnType<T>> | undefined>(async (resolve) => {
return new Promise<Awaited<ReturnType<T>> | undefined>((resolve) => {
try {
const result = await func(...args);
resolve(result);
func(...args).then((result) => {
resolve(result);
}).catch((e) => {
resolve(undefined);
});
} catch (e) {
resolve(undefined);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/apis/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class NTQQUserApi {
}

async getUserDetailInfo(uid: string): Promise<User> {
const retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, UserDetailSource.KDB));
const retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, UserDetailSource.KDB), uid);
if (retUser && retUser.uin !== '0') {
return retUser;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/apis/webapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class NTQQWebApi {
let resJson;
try {
const res = await RequestUtil.HttpGetText(url, 'GET', '', { 'Cookie': this.cookieToString(cookieObject) });
const match = res.match(/window\.__INITIAL_STATE__=(.*?);/);
let match = /window\.__INITIAL_STATE__=(.*?);/.exec(res);
if (match) {
resJson = JSON.parse(match[1].trim());
}
Expand Down

0 comments on commit 5f1d8fb

Please sign in to comment.