김연준

Seperating functions file to Router folder and exporting to index.js

File mode changed
1 const SlackBot = require('slackbots'); 1 const SlackBot = require('slackbots');
2 const axios = require('axios'); 2 const axios = require('axios');
3 +const route = require('./Routers/route');
3 4
4 const bot = new SlackBot({ 5 const bot = new SlackBot({
5 token : "xoxb-582582124755-587875604934-rRhFVlXlB0StEMnlrmsQlcac", 6 token : "xoxb-582582124755-587875604934-rRhFVlXlB0StEMnlrmsQlcac",
...@@ -34,67 +35,32 @@ bot.on('message', (data) => { ...@@ -34,67 +35,32 @@ bot.on('message', (data) => {
34 // Responding to Data 35 // Responding to Data
35 function handleMessage(message){ 36 function handleMessage(message){
36 if(message.includes('chucknorris')){ 37 if(message.includes('chucknorris')){
37 - chuckJoke(); 38 + route.chuckJoke()
39 + .then((err, res)=>{
40 + if(err)throw err;
41 + res("ChuckJoke function activated");
42 + });
38 } 43 }
39 else if(message.includes(' yomama')){ 44 else if(message.includes(' yomama')){
40 - yoMamaJoke(); 45 + route.yoMamaJoke()
46 + .then((err, res)=>{
47 + if(err)throw err;
48 + res("yoMamaJoke function activated");
49 +});
41 } 50 }
42 else if(message.includes(' random')){ 51 else if(message.includes(' random')){
43 - randomJoke(); 52 + route.randomJoke()
44 - } 53 + .then((err, res)=>{
45 - else if(message.includes(' help')){ 54 + if(err)throw err
46 - runHelp(); 55 + res("randomJoke function activated");
47 - }
48 -}
49 -
50 -
51 -// Tell a Chuck Norris Joke
52 -function chuckJoke(){
53 - axios.get('http://api.icndb.com/jokes/random/')
54 - .then(res =>{
55 - const joke = res.data.value.joke;
56 -
57 - const face = {
58 - icon_emoji: ':laughing:'
59 - };
60 -
61 - bot.postMessageToChannel('everyone', `Chuck Norris: ${joke}`,face);
62 - bot.postMessageToChannel('full-stack-web', `Yo mama: ${joke}`,face);
63 - bot.postMessageToChannel('bot_test', `Yo mama: ${joke}`,face);
64 }); 56 });
65 } 57 }
66 58
67 -// Tell a yomama Joke 59 + else if(message.includes(' help')){
68 -function yoMamaJoke(){ 60 + route.runHelp()
69 - axios.get('http://api.yomomma.info/') 61 + .then((err, res)=>{
70 - .then(res =>{ 62 + if(err)throw err
71 - const joke = res.data.joke; 63 + res(" function activated");
72 -
73 - const face = {
74 - icon_emoji: ':laughing:'
75 - };
76 -
77 - bot.postMessageToChannel('everyone', `Yo mama: ${joke}`,face);
78 - bot.postMessageToChannel('full-stack-web', `Yo mama: ${joke}`,face);
79 - bot.postMessageToChannel('bot_test', `Yo mama: ${joke}`,face);
80 -
81 }); 64 });
82 -}
83 -//Tell random joke
84 -function randomJoke(){
85 - const rand = Math.floor(Math.random() * 2) +1;
86 - if(rand ===1){
87 - chuckJoke();
88 - }
89 - else if(rand === 2){
90 - yoMamaJoke();
91 } 65 }
92 } 66 }
...\ No newline at end of file ...\ No newline at end of file
93 -function runHelp(){
94 - const face = {
95 - icon_emoji: ':question:'
96 - };
97 -
98 - bot.postMessageToChannel('everyone', "Type @joker and write a joke that you would like\n ex- @joker random",face);
99 - bot.postMessageToChannel('full-stack-web', "Type @joker and write a joke that you would like\n ex- @joker random",face);
100 -}
...\ No newline at end of file ...\ No newline at end of file
......