Skip to content

Commit

Permalink
fix: import error
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Jul 12, 2024
1 parent f486bf9 commit 56e6da5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions main/src/client/QQClient/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import OicqClient, { CreateOicqParams } from '../OicqClient';
import { CreateOicqParams } from '../OicqClient';
import { Friend, Group } from './entity';
import {
FriendIncreaseEvent,
Expand All @@ -8,7 +8,7 @@ import {
MessageRecallEvent, PokeEvent,
} from './events';
import type { FriendRequestEvent, GroupInviteEvent, ImageElem, MessageElem } from '@icqqjs/icqq';
import { CreateNapCatParams, NapCatClient } from '../NapCatClient';
import { CreateNapCatParams } from '../NapCatClient';

export * from './events';
export * from './entity';
Expand All @@ -34,26 +34,31 @@ export abstract class QQClient {

private static existedBots = {} as { [id: number]: Promise<QQClient> };

public static create(params: CreateQQClientParams) {
public static async create(params: CreateQQClientParams) {
if (this.existedBots[params.id]) {
return this.existedBots[params.id];
}

let client: Promise<QQClient>;
let clientType: {
create(params: CreateQQClientParams): Promise<QQClient>;
};

switch (params.type) {
case 'oicq':
client = OicqClient.create(params);
clientType = (await import('../OicqClient')).default;
break;
case 'napcat':
client = NapCatClient.create(params);
clientType = (await import('../NapCatClient')).NapCatClient;
break;
default:
throw new Error('Unknown client type');
}

client = clientType.create(params);

this.existedBots[params.id] = client;
return client;
return await client;
}


Expand Down

0 comments on commit 56e6da5

Please sign in to comment.