forked from Xerxous/rallyslack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·56 lines (43 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
var table = require('text-table'),
jsonfile = require('jsonfile'),
manager = require('./bot/manager/manager'),
logger = require('./bot/logger'),
slackWeb = require('./bot/web').slackWeb;
try {
var config = jsonfile.readFileSync('./config.json'),
modules = config.config.modules;
if (process.argv.length > 2){
manager(process.argv, modules);
process.exit();
}
slackWeb = slackWeb(config.slackbot.slackWebKey);
var mods = {},
listens = [],
listensFiles = config.config.listens;
for (let listen in listensFiles){
listens = listens.concat(require(listensFiles[listen]))
}
for (let mod in modules){
if (!modules[mod].options){
modules[mod].options = {};
}
modules[mod].options.slackWeb = slackWeb;
modules[mod].options.logger = logger(slackWeb);
mods[mod] = require(modules[mod].path)(modules[mod].options);
console.log('Installed modules: ' + mod);
}
console.log('Aggregation of \'listens\' configuration files:')
console.log(table(listens))
modules.capture.options.listens = listens;
var slackbot = require(config.slackbot.bot)(config.slackbot.slackBotKey, mods, listens);
} catch (err){
console.trace(err)
process.exit();
}
slackbot.startRTM((err, bot, payload) => {
if (err) {
console.log('No connection to Slack.\nMay occur due to connection issues or invalid API key.');
}
});
module.exports = slackbot;