-
Notifications
You must be signed in to change notification settings - Fork 24
/
bot.js
50 lines (41 loc) · 1.53 KB
/
bot.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
42
43
44
45
46
47
48
49
'use strict'
const config = require('./config')
const Telegram = require('telegram-node-bot')
const TextCommand = Telegram.TextCommand
var request = require('request');
var mongojs = require('mongojs')
var db = mongojs(config.db.name || process.env.DBNAME)
var followedForums = db.collection('followed_forums');
var botToken = config.token || process.env.BOT_TOKEN
// Export bot as global variable
global.tg = new Telegram.Telegram(botToken, {
localization: [require('./localization/En.json')]
})
const BotUtils = require('./utils')
// Default Controllers
var CallbackController = require("./handlers/callbackQuery.js")
var InlineController = require("./handlers/inline.js")
var OtherwiseController = require("./handlers/custom_commands.js")
// Exports all handlers
require('fs').readdirSync(__dirname + '/handlers/').forEach(function (file) {
if (file.match(/\.js$/) !== null && file !== 'index.js') {
try {
var handler = require('./handlers/' + file)
var instance = new handler()
if (instance.config) {
instance.config.commands.forEach(command => {
tg.router.when(
new TextCommand(command.command, command.handler, 'Display commands menu'),
instance
)
})
}
} catch (ex) {
console.log(ex)
}
}
});
// Routes
tg.router.callbackQuery(new CallbackController())
.inlineQuery(new InlineController())
.otherwise(new OtherwiseController())