This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
41 lines (33 loc) · 1.6 KB
/
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
40
41
'use strict';
const Telegram = require('telegram-node-bot'),
path = require('path'),
store = require('./store'),
constants = require('./constants'),
tg = new Telegram.Telegram(constants.TOKEN, {
workers: 1
});
const InlineModeController = require('./controllers/inline_mode')
, OtherwiseController = require('./controllers/otherwise')
, UserController = require('./controllers/user')
, StartController = require('./controllers/start');
const userCtrl = new UserController(),
startCtrl = new StartController();
tg.router.inlineQuery(new InlineModeController())
.when(new Telegram.TextCommand(constants.COMMAND_START, 'startCommand'), startCtrl)
.when(new Telegram.TextCommand(constants.COMMAND_SET, 'setCommand'), userCtrl)
.when(new Telegram.TextCommand(constants.COMMAND_GET, 'getCommand'), userCtrl)
.when(new Telegram.TextCommand(constants.COMMAND_CURRENCY, 'currencyCommand'), userCtrl)
.when(new Telegram.TextCommand(constants.TEXT_COMMAND_SET_PAYPAL, 'setTextCommand'), startCtrl)
.when(new Telegram.TextCommand(constants.TEXT_COMMAND_SET_CURRENCY, 'currencyTextCommand'), startCtrl)
.when(new Telegram.TextCommand(constants.TEXT_COMMAND_REQUEST_MONEY, 'requestTextCommand'), startCtrl)
.otherwise(new OtherwiseController());
store.init(path.normalize(__dirname + constants.FILE_PATH_STORE));
setInterval(() => {
store.flush();
}, constants.FLUSH_INTERVAL);
function exitHandler(exitCode) {
store.flush();
process.exit(exitCode);
}
process.on('SIGINT', exitHandler.bind(null, 0));
process.on('uncaughtException', exitHandler.bind(null, 1));