Q2TG/src/index.ts

57 lines
1.9 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 { configure, getLogger } from 'log4js';
2022-02-17 13:09:12 +00:00
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';
import ForwardController from './controllers/ForwardController';
2022-03-04 10:50:11 +00:00
import FileAndFlashPhotoController from './controllers/FileAndFlashPhotoController';
import DeleteMessageController from './controllers/DeleteMessageController';
2022-02-16 08:20:50 +00:00
(async () => {
2022-02-17 13:09:12 +00:00
configure({
appenders: {
console: { type: 'console' },
},
categories: {
2022-02-24 13:23:35 +00:00
default: { level: 'debug', appenders: ['console'] },
2022-02-17 13:09:12 +00:00
},
});
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,
}, 'bot');
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 {
log.debug('正在登录 TG UserBot');
tgUser = await Telegram.connect('user');
log.debug('TG UserBot 登录完成');
2022-02-20 08:25:30 +00:00
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);
new DeleteMessageController(tgBot, tgUser, oicq);
new ForwardController(tgBot, tgUser, oicq);
2022-03-04 10:50:11 +00:00
new FileAndFlashPhotoController(tgBot, oicq);
2022-02-16 08:20:50 +00:00
})();