Showing
2 changed files
with
39 additions
and
48 deletions
... | @@ -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,8 +255,38 @@ programmingJoke= (user_channel)=>{ | ... | @@ -254,8 +255,38 @@ 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 | + |
260 | +//Function for giving out random joke after filtering only reddit jokes | ||
261 | +Funnystory= (user_channel)=>{ | ||
262 | + MongoClient.connect(url, function (err, client){ | ||
263 | + if (err) throw err; | ||
264 | + var db = client.db('FunnyStoryapi'); | ||
265 | + | ||
266 | + | ||
267 | + random = getRandomInt(200); | ||
268 | + result = db.collection('FunnyStory').findOne({id: random}); | ||
269 | + 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 | ||
271 | + user.then(function(total){ | ||
272 | + category = total.category | ||
273 | + bot.postMessageToChannel(user_channel, category, emoji.emojis('smiliey')); | ||
274 | + console.log("이야기 카테고리") | ||
275 | + return total; | ||
276 | + }) | ||
277 | + .then((all)=>{ | ||
278 | + story = all.body; | ||
279 | + bot.postMessageToChannel(user_channel, `${story}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing')) | ||
280 | + console.log("이야기 시작!"); | ||
281 | + | ||
282 | + }) | ||
283 | + client.close(); | ||
284 | + }) | ||
285 | + }; | ||
286 | + | ||
287 | + | ||
288 | +//Function for giving out random joke after filtering only reddit jokes | ||
289 | +redditJoke= (user_channel)=>{ | ||
259 | MongoClient.connect(url, function (err, client){ | 290 | MongoClient.connect(url, function (err, client){ |
260 | if (err) throw err; | 291 | if (err) throw err; |
261 | var db = client.db('redditjoke'); | 292 | var db = client.db('redditjoke'); |
... | @@ -275,12 +306,11 @@ programmingJoke= (user_channel)=>{ | ... | @@ -275,12 +306,11 @@ programmingJoke= (user_channel)=>{ |
275 | joke = all.body; | 306 | joke = all.body; |
276 | bot.postMessageToChannel(user_channel, `${joke}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing')) | 307 | bot.postMessageToChannel(user_channel, `${joke}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing')) |
277 | console.log("정답은~~"); | 308 | console.log("정답은~~"); |
278 | - return joke; | 309 | + |
279 | }) | 310 | }) |
280 | client.close(); | 311 | client.close(); |
281 | }) | 312 | }) |
282 | }; | 313 | }; |
283 | - | ||
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 | ... | ... |
-
Please register or login to post a comment