-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (63 loc) · 1.59 KB
/
app.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
/**
*
* __ ______ __ __ ______ ______ ______
* /\ \ /\ __ \ /\ "-.\ \ /\ == \ /\ __ \ /\__ _\
* \ \ \____ \ \ __ \ \ \ \-. \ \ \ __< \ \ \/\ \ \/_/\ \/
* \ \_____\ \ \_\ \_\ \ \_\\"\_\ \ \_____\ \ \_____\ \ \_\
* \/_____/ \/_/\/_/ \/_/ \/_/ \/_____/ \/_____/ \/_/
*
*
* LANBotX, a botkit-powered LANBot
*/
import Botkit from 'botkit';
import redis from 'botkit/lib/storage/redis_storage';
import fs from 'fs';
import Path from 'path';
import monitor from './src/monitor';
import webserver from './src/webserver';
/**
* Initialize botkit
*/
const storage = redis({
host: process.env.REDIS_PORT_6379_TCP_ADDR || '127.0.0.1',
port: process.env.REDIS_PORT_6379_TCP_PORT || 6379,
namespace: 'lanbot',
methods: ['teams', 'users', 'channels', 'responses', 'karma'],
});
const controller = Botkit.slackbot({
debug: false,
storage: storage,
});
const worker = controller.spawn({
token: process.env.token
}).startRTM((err) => {
if (err) {
throw new Error(err);
}
});
monitor(controller, worker);
webserver(controller);
/**
* Determine if bot is running
*/
controller.hears(
'ping',
['direct_message','direct_mention','mention'],
(bot,message) => {
bot.reply(message, 'PONG');
}
);
/**
* Initalize scripts
*/
for(const file of fs.readdirSync('./scripts/')) {
if (Path.extname(file) !== '.js') {
continue;
}
try {
const script = require(`./scripts/${file}`).default;
new script(controller);
} catch (e) {
console.error(`Unable to load ${file}: ${e.stack}`);
}
}