Update SetupController.ts

This commit is contained in:
Nofated 2023-01-19 00:32:54 +08:00 committed by GitHub
parent 5060ba5189
commit 1273fb8a97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 17 deletions

View File

@ -15,9 +15,8 @@ export default class SetupController {
private readonly setupService: SetupService;
private readonly log: Logger;
private isInProgress = false;
private waitForFinishCallbacks: Array<(ret: { tgUser: Telegram, oicq: OicqClient }) => unknown> = [];
private waitForFinishCallbacks: Array<(ret: { oicq: OicqClient }) => unknown> = [];
// 创建的 UserBot
private tgUser: Telegram;
private oicq: OicqClient;
constructor(private readonly instance: Instance,
@ -99,19 +98,20 @@ export default class SetupController {
if (this.instance.userSessionId) {
await this.setupService.informOwner('userSessionId 已经存在,跳过');
}
else
try {
const phoneNumber = await this.setupService.waitForOwnerInput('创建 Telegram UserBot请输入你的手机号码需要带国家区号例如+86');
await this.setupService.informOwner('正在登录,请稍候…');
this.tgUser = await this.setupService.createUserBot(phoneNumber);
this.instance.userSessionId = this.tgUser.sessionId;
await this.setupService.informOwner(`登录成功`);
}
catch (e) {
this.log.error('创建 UserBot 失败', e);
this.isInProgress = false;
throw e;
}
else {
await this.setupService.informOwner(`UserBot 创建被跳过`);
// try {
// const phoneNumber = await this.setupService.waitForOwnerInput('创建 Telegram UserBot请输入你的手机号码需要带国家区号例如+86');
// await this.setupService.informOwner('正在登录,请稍候…');
// this.tgUser = await this.setupService.createUserBot(phoneNumber);
// this.instance.userSessionId = this.tgUser.sessionId;
// await this.setupService.informOwner(`登录成功`);
// }
// catch (e) {
// this.log.error('创建 UserBot 失败', e);
// this.isInProgress = false;
// throw e;
// }
}
private async finishSetup() {
@ -119,13 +119,12 @@ export default class SetupController {
this.isInProgress = false;
await this.setupService.finishConfig();
this.waitForFinishCallbacks.forEach(e => e({
tgUser: this.tgUser,
oicq: this.oicq,
}));
}
public waitForFinish() {
return new Promise<{ tgUser: Telegram, oicq: OicqClient }>(resolve => {
return new Promise<{ oicq: OicqClient }>(resolve => {
this.waitForFinishCallbacks.push(resolve);
});
}