index.js
1.44 KB
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
const SlackBot = require('slackbots');
const axios = require('axios');
const route = require('./Routers/route');
const bot = new SlackBot({
token : "xoxb-582582124755-587875604934-rRhFVlXlB0StEMnlrmsQlcac",
name : "Joker"
});
// Start Handler
bot.on('start', () =>{
const face = {
icon_emoji: ':laughing:'
};
bot.postMessageToChannel('everyone', 'Feeling tired??? Have some fun with @Joker!'
, face);
});
// Error Handler
bot.on('error', (err) => console.log(err));
//Message Handler
bot.on('message', (data) => {
if(data.type !== 'message'){
return;
}
console.log(data);
handleMessage(data.text);
});
// Responding to Data
function handleMessage(message){
if(message.includes('chucknorris')){
route.chuckJoke()
.then((err, res)=>{
if(err)throw err;
res("ChuckJoke function activated");
});
}
else if(message.includes(' yomama')){
route.yoMamaJoke()
.then((err, res)=>{
if(err)throw err;
res("yoMamaJoke function activated");
});
}
else if(message.includes(' random')){
route.randomJoke()
.then((err, res)=>{
if(err)throw err
res("randomJoke function activated");
});
}
else if(message.includes(' help')){
route.runHelp()
.then((err, res)=>{
if(err)throw err
res(" function activated");
});
}
}