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';
|
2022-02-24 10:27:06 +00:00
|
|
|
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';
|
2022-02-24 10:27:06 +00:00
|
|
|
import ForwardController from './controllers/ForwardController';
|
2022-03-04 10:50:11 +00:00
|
|
|
import FileAndFlashPhotoController from './controllers/FileAndFlashPhotoController';
|
2022-03-06 12:24:19 +00:00
|
|
|
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');
|
2022-02-22 11:17:17 +00:00
|
|
|
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-24 13:16:19 +00:00
|
|
|
}, 'bot');
|
2022-02-23 06:09:54 +00:00
|
|
|
|
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-24 13:16:19 +00:00
|
|
|
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({
|
2022-02-19 07:39:40 +00:00
|
|
|
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-03-06 12:24:19 +00:00
|
|
|
new DeleteMessageController(tgBot, tgUser, oicq);
|
2022-02-24 10:27:06 +00:00
|
|
|
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
|
|
|
})();
|