-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (44 loc) · 1.13 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
const SlackBot = require('slackbots');
const axios = require('axios');
const bot = new SlackBot({
token: 'xoxb-622716498160-624536974679-6ZqJ9w6s3OSyXWjHtLd9r4Qk',
name: 'HackerSalt'
});
//Start Handler
bot.on('start', () => {
const params = {
icon_emoji: ':wave:'
};
bot.postMessageToChannel('general', 'Get ready for some salt!', params);
});
//Error Handler
bot.on('error', err => {
console.log(err);
});
//Message Handler
bot.on('message', data => {
if (data.type !== 'message') {
return;
}
handleMessage(data.text);
});
//Respond to Data
function handleMessage(message) {
const hacker = message;
findSalt(hacker);
}
//Tell
function findSalt(hacker) {
axios
.get(`https://hacker-salt.herokuapp.com/api/hacker/${hacker}`)
.then(res => {
const comment = res.data.top_cmnts_s.c_0.cleaned_comment;
const params = {
icon_emoji: ':speaking_head_in_silhoute:'
};
bot.postMessageToChannel('general', `${hacker}'s saltiest comment: "${comment}" Check out ${hacker}'s saltiness at https://www.hackersalt.com/${hacker}`, params);
})
.catch(err => {
cancel();
});
}