-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
39 lines (32 loc) · 989 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
const Telegram = require('telegram-node-bot');
const config = require('./config');
const args = require('minimist')(process.argv.slice(2));
const logger = require('./lib/logger')(config.log);
require('./lib/api')(config.api);
/**
* Handles process shutdown
*
* @param {Boolean} silent
* @param {Error} err
*/
var exitHandler = function(silent, err) {
if (!silent) {
logger.info('Shutdown');
}
if (err) {
logger.error(err.stack);
}
process.exit();
};
process.on('exit', exitHandler.bind(null, false));
process.on('SIGINT', exitHandler.bind(null, true));
process.on('uncaughtException', exitHandler.bind(null, true));
const botKey = process.env.TELEGRAM_FSPLS_BOT_TOKEN || args.key || config.key;
if (!botKey) {
throw new Error('Bot key is not provided');
}
const localizations = [ require('./data/i18n/en.json') ];
const tg = new Telegram.Telegram(botKey, logger, null, localizations);
require('./router')(tg, config);
logger.info('Started');