mirror of https://github.com/Nofated095/Q2TG.git
perf: 整合发送提示和等待输入
This commit is contained in:
parent
9ee2791ad8
commit
7bb8423099
|
@ -41,9 +41,8 @@ export default class SetupController {
|
|||
this.isInProgress = false;
|
||||
throw e;
|
||||
}
|
||||
await this.setupService.informOwner('创建 Telegram UserBot,请输入你的手机号码(需要带国家区号,例如:+86)');
|
||||
try {
|
||||
const phoneNumber = await this.setupService.waitForOwnerInput();
|
||||
const phoneNumber = await this.setupService.waitForOwnerInput('创建 Telegram UserBot,请输入你的手机号码(需要带国家区号,例如:+86)');
|
||||
await this.setupService.informOwner('正在登录,请稍候…');
|
||||
this.tgUser = await this.setupService.createUserBot(phoneNumber);
|
||||
await this.setupService.informOwner(`登录成功`);
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Telegram, TelegramChat } from '../client/Telegram';
|
|||
import { config, saveConfig } from '../providers/userConfig';
|
||||
import { getLogger } from 'log4js';
|
||||
import { BigInteger } from 'big-integer';
|
||||
import { Platform } from 'oicq';
|
||||
|
||||
export default class SetupService {
|
||||
private owner: TelegramChat;
|
||||
|
@ -39,12 +40,13 @@ export default class SetupService {
|
|||
await this.owner.sendMessage({ message });
|
||||
}
|
||||
|
||||
public async waitForOwnerInput() {
|
||||
public async waitForOwnerInput(message: string) {
|
||||
if (!this.owner) {
|
||||
throw new Error('应该不会运行到这里');
|
||||
}
|
||||
const { message } = await this.owner.waitForInput();
|
||||
return message;
|
||||
await this.owner.sendMessage({ message });
|
||||
const { message: reply } = await this.owner.waitForInput();
|
||||
return reply;
|
||||
}
|
||||
|
||||
public async createUserBot(phoneNumber: string) {
|
||||
|
@ -54,16 +56,10 @@ export default class SetupService {
|
|||
return await Telegram.create({
|
||||
phoneNumber,
|
||||
password: async (hint?: string) => {
|
||||
await this.owner.sendMessage({
|
||||
message: `请输入你的二步验证密码${hint ? '\n密码提示:' + hint : ''}`,
|
||||
});
|
||||
return await this.waitForOwnerInput();
|
||||
return await this.waitForOwnerInput(`请输入你的二步验证密码${hint ? '\n密码提示:' + hint : ''}`);
|
||||
},
|
||||
phoneCode: async (isCodeViaApp?: boolean) => {
|
||||
await this.owner.sendMessage({
|
||||
message: `请输入你${isCodeViaApp ? ' Telegram APP 中' : '手机上'}收到的验证码`,
|
||||
});
|
||||
return await this.waitForOwnerInput();
|
||||
return await this.waitForOwnerInput(`请输入你${isCodeViaApp ? ' Telegram APP 中' : '手机上'}收到的验证码`);
|
||||
},
|
||||
onError: (err) => this.log.error(err),
|
||||
});
|
||||
|
@ -73,6 +69,10 @@ export default class SetupService {
|
|||
config.userBotSession = session;
|
||||
}
|
||||
|
||||
public async createOicq(uin: number, password: string, platform: Platform) {
|
||||
|
||||
}
|
||||
|
||||
public async finishConfig() {
|
||||
config.isSetup = true;
|
||||
await saveConfig();
|
||||
|
|
Loading…
Reference in New Issue