Q2TG/src/index.ts

53 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-02-23 09:11:04 +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-23 06:09:54 +00:00
import OicqClient from './client/OicqClient';
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');
process.on('unhandledRejection', error => {
log.error('UnhandledException: ', error);
});
2022-02-23 06:09:54 +00:00
2022-02-17 13:09:12 +00:00
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-23 06:09:54 +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);
({ 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-23 06:09:54 +00:00
oicq = await OicqClient.create({
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
})();