Showing
1 changed file
with
54 additions
and
57 deletions
... | @@ -7,7 +7,7 @@ const url = 'mongodb://localhost:27017/'; | ... | @@ -7,7 +7,7 @@ const url = 'mongodb://localhost:27017/'; |
7 | exports.startbot = ()=>{ | 7 | exports.startbot = ()=>{ |
8 | // Get authorization to use the slackbot | 8 | // Get authorization to use the slackbot |
9 | const bot = new SlackBot({ | 9 | const bot = new SlackBot({ |
10 | - token : "xoxb-582582124755-587875604934-86ISu22wmEaDhGWtQmpvumbR", | 10 | + token : "xoxb-582582124755-587875604934-oewQRL6lzHXLkybUrg4CWJVJ", |
11 | name : "Joker" | 11 | name : "Joker" |
12 | }); | 12 | }); |
13 | 13 | ||
... | @@ -36,11 +36,7 @@ bot.on('message', (data) => { | ... | @@ -36,11 +36,7 @@ bot.on('message', (data) => { |
36 | // Responding to Data | 36 | // Responding to Data |
37 | function handleMessage(message, channel, user){ | 37 | function handleMessage(message, channel, user){ |
38 | console.log(message); | 38 | console.log(message); |
39 | - console.log(channel); | ||
40 | - console.log(user); | ||
41 | 39 | ||
42 | - if(message === `${user} hi`) | ||
43 | - bot.postMessageToChannel('everyone', "Tell you what??? :nomouth:", embarrased); | ||
44 | if(message.includes(' tell me')){ | 40 | if(message.includes(' tell me')){ |
45 | if(message.includes(' knock')){ | 41 | if(message.includes(' knock')){ |
46 | knockknockJoke(); | 42 | knockknockJoke(); |
... | @@ -50,7 +46,9 @@ function handleMessage(message, channel, user){ | ... | @@ -50,7 +46,9 @@ function handleMessage(message, channel, user){ |
50 | } | 46 | } |
51 | 47 | ||
52 | else if(message.includes(' random')){ | 48 | else if(message.includes(' random')){ |
53 | - console.log(message); | 49 | + randomJoke(); |
50 | + } | ||
51 | + else if(message.includes(' a joke')){ | ||
54 | randomJoke(); | 52 | randomJoke(); |
55 | } | 53 | } |
56 | 54 | ||
... | @@ -73,7 +71,7 @@ function handleMessage(message, channel, user){ | ... | @@ -73,7 +71,7 @@ function handleMessage(message, channel, user){ |
73 | else if(message.includes(' help')){ | 71 | else if(message.includes(' help')){ |
74 | 72 | ||
75 | } | 73 | } |
76 | - else if(message.includes(' what jokes' || ' What jokes' || ' which jokes')){ | 74 | + else if(message.includes(' what jokes')){ |
77 | jokeTypes = ["general", 'programming', 'knock-knock']; | 75 | jokeTypes = ["general", 'programming', 'knock-knock']; |
78 | const face = { | 76 | const face = { |
79 | icon_emoji: ':thumbsup:' | 77 | icon_emoji: ':thumbsup:' |
... | @@ -134,63 +132,63 @@ randomJoke= ()=>{ | ... | @@ -134,63 +132,63 @@ randomJoke= ()=>{ |
134 | const face = { | 132 | const face = { |
135 | icon_emoji: ':laughing:' | 133 | icon_emoji: ':laughing:' |
136 | }; | 134 | }; |
137 | - function secondFunction(channel){ | 135 | + setTimeout(function secondFunction(){ |
138 | - setTimeout(bot.postMessageToChannel(channel, joke, face, 7000)); | 136 | + bot.postMessageToChannel('everyone', `${joke}:stuck_out_tongue_winking_eye::laughing:`, face) |
139 | console.log( "허무개그 전송~~~~!") | 137 | console.log( "허무개그 전송~~~~!") |
140 | - } | 138 | + }, 3000); |
141 | - secondFunction('everyone'); | 139 | + |
142 | }) | 140 | }) |
143 | client.close(); | 141 | client.close(); |
144 | }) | 142 | }) |
145 | } | 143 | } |
146 | generalJoke= ()=>{ | 144 | generalJoke= ()=>{ |
147 | - MongoClient.connect(url, function (err, client){ | 145 | + MongoClient.connect(url, function (err, client){ |
148 | if (err) throw err; | 146 | if (err) throw err; |
149 | var db = client.db('jokeapi'); | 147 | var db = client.db('jokeapi'); |
150 | 148 | ||
151 | json_max = 376; | 149 | json_max = 376; |
152 | function getRandomInt() { | 150 | function getRandomInt() { |
153 | min = Math.ceil(1); | 151 | min = Math.ceil(1); |
154 | - max = Math.floor(376); | 152 | + max = Math.floor(json_max); |
155 | return Math.floor(Math.random() * (max - min + 1)) + min; | 153 | return Math.floor(Math.random() * (max - min + 1)) + min; |
156 | } | 154 | } |
157 | random = getRandomInt(); | 155 | random = getRandomInt(); |
158 | result = db.collection('jokes').findOne({id: random}); | 156 | result = db.collection('jokes').findOne({id: random}); |
159 | - | ||
160 | user = result; | 157 | user = result; |
161 | user.then(function(total){ | 158 | user.then(function(total){ |
162 | - if(total.type != "general"){ | 159 | + if(total.type === "general"){ |
163 | - client.close(); | 160 | + question = total.setup; |
164 | - programmingJoke(); | 161 | + joke = total.punchline; |
165 | - } | 162 | + channel = 'everyone'; |
166 | - else if(total.type === "general"){ | 163 | + const face = { |
167 | - question = total.setup; | 164 | + icon_emoji: ':laughing:' |
168 | - joke = total.punchline; | 165 | + }; |
169 | - } | 166 | + ques_and_joke = [question, joke, face, channel]; |
170 | - const face = { | 167 | + return ques_and_joke; |
171 | - icon_emoji: ':laughing:' | 168 | + } |
172 | - }; | 169 | + else if(total.type != "general"){ |
173 | - function firstFunction(channel){ | 170 | + client.close(); |
174 | - bot.postMessageToChannel(channel, joke, face); | 171 | + generalJoke(); |
175 | - console.log("일반 허무개그 전송~~~~!"); | 172 | + } |
176 | - } | ||
177 | 173 | ||
178 | - function secondFunction(channel, callback){ | 174 | + }) |
179 | - bot.postMessageToChannel(channel, question, face); | 175 | + .then((joke_info)=>{ |
180 | - console.log("일반 질문 불려짐") | 176 | + function askQuestion(){ |
181 | - firstFunction(channel); | 177 | + bot.postMessageToChannel(joke_info[3], joke_info[0], joke_info[2]); |
178 | + console.log("일반 질문 불려짐"); | ||
182 | } | 179 | } |
183 | - secondFunction('everyone',firstFunction); | 180 | + askQuestion(); |
184 | - // bot.postMessageToChannel('everyone', question, face); | 181 | + return joke_info; |
185 | - // bot.postMessageToChannel('full-stack-web', question, joke, face); | 182 | + }) |
186 | - // bot.postMessageToChannel('bot_test', question, face); | 183 | + .then((info)=>{ |
187 | - // bot.postMessageToChannel('everyone', joke, face); | 184 | + setTimeout(function secondFunction(){ |
188 | - // bot.postMessageToChannel('full-stack-web', joke, face); | 185 | + bot.postMessageToChannel(info[3], `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, info[2]) |
189 | - // bot.postMessageToChannel('bot_test', joke, face); | 186 | + console.log( "허무개그 전송~~~~!") |
187 | + }, 3000); | ||
190 | }) | 188 | }) |
191 | client.close(); | 189 | client.close(); |
192 | }) | 190 | }) |
193 | - } | 191 | + }; |
194 | programmingJoke= ()=>{ | 192 | programmingJoke= ()=>{ |
195 | MongoClient.connect(url, function (err, client){ | 193 | MongoClient.connect(url, function (err, client){ |
196 | if (err) throw err; | 194 | if (err) throw err; |
... | @@ -237,8 +235,10 @@ programmingJoke= ()=>{ | ... | @@ -237,8 +235,10 @@ programmingJoke= ()=>{ |
237 | return joke_info; | 235 | return joke_info; |
238 | }) | 236 | }) |
239 | .then((info)=>{ | 237 | .then((info)=>{ |
240 | - bot.postMessageToChannel(info[3], info[1], info[2]); | 238 | + setTimeout(function secondFunction(){ |
241 | - return; | 239 | + bot.postMessageToChannel(info[3], `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, info[2]) |
240 | + console.log( "허무개그 전송~~~~!") | ||
241 | + }, 3000); | ||
242 | }) | 242 | }) |
243 | client.close(); | 243 | client.close(); |
244 | }) | 244 | }) |
... | @@ -274,12 +274,6 @@ knockknockJoke= ()=>{ | ... | @@ -274,12 +274,6 @@ knockknockJoke= ()=>{ |
274 | knockknockJoke(); | 274 | knockknockJoke(); |
275 | } | 275 | } |
276 | 276 | ||
277 | - // bot.postMessageToChannel('everyone', question, face); | ||
278 | - // bot.postMessageToChannel('full-stack-web', question, joke, face); | ||
279 | - // bot.postMessageToChannel('bot_test', question, face); | ||
280 | - // bot.postMessageToChannel('everyone', joke, face); | ||
281 | - // bot.postMessageToChannel('full-stack-web', joke, face); | ||
282 | - // bot.postMessageToChannel('bot_test', joke, face); | ||
283 | }) | 277 | }) |
284 | .then((joke_info)=>{ | 278 | .then((joke_info)=>{ |
285 | function askQuestion(){ | 279 | function askQuestion(){ |
... | @@ -290,19 +284,22 @@ knockknockJoke= ()=>{ | ... | @@ -290,19 +284,22 @@ knockknockJoke= ()=>{ |
290 | return joke_info; | 284 | return joke_info; |
291 | }) | 285 | }) |
292 | .then((info)=>{ | 286 | .then((info)=>{ |
293 | - bot.postMessageToChannel(info[3], info[1], info[2]); | 287 | + setTimeout(function secondFunction(){ |
288 | + bot.postMessageToChannel(info[3], `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, info[2]) | ||
289 | + console.log( "허무개그 전송~~~~!") | ||
290 | + }, 3000); | ||
294 | }) | 291 | }) |
295 | client.close(); | 292 | client.close(); |
296 | }) | 293 | }) |
297 | } | 294 | } |
298 | runHelp = () =>{ | 295 | runHelp = () =>{ |
299 | - function runhelp(){ | 296 | + |
300 | - const face = { | 297 | + const face = { |
301 | - icon_emoji: ':question:' | 298 | + icon_emoji: ':question:' |
302 | - }; | 299 | + }; |
303 | - comment = "Thanks for using Joker bot!:ghost::ghost:laugh:\nBot info: type '@joker --help'\nBot functions: @joker tell me [something] " | 300 | + comment = "Thanks for using Joker bot!:ghost::ghost:laugh:\nBot info: type '@joker --help'\nBot functions: @joker tell me [something] " |
304 | - bot.postMessageToChannel('everyone', "Type @joker and write a joke that you would like\n ex- @joker random",face); | 301 | + bot.postMessageToChannel('everyone', "Type @joker and write a joke that you would like\n ex- @joker random",face); |
305 | - } | 302 | + |
306 | } | 303 | } |
307 | } | 304 | } |
308 | 305 | ... | ... |
-
Please register or login to post a comment