forked from benjaminadk/giggle-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (46 loc) · 1.42 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
57
58
59
60
61
62
63
64
'use strict'
const Bot = require('./bot.js');
/* get token from env variable for security reasons
eg.
when running the bot process use
SLACK_TOKEN = <BOT_SLACK_TOKEN_HERE> node index.js
*/
const token = process.env.SLACK_TOKEN;
// create bot instance
const bot = new Bot({
token: token,
autoReconnect: true,
autoMark: true
});
/*
bot respond commands
giggle-bot listens on message events incoming and looks for
specific string patterns if found giggle-bot responds based on
particular pattern
*/
bot.respondTo('hello', (message, channel, user) => {
bot.send(' Hello to you too.', channel);
},
true);
bot.respondTo('joke', (message, channel, user) => {
let tokenArr = message.text.split(' ');
if (tokenArr.length === 1) {
/*
making giggle bot send joke to channel if no argument is specified
eg.
bot.send('Sorry, somebody forgot to put some jokes in me, ok', channel);
write send message code here
*/
}
else {
/*
taking argument and cracking a joke with the given argument
eg.
let args = tokenArr.slice(1);
bot.send(`${args[0]} looks like ..., arrhh I need some damn jokes`, channel);
write send message code here
*/
}
},
true);
// api wrapper functions can go here (optional)