2022-02-16 08:20:50 +00:00
|
|
|
import { Telegram } from './client/Telegram';
|
2022-02-17 13:09:12 +00:00
|
|
|
import { config } from './providers/userConfig';
|
|
|
|
import { getLogger, configure } from 'log4js';
|
|
|
|
import SetupController from './controllers/SetupController';
|
2022-02-19 07:39:40 +00:00
|
|
|
import { Client as OicqClient } from 'oicq';
|
|
|
|
import createOicq from './client/oicq';
|
2022-02-20 08:25:30 +00:00
|
|
|
import ConfigController from './controllers/ConfigController';
|
2022-02-16 08:20:50 +00:00
|
|
|
|
|
|
|
(async () => {
|
2022-02-17 13:09:12 +00:00
|
|
|
configure({
|
|
|
|
appenders: {
|
|
|
|
console: { type: 'console' },
|
|
|
|
},
|
|
|
|
categories: {
|
|
|
|
default: { level: 'debug', appenders: ['console'] },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const log = getLogger('Main');
|
|
|
|
log.debug('正在登录 TG Bot');
|
2022-02-17 15:26:48 +00:00
|
|
|
const tgBot = await Telegram.create({
|
2022-02-16 08:20:50 +00:00
|
|
|
botAuthToken: process.env.TG_BOT_TOKEN,
|
|
|
|
});
|
2022-02-19 07:39:40 +00:00
|
|
|
let tgUser: Telegram, oicq: OicqClient;
|
2022-02-17 13:09:12 +00:00
|
|
|
log.debug('TG Bot 登录完成');
|
|
|
|
if (!config.isSetup) {
|
|
|
|
log.info('当前服务器未配置,请向 Bot 发送 /setup 来设置');
|
2022-02-17 15:26:48 +00:00
|
|
|
const setupController = new SetupController(tgBot);
|
2022-02-19 07:39:40 +00:00
|
|
|
({ tgUser, oicq } = await setupController.waitForFinish());
|
2022-02-17 15:26:48 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-02-20 08:25:30 +00:00
|
|
|
if (config.userBotSession) {
|
|
|
|
log.debug('正在登录 TG UserBot');
|
|
|
|
tgUser = await Telegram.connect(config.userBotSession);
|
|
|
|
log.debug('TG UserBot 登录完成');
|
|
|
|
}
|
|
|
|
log.debug('正在登录 OICQ');
|
2022-02-19 07:39:40 +00:00
|
|
|
oicq = await createOicq({
|
|
|
|
uin: config.qqUin,
|
|
|
|
password: config.qqPassword,
|
|
|
|
platform: config.qqPlatform,
|
|
|
|
onVerifyDevice: () => null,
|
|
|
|
onVerifySlider: () => null,
|
|
|
|
onQrCode: () => null,
|
|
|
|
});
|
2022-02-20 08:25:30 +00:00
|
|
|
log.debug('OICQ 登录完成');
|
2022-02-17 13:09:12 +00:00
|
|
|
}
|
2022-02-20 08:25:30 +00:00
|
|
|
new ConfigController(tgBot, tgUser, oicq);
|
2022-02-16 08:20:50 +00:00
|
|
|
})();
|