-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
118 lines (93 loc) · 3.3 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict'
const fetch = require('node-fetch');
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('giggle help', (message, channel, user) => {
bot.send('- To make me crack a random joke type \`joke\`\n\
- To make me joke about a friend or anyone, type \`joke <username>\`\n\
- For my cool awesome selfie type \`gigpic\`\n\
- To display this message again type \`giggle help\`\n\
- There is an easter egg for you. Find it to unleash my greatest power', 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
*/
let url = 'https://api.chucknorris.io/jokes/random';
fetch(url)
.then(function(res) {
return res.json();
}).then(function(json) {
bot.send(json.value, channel);
});
} 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
*/
let url = 'https://api.chucknorris.io/jokes/random';
let args = tokenArr.slice(1);
fetch(url)
.then(function(res) {
return res.json();
}).then(function(json) {
let joke = json.value.replace(/(chuck norris|chuck|chucky)/gi, args[0]);
bot.send(joke, channel);
});
}
},
true);
bot.respondTo('mom', (message, channel, user) => {
let tokenArr = message.text.split(' ');
if (tokenArr.length === 1) {
let url = 'http://api.yomomma.info/';
function getJoke() {
fetch(url)
.then(function(res) {
return res.json();
}).then(function(json) {
bot.send(json.joke, channel);
});
}
setTimeout(getJoke, 2000);
} else {
bot.send("It's not nice to target a friend's MOMMA!!!! Even Giggle has his limits!!", channel);
}
}, true);
bot.respondTo('gigpic', (message, channel, user) => {
let tokenArr = message.text.split(' ');
if (tokenArr.length === 1) {
function selfie() {
bot.send("http://www.scenictrail.com/LonghornSheep_2.jpg", channel);
}
setTimeout(selfie, 2000);
} else {
bot.send("huh", channel);
}
}, true);