-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathebbot.js
More file actions
31 lines (25 loc) · 954 Bytes
/
ebbot.js
File metadata and controls
31 lines (25 loc) · 954 Bytes
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
const Telegram = require('telegram-node-bot');
const config = require('./config');
const Auth = require('./auth');
class EBbot {
static start() {
const onAllAuthReqsSucceed = EBbot.registerRoutes.bind(EBbot);
Auth.run(onAllAuthReqsSucceed);
}
static registerRoutes() {
const telebot = new Telegram.Telegram(config.botToken, { workers: config.workersCount });
const router = telebot.router;
const routes = config.routes.right;
const OtherwiseCtrl = require('./controllers/' + config.routes.wrong);
const otherwiseCtrl = new OtherwiseCtrl();
router.otherwise(otherwiseCtrl);
Object.keys(routes).forEach(command => {
const ctrlPath = './controllers/' + routes[command];
const Ctrl = require(ctrlPath);
const commandTextPattern = '/' + command;
const textCommand = new Telegram.TextCommand(commandTextPattern);
router.when(textCommand, new Ctrl(commandTextPattern, otherwiseCtrl));
});
}
}
module.exports = EBbot;