오원석

r.code

...@@ -199,11 +199,17 @@ randomJoke= (user_channel)=>{ ...@@ -199,11 +199,17 @@ randomJoke= (user_channel)=>{
199 //After finding one joke, use promise to run codes synchronously 199 //After finding one joke, use promise to run codes synchronously
200 user.then(function(total){ 200 user.then(function(total){
201 question = total.setup; 201 question = total.setup;
202 - joke=total.punchline; 202 + bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
203 - ques_and_joke=question+'\n'+joke+':stuck_out_tongue_winking_eye::laughing:'; 203 + console.log("질문 불려짐");
204 - //Ask the question first by extracting 'setup' section from api format 204 + return total;
205 - bot.postMessageToChannel(user_channel, ques_and_joke, emoji.emojis('laughing')); 205 + })
206 - console.log('Random joke~~~'); 206 + .then((all)=>{
207 + joke=all.punchline;
208 + //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
209 + setTimeout(function secondFunction(){
210 + bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
211 + console.log("허무개그 전송~~~~~~!");
212 + },3000);
207 }) 213 })
208 //close mongodb 214 //close mongodb
209 client.close(); 215 client.close();
...@@ -242,10 +248,17 @@ generalJoke= (user_channel)=>{ ...@@ -242,10 +248,17 @@ generalJoke= (user_channel)=>{
242 //if the random picked api type is not general execute the function from the start to get another format for general type 248 //if the random picked api type is not general execute the function from the start to get another format for general type
243 user.then(function(total){ 249 user.then(function(total){
244 question = total.setup; 250 question = total.setup;
245 - joke = total.punchline; 251 + bot.postMessageToChannel(user_channel,question,emoji.emojis('laughing'));
246 - ques_and_joke=question+'\n'+joke+':stuck_out_tongue_winking_eye::laughing:'; 252 + console.log('질문 불려짐');
247 - bot.postMessageToChannel(user_channel,ques_and_joke,emoji.emojis('laughing')); 253 + return total;
248 - console.log("General Joke~~~~"); 254 + })
255 + .then((all)=>{
256 + joke=all.punchline;
257 + //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
258 + setTimeout(function secondFunction(){
259 + bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
260 + console.log("허무개그 전송~~~~~~!");
261 + },3000);
249 }) 262 })
250 client.close(); 263 client.close();
251 }) 264 })
...@@ -262,10 +275,17 @@ programmingJoke= (user_channel)=>{ ...@@ -262,10 +275,17 @@ programmingJoke= (user_channel)=>{
262 user = result; 275 user = result;
263 user.then(function(total){ 276 user.then(function(total){
264 question = total.setup; 277 question = total.setup;
265 - joke = total.punchline; 278 + bot.postMessageToChannel(user_channel,question,emoji.emojis('laughing'));
266 - ques_and_joke = question+'\n'+joke+':stuck_out_tongue_winking_eye::laughing:'; 279 + console.log("질문 불려짐");
267 - bot.postMessageToChannel(user_channel,ques_and_joke,emoji.emojis('laughing')); 280 + return total;
268 - console.log("Programming Joke~~~"); 281 + })
282 + .then((all)=>{
283 + joke=all.punchline;
284 + //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
285 + setTimeout(function secondFunction(){
286 + bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
287 + console.log("허무개그 전송~~~~~~!");
288 + },3000);
269 }) 289 })
270 client.close(); 290 client.close();
271 }) 291 })
...@@ -279,17 +299,16 @@ Funnystory= (user_channel)=>{ ...@@ -279,17 +299,16 @@ Funnystory= (user_channel)=>{
279 if (err) throw err; 299 if (err) throw err;
280 var db = client.db('FunnyStoryapi'); 300 var db = client.db('FunnyStoryapi');
281 301
282 -
283 random = getRandomInt(1,201); 302 random = getRandomInt(1,201);
284 result = db.collection('FunnyStory').findOne({id: random}); 303 result = db.collection('FunnyStory').findOne({id: random});
285 user = result; 304 user = result;
286 //if the random picked api type is not general execute the function from the start to get another format for general type 305 //if the random picked api type is not general execute the function from the start to get another format for general type
287 user.then(function(total){ 306 user.then(function(total){
288 - category = total.category 307 + cate = total.category;
289 - story=total.body; 308 + story = total.body;
290 - category_story=category+'\n'+story+':stuck_out_tongue_winking_eye::laughing:'; 309 + category_story=cate+'\n'+story+':stuck_out_tongue_winking_eye::laughing:';
291 - bot.postMessageToChannel(user_channel, category, emoji.emojis('smiliey')); 310 + bot.postMessageToChannel(user_channel, category_story, emoji.emojis('smiliey'));
292 - console.log("Funny story~~~"); 311 + console.log("Funny story~~~");
293 }) 312 })
294 client.close(); 313 client.close();
295 }) 314 })
...@@ -308,10 +327,17 @@ redditJoke= (user_channel)=>{ ...@@ -308,10 +327,17 @@ redditJoke= (user_channel)=>{
308 //if the random picked api type is not general execute the function from the start to get another format for general type 327 //if the random picked api type is not general execute the function from the start to get another format for general type
309 user.then(function(total){ 328 user.then(function(total){
310 title = total.title; 329 title = total.title;
311 - joke=total.body; 330 + bot.postMessageToChannel(user_channel, title, emoji.emojis('smiliey'));
312 - title_joke=title+'\n'+joke+':stuck_out_tongue_winking_eye::laughing:'; 331 + console.log("질문 불려짐");
313 - bot.postMessageToChannel(user_channel, title_joke, emoji.emojis('smiliey')); 332 + return total;
314 - console.log("reddit Joke~~~"); 333 + })
334 + .then((all)=>{
335 + joke=all.body;
336 + //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
337 + setTimeout(function secondFunction(){
338 + bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
339 + console.log("허무개그 전송~~~~~~!");
340 + },3000);
315 }) 341 })
316 client.close(); 342 client.close();
317 }) 343 })
...@@ -327,10 +353,16 @@ knockknockJoke= (user_channel)=>{ ...@@ -327,10 +353,16 @@ knockknockJoke= (user_channel)=>{
327 user = result; 353 user = result;
328 user.then(function(total){ 354 user.then(function(total){
329 question = total.setup; 355 question = total.setup;
330 - joke = total.punchline; 356 + bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
331 - ques_and_joke = question+'\n'+joke+':stuck_out_tongue_winking_eye::laughing:'; 357 + console.log("질문 불려짐");
332 - bot.postMessageToChannel(user_channel, ques_and_joke, emoji.emojis('laughing')); 358 + return total;
333 - console.log("Knock-Knock joke~~~"); 359 + })
360 + .then((all)=>{
361 + joke=all.punchline;
362 + setTimeout(function secondFunction(){
363 + bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
364 + console.log("허무개그 전송~~~~~~!");
365 + },3000);
334 }) 366 })
335 client.close(); 367 client.close();
336 }) 368 })
......