forked from ceejbot/LOUDBOT-SLACK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SLACKER.js
55 lines (45 loc) · 1.18 KB
/
SLACKER.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
var
SLACKBOT = require('./SLACKBOT.js'),
RESTIFY = require('restify')
;
var TOKENS;
if (process.env.TOKEN)
{
TOKENS = process.env.TOKEN.split(',');
}
var LOUDBOT = new SLACKBOT();
var SERVER = RESTIFY.createServer();
SERVER.use(RESTIFY.acceptParser(SERVER.acceptable));
SERVER.use(RESTIFY.queryParser());
SERVER.use(RESTIFY.gzipResponse());
SERVER.use(RESTIFY.bodyParser({ mapParams: false }));
SERVER.get('/PING', PING);
SERVER.get('/LOUDS', LOUDS);
SERVER.post('/MESSAGE', MESSAGE);
SERVER.listen(process.env.PORT || 4444);
function PING(REQUEST, RESPONSE, NEXT)
{
RESPONSE.send(200, 'PONG');
NEXT();
}
function LOUDS(REQUEST, RESPONSE, NEXT)
{
RESPONSE.send(LOUDBOT.THELOUDS());
NEXT();
}
function MESSAGE(REQUEST, RESPONSE, NEXT)
{
if (TOKENS)
{
var IDX = TOKENS.indexOf(REQUEST.body.token);
if (IDX === -1) return NEXT(new RESTIFY.ForbiddenError('NO LOUDS FOR YOU'));
}
var WHAT;
if (REQUEST.body.user_name !== 'slackbot')
WHAT = LOUDBOT.LISTENUP(REQUEST.body.text);
if (WHAT)
RESPONSE.json(200, { text: WHAT, channel: REQUEST.body.channel_name });
else
RESPONSE.send(200);
NEXT();
}