김민욱

db_control_red

...@@ -80,10 +80,8 @@ bot.on('message', (data) => { ...@@ -80,10 +80,8 @@ bot.on('message', (data) => {
80 // Responding to Data 80 // Responding to Data
81 function handleMessage(message, current_channel){ 81 function handleMessage(message, current_channel){
82 console.log(message); 82 console.log(message);
83 - var test = -1;
84 //Handles message response depending on the user message 83 //Handles message response depending on the user message
85 if(message.includes(' tell me') || message.includes(' Tell me')){ 84 if(message.includes(' tell me') || message.includes(' Tell me')){
86 - test =1;
87 if(message.includes(' knock')){ 85 if(message.includes(' knock')){
88 knockknockJoke(current_channel); 86 knockknockJoke(current_channel);
89 } 87 }
...@@ -101,14 +99,17 @@ function handleMessage(message, current_channel){ ...@@ -101,14 +99,17 @@ function handleMessage(message, current_channel){
101 else if(message.includes(' reddit')){ 99 else if(message.includes(' reddit')){
102 redditJoke(current_channel); 100 redditJoke(current_channel);
103 } 101 }
102 + else if(message.includes(' funny story')){
103 + Funnystory(current_channel);
104 + }
104 else if(message.includes(' me')){ 105 else if(message.includes(' me')){
105 - comment = "Please use @joker --help to know what I can do!:smiliey::smiliey::smiliey:\n You can write type of joke[knock-knock, general, programming]"; 106 + comment = "Please use @joker --help to know what I can do!:smiliey::smiliey::smiliey:\n You can write type of joke[knock-knock, general, programming, funny story, reddit]";
106 bot.postMessageToChannel(current_channel, "Tell you what??? :no_mouth:", emoji.emojis('no_mouth')); 107 bot.postMessageToChannel(current_channel, "Tell you what??? :no_mouth:", emoji.emojis('no_mouth'));
107 bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed')); 108 bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed'));
108 } 109 }
109 } 110 }
110 else if(message.includes(' help')){ 111 else if(message.includes(' help')){
111 - comment = "If you want to start @joker then write [tell me] and write type of joke [knock-knock, general, programming]:smiley:!!"; 112 + comment = "If you want to start @joker then write [tell me] and write type of joke [knock-knock, general, programming, funny story, reddit]:smiley:!!!";
112 bot.postMessageToChannel(current_channel, comment, emoji.emojis('smiliey')); 113 bot.postMessageToChannel(current_channel, comment, emoji.emojis('smiliey'));
113 } 114 }
114 else if(message.includes(' what jokes')){ 115 else if(message.includes(' what jokes')){
...@@ -120,7 +121,7 @@ function handleMessage(message, current_channel){ ...@@ -120,7 +121,7 @@ function handleMessage(message, current_channel){
120 //{ 121 //{
121 // MakeJoke(message); 122 // MakeJoke(message);
122 //} 123 //}
123 - /*else if (test = 0){ 124 + /*else{
124 comment = "Sorry I'm not smart enough to understand this.....\nPlease use @joker help to know what I can do!"; 125 comment = "Sorry I'm not smart enough to understand this.....\nPlease use @joker help to know what I can do!";
125 bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed')); 126 bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed'));
126 }*/ 127 }*/
...@@ -254,33 +255,62 @@ programmingJoke= (user_channel)=>{ ...@@ -254,33 +255,62 @@ programmingJoke= (user_channel)=>{
254 }) 255 })
255 }; 256 };
256 257
257 - //Function for giving out random joke after filtering only reddit jokes 258 +
258 - redditJoke= (user_channel)=>{ 259 +
259 - MongoClient.connect(url, function (err, client){ 260 +//Function for giving out random joke after filtering only reddit jokes
260 - if (err) throw err; 261 +Funnystory= (user_channel)=>{
261 - var db = client.db('redditjoke'); 262 + MongoClient.connect(url, function (err, client){
263 + if (err) throw err;
264 + var db = client.db('FunnyStoryapi');
265 +
262 266
263 - json_max = 70; 267 + random = getRandomInt(200);
264 - random = getRandomInt(json_max); 268 + result = db.collection('FunnyStory').findOne({id: random});
265 - result = db.collection('reddit').findOne({id: random}); 269 + user = result;
266 - user = result; 270 + //if the random picked api type is not general execute the function from the start to get another format for general type
267 - //if the random picked api type is not general execute the function from the start to get another format for general type 271 + user.then(function(total){
268 - user.then(function(total){ 272 + category = total.category
269 - title = total.title; 273 + bot.postMessageToChannel(user_channel, category, emoji.emojis('smiliey'));
270 - bot.postMessageToChannel(user_channel, title, emoji.emojis('smiliey')); 274 + console.log("이야기 카테고리")
271 - console.log("문답형 JOKE")
272 return total; 275 return total;
273 - }) 276 + })
274 - .then((all)=>{ 277 + .then((all)=>{
275 - joke = all.body; 278 + story = all.body;
276 - bot.postMessageToChannel(user_channel, `${joke}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing')) 279 + bot.postMessageToChannel(user_channel, `${story}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing'))
277 - console.log("정답은~~"); 280 + console.log("이야기 시작!");
278 - return joke; 281 +
279 - }) 282 + })
280 - client.close(); 283 + client.close();
281 - }) 284 + })
282 - }; 285 + };
283 - 286 +
287 +
288 +//Function for giving out random joke after filtering only reddit jokes
289 +redditJoke= (user_channel)=>{
290 + MongoClient.connect(url, function (err, client){
291 + if (err) throw err;
292 + var db = client.db('redditjoke');
293 +
294 + json_max = 70;
295 + random = getRandomInt(json_max);
296 + result = db.collection('reddit').findOne({id: random});
297 + user = result;
298 + //if the random picked api type is not general execute the function from the start to get another format for general type
299 + user.then(function(total){
300 + title = total.title;
301 + bot.postMessageToChannel(user_channel, title, emoji.emojis('smiliey'));
302 + console.log("문답형 JOKE")
303 + return total;
304 + })
305 + .then((all)=>{
306 + joke = all.body;
307 + bot.postMessageToChannel(user_channel, `${joke}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing'))
308 + console.log("정답은~~");
309 +
310 + })
311 + client.close();
312 + })
313 + };
284 //Function for giving out random joke after filtering only knock-knock type jokes 314 //Function for giving out random joke after filtering only knock-knock type jokes
285 knockknockJoke= (user_channel)=>{ 315 knockknockJoke= (user_channel)=>{
286 MongoClient.connect(url, function (err, client){ 316 MongoClient.connect(url, function (err, client){
......
...@@ -43,42 +43,3 @@ MongoClient.connect(url,{ useNewUrlParser: true }).then((client) => { ...@@ -43,42 +43,3 @@ MongoClient.connect(url,{ useNewUrlParser: true }).then((client) => {
43 }) 43 })
44 .catch((err) => console.log(err)); 44 .catch((err) => console.log(err));
45 45
46 -
47 -
48 -
49 -
50 -
51 -
52 -
53 -
54 -
55 -
56 -
57 -
58 -// //will encapsulate all that database operations
59 -// const assert = require('assert');
60 -
61 -// exports.insertDocument = (db, document, collection, callback) =>{
62 -// const coll = db.collection(collection);
63 -// return coll.insert(document);
64 -// };
65 -
66 -// exports.findDocuments = (db, collection, input,callback)=>{
67 -// const coll = db.collection(collection);
68 -// return coll.find({"type": input}).toArray();
69 -// }
70 -
71 -// exports.removeDocuments = (db, document , collection, callback)=>{
72 -// const coll = db.collection(collection);
73 -// return coll.deleteone(document);
74 -// }
75 -
76 -// exports.updateDocuments = (db, document , update ,collection, callback)=>{
77 -// const coll = db.collection(collection);
78 -// return coll.updateOne(document, {$set: update}, null);
79 -// }
80 -
81 -// exports.getdata = (db, document, collection, input, callback =>{
82 -// result = findDocuments(db,collection);
83 -// return result;
84 -// })
...\ No newline at end of file ...\ No newline at end of file
......