Skip to content

Commit

Permalink
chore: 未完成初始化时,对消息返回提示
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Dec 26, 2024
1 parent 47825e4 commit 9de755f
Show file tree
Hide file tree
Showing 4 changed files with 462 additions and 509 deletions.
1 change: 1 addition & 0 deletions main/src/controllers/AliveCheckController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class AliveCheckController {
await message.reply({
message: await this.genMessage(this.instance.id === 0 ? Instance.instances : [this.instance]),
});
return true;
};

private async genMessage(instances: Instance[]): Promise<string> {
Expand Down
39 changes: 39 additions & 0 deletions main/src/controllers/LoadingController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Instance from '../models/Instance';
import Telegram from '../client/Telegram';
import { MiraiElem } from '@icqqjs/icqq';
import { MessageEvent, QQClient } from '../client/QQClient';
import { Api } from 'telegram';
import lottie from '../constants/lottie';

export default class {
constructor(private readonly instance: Instance,
private readonly tgBot: Telegram,
private readonly tgUser: Telegram,
private readonly qqBot: QQClient) {
this.initStickerPack();
tgBot.addNewMessageEventHandler(this.onTelegramMessage);
}

private stickerPackHandles: Api.TypeDocument[] = null;

private async initStickerPack() {
const pack = await this.tgBot.getStickerSet('Clansty_WEBM');
this.stickerPackHandles = pack.documents;
}

private onTelegramMessage = async (message: Api.Message) => {
if ((message.isGroup || message.isChannel) && this.instance.workMode === 'group') return;
if (this.stickerPackHandles)
await message.reply({
file: this.stickerPackHandles[0],
});
await message.reply({
message: 'Q2TG 还在初始化中,所以暂时无法处理你的消息。请稍后再试',
});
return true;
};

public off() {
this.tgBot.removeNewMessageEventHandler(this.onTelegramMessage);
}
}
8 changes: 7 additions & 1 deletion main/src/models/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import env from './env';
import AliveCheckController from '../controllers/AliveCheckController';
import { QQClient } from '../client/QQClient';
import posthog from './posthog';
import LoadingController from '../controllers/LoadingController';
import { sleep } from 'telegram/Helpers';

export default class Instance {
public static readonly instances: Instance[] = [];
Expand Down Expand Up @@ -60,6 +62,7 @@ export default class Instance {
private quotLyController: QuotLyController;
private miraiSkipFilterController: MiraiSkipFilterController;
private aliveCheckController: AliveCheckController;
private loadingController: LoadingController;

private constructor(public readonly id: number) {
this.log = getLogger(`Instance - ${this.id}`);
Expand Down Expand Up @@ -143,7 +146,10 @@ export default class Instance {
});
this.log.info('OICQ 登录完成');
}
this.aliveCheckController = new AliveCheckController(this, this.tgBot, this.tgUser, this.oicq);
this.loadingController = new LoadingController(this, this.tgBot, this.tgUser, this.oicq);
this.forwardPairs = await ForwardPairs.load(this.id, this.oicq, this.tgBot, this.tgUser);
await sleep(10000);
this.setupCommands()
.then(() => this.log.info('命令设置成功'))
.catch(e => {
Expand All @@ -156,7 +162,6 @@ export default class Instance {
this.oicqErrorNotifyController = new OicqErrorNotifyController(this, this.oicq);
this.requestController = new RequestController(this, this.tgBot, this.oicq);
this.configController = new ConfigController(this, this.tgBot, this.tgUser, this.oicq);
this.aliveCheckController = new AliveCheckController(this, this.tgBot, this.tgUser, this.oicq);
this.deleteMessageController = new DeleteMessageController(this, this.tgBot, this.tgUser, this.oicq);
this.miraiSkipFilterController = new MiraiSkipFilterController(this, this.tgBot, this.tgUser, this.oicq);
this.inChatCommandsController = new InChatCommandsController(this, this.tgBot, this.tgUser, this.oicq);
Expand All @@ -167,6 +172,7 @@ export default class Instance {
}
this.fileAndFlashPhotoController = new FileAndFlashPhotoController(this, this.tgBot, this.oicq);
this.isInit = true;
this.loadingController.off();
})()
.then(() => this.log.info('初始化已完成'));
}
Expand Down
Loading

0 comments on commit 9de755f

Please sign in to comment.