오원석

random print userjoke

...@@ -6,6 +6,7 @@ const url = 'mongodb://13.124.65.242:27017/'; ...@@ -6,6 +6,7 @@ const url = 'mongodb://13.124.65.242:27017/';
6 const url2 = 'mongodb://13.124.65.242:27017/userdb'; 6 const url2 = 'mongodb://13.124.65.242:27017/userdb';
7 const fs=require('fs'); 7 const fs=require('fs');
8 message_recieved = 0; 8 message_recieved = 0;
9 +ary_size=0;
9 10
10 exports.startbot = ()=>{ 11 exports.startbot = ()=>{
11 // Get authorization to use the slackbot 12 // Get authorization to use the slackbot
...@@ -174,13 +175,13 @@ function MakeJoke(message,user_channel){ ...@@ -174,13 +175,13 @@ function MakeJoke(message,user_channel){
174 }); 175 });
175 176
176 }) 177 })
177 - // var json=JSON.stringify(obj); 178 + var json=JSON.stringify(obj);
178 - // fs.writeFile(path,json,'utf8',function(err){ 179 + fs.writeFile(path,json,'utf8',function(err){
179 - // if(err){ 180 + if(err){
180 - // console.log(err); 181 + console.log(err);
181 - // } 182 + }
182 - // console.log('완료'); 183 + console.log('완료');
183 - // }); 184 + });
184 } 185 }
185 }); 186 });
186 comment="Sucess making joke!!:+1::thumbsup:\nWhen you want to show your joke, please enter @jokebot tell-me-userjoke"; 187 comment="Sucess making joke!!:+1::thumbsup:\nWhen you want to show your joke, please enter @jokebot tell-me-userjoke";
...@@ -267,35 +268,63 @@ UserMakeJoke= (message,user_channel)=>{ ...@@ -267,35 +268,63 @@ UserMakeJoke= (message,user_channel)=>{
267 if (err) throw err; 268 if (err) throw err;
268 //go into database name jokeapi 269 //go into database name jokeapi
269 var db = client.db('userdb'); 270 var db = client.db('userdb');
270 - ary_size=0;
271 var array = db.collection('user').find({type: user}).toArray(function(err,docs){ 271 var array = db.collection('user').find({type: user}).toArray(function(err,docs){
272 if(err){ 272 if(err){
273 callback(err,null); 273 callback(err,null);
274 - return ; 274 + return;
275 } 275 }
276 ary_size=docs.length; 276 ary_size=docs.length;
277 console.log(docs.length); 277 console.log(docs.length);
278 - }); 278 + var random=getRandomInt(1,ary_size+1);
279 + console.log(random);
280 + var result=docs[random-1];
281 + user = result;
282 + console.log(user);
279 283
280 - // var random=getRandomInt(1,ar+1); 284 + question = user.setup;
281 - //console.log(array.); 285 + joke=user.punchline;
282 - var result=db.collection('user').findOne({type : user ,id : random});
283 - user = result;
284 - //After finding one joke, use promise to run codes synchronously
285 - user.then(function(total){
286 - question = total.setup;
287 bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing')); 286 bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
288 console.log("질문 불려짐"); 287 console.log("질문 불려짐");
289 - return total; 288 + setTimeout(function secondFunction(){
290 - })
291 - .then((all)=>{
292 - joke=all.punchline;
293 - //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
294 - setTimeout(function secondFunction(){
295 bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing')); 289 bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
296 console.log("허무개그 전송~~~~~~!"); 290 console.log("허무개그 전송~~~~~~!");
297 },3000); 291 },3000);
298 - }) 292 + // //After finding one joke, use promise to run codes synchronously
293 + // user.then(function(total){
294 + // question = total.setup;
295 + // bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
296 + // console.log("질문 불려짐");
297 + // return total;
298 + // })
299 + // .then((all)=>{
300 + // joke=all.punchline;
301 + // //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
302 + // setTimeout(function secondFunction(){
303 + // bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
304 + // console.log("허무개그 전송~~~~~~!");
305 + // },3000);
306 + // })
307 + });
308 +
309 + //var random=getRandomInt(1,ary_size+1);
310 + // console.log(ary_size);
311 + // var result=db.collection('user').findOne({type : user ,id : random});
312 + // user = result;
313 + // //After finding one joke, use promise to run codes synchronously
314 + // user.then(function(total){
315 + // question = total.setup;
316 + // bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
317 + // console.log("질문 불려짐");
318 + // return total;
319 + // })
320 + // .then((all)=>{
321 + // joke=all.punchline;
322 + // //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
323 + // setTimeout(function secondFunction(){
324 + // bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
325 + // console.log("허무개그 전송~~~~~~!");
326 + // },3000);
327 + // })
299 //close mongodb 328 //close mongodb
300 client.close(); 329 client.close();
301 }) 330 })
......
1 -{"table":[{"id":1,"type":"UJZF5UTMX","setup":" ok","punchline":" okkk"},{"id":2,"type":"UJZF5UTMX","setup":" man","punchline":" woman"},{"id":3,"type":"UJZF5UTMX","setup":" kim ","punchline":" minuk"},{"id":4,"type":"UH9RRHSTG","setup":" 팔에 비빔면 뭍으면 빨리 닦아야됨 왜?","punchline":" 팔도비빔면됨"},{"id":5,"type":"UH9RRHSTG","setup":" 팔에 비빔소스 묻으면 빨리 닦아야함","punchline":" 팔도비빔면되서"},{"id":6,"type":"UH9RRHSTG","setup":" check","punchline":" working"},{"id":7,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":8,"type":"UJP8BFSNP","setup":" kim","punchline":" yeonjun"},{"id":9,"type":"UJP8BFSNP","setup":" hi","punchline":" hello"},{"id":10,"type":"UJP8BFSNP","setup":" hello","punchline":" hi"},{"id":11,"type":"UJP8BFSNP","setup":" bye","punchline":" bi"},{"id":12,"type":"UJP8BFSNP","setup":" kkkkk","punchline":" jjjjj"},{"id":13,"type":"UJP8BFSNP","setup":" oh","punchline":"wonserk"},{"id":14,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":15,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":16,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":17,"type":"UJP8BFSNP","setup":" kim","punchline":" yeonjun"},{"id":18,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":19,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":20,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":21,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":22,"type":"UJP8BFSNP","setup":" kim","punchline":"yeonjun"},{"id":23,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":24,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":25,"type":"UJP8BFSNP","setup":" kim","punchline":" yeonjun"},{"id":26,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":27,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":28,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"}]}
...\ No newline at end of file ...\ No newline at end of file
1 +{"table":[{"id":1,"type":"UJZF5UTMX","setup":" ok","punchline":" okkk"},{"id":2,"type":"UJZF5UTMX","setup":" man","punchline":" woman"},{"id":3,"type":"UJZF5UTMX","setup":" kim ","punchline":" minuk"},{"id":4,"type":"UH9RRHSTG","setup":" 팔에 비빔면 뭍으면 빨리 닦아야됨 왜?","punchline":" 팔도비빔면됨"},{"id":5,"type":"UH9RRHSTG","setup":" 팔에 비빔소스 묻으면 빨리 닦아야함","punchline":" 팔도비빔면되서"},{"id":6,"type":"UH9RRHSTG","setup":" check","punchline":" working"},{"id":7,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":8,"type":"UJP8BFSNP","setup":" kim","punchline":" yeonjun"},{"id":9,"type":"UJP8BFSNP","setup":" hi","punchline":" hello"},{"id":10,"type":"UJP8BFSNP","setup":" hello","punchline":" hi"},{"id":11,"type":"UJP8BFSNP","setup":" bye","punchline":" bi"},{"id":12,"type":"UJP8BFSNP","setup":" kkkkk","punchline":" jjjjj"},{"id":13,"type":"UJP8BFSNP","setup":" oh","punchline":"wonserk"},{"id":14,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":15,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":16,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":17,"type":"UJP8BFSNP","setup":" kim","punchline":" yeonjun"},{"id":18,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":19,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":20,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":21,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":22,"type":"UJP8BFSNP","setup":" kim","punchline":"yeonjun"},{"id":23,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":24,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":25,"type":"UJP8BFSNP","setup":" kim","punchline":" yeonjun"},{"id":26,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":27,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":28,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":29,"type":"UJP8BFSNP","setup":" oh","punchline":" wonserk"},{"id":30,"type":"UJP8BFSNP","setup":" kim","punchline":" minuk"},{"id":31,"type":"UJP8BFSNP","setup":" kim","punchline":" yeonjun"},{"id":32,"type":"UJP8BFSNP","setup":" open","punchline":" source"}]}
...\ No newline at end of file ...\ No newline at end of file
......