-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
99 lines (81 loc) · 2.58 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// __ __ ___ ___
// |__) / \ | |__/ | |
// |__) \__/ | | \ | |
// This is the main file for the veribot bot.
// Import Botkit's core features
const Winston = require('winston');
const Botkit = require('botkit');
const BotkitDiscord = require('botkit-discord');
const BotkitTelegram = require('botkit-telegram');
var appConfig = require('./config/app');
// Init logs
const log = new (Winston.Logger)({
level: appConfig.logs.level || 'info',
levels: Winston.config.syslog.levels,
transports: [
new Winston.transports.Console({
colorize: true,
prettyPrint: true,
timestamp: true
}),
]
});
var debug = log.level == 'debug' || log.level == 'silly';
function initSlack(log) {
if (!appConfig.platform.slack.token) {
log.warning('Missing SLACK_BOT_TOKEN, skipping Slack ')
return;
}
log.info('Initializing Slack Bot')
var controller = Botkit.slackbot({
clientSigningSecret: appConfig.platform.slack.signingKey,
debug: debug,
logger: log,
retry: 10,
});
log.info('Initializing Slack Bot')
var bot = controller.spawn({
token: appConfig.platform.slack.token,
}).startRTM();
var normalizedPath = require("path").join(__dirname, "feature");
require("fs").readdirSync(normalizedPath).forEach(function (file) {
require("./feature/" + file)(controller);
});
}
function initDiscord(log) {
if (!appConfig.platform.discord.token) {
log.warning('Missing DISCORD_BOT_TOKEN, skipping Discord ')
return;
}
log.info('Initializing Discord Bot')
const controller = BotkitDiscord({
token: appConfig.platform.discord.token,
debug: debug,
logger: log,
retry: 10,
});
var normalizedPath = require("path").join(__dirname, "feature");
require("fs").readdirSync(normalizedPath).forEach(function (file) {
require("./feature/" + file)(controller);
});
}
function initTelegram(log) {
if (!appConfig.platform.telegram.token) {
log.warning('Missing TELEGRAM_BOT_TOKEN, skipping Telegram ')
return;
}
log.info('Initializing Telegram Bot')
var controller = BotkitTelegram({
token: appConfig.platform.telegram.token,
debug: debug,
logger: log,
retry: 10,
})
var normalizedPath = require("path").join(__dirname, "feature");
require("fs").readdirSync(normalizedPath).forEach(function (file) {
require("./feature/" + file)(controller);
});
}
initSlack(log);
initDiscord(log);
initTelegram(log);