Showing
2 changed files
with
152 additions
and
155 deletions
... | @@ -7,8 +7,8 @@ const url = 'mongodb://localhost:27017/'; | ... | @@ -7,8 +7,8 @@ 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-651692943605-645515979745-sfNJBLVbIIb86Bz1gfFc7oT2", | 10 | + token : "xoxb-635297512738-635283536771-A03RoBh4Dv8qG1EiLudMpk1f", |
11 | - name : "joker" | 11 | + name : "jokebot" |
12 | }); | 12 | }); |
13 | 13 | ||
14 | // Start the slackbot | 14 | // Start the slackbot |
... | @@ -135,10 +135,8 @@ function MakeJoke(message){ | ... | @@ -135,10 +135,8 @@ function MakeJoke(message){ |
135 | }) | 135 | }) |
136 | } | 136 | } |
137 | //Gets a random integer | 137 | //Gets a random integer |
138 | -function getRandomInt(max_num) { | 138 | +function getRandomInt(start,end) { |
139 | - min = Math.ceil(1); | 139 | + return Math.floor((Math.random() * 100)%(end-start))+start; |
140 | - max = Math.floor(max_num); | ||
141 | - return Math.floor(Math.random() * (max - min + 1)) + min; | ||
142 | } | 140 | } |
143 | 141 | ||
144 | //Function for giving out random joke | 142 | //Function for giving out random joke |
... | @@ -184,23 +182,15 @@ generalJoke= (user_channel)=>{ | ... | @@ -184,23 +182,15 @@ generalJoke= (user_channel)=>{ |
184 | if (err) throw err; | 182 | if (err) throw err; |
185 | var db = client.db('jokeapi'); | 183 | var db = client.db('jokeapi'); |
186 | 184 | ||
187 | - json_max = 376; | 185 | + random = getRandomInt(24,377); |
188 | - random = getRandomInt(json_max); | ||
189 | result = db.collection('jokes').findOne({id: random}); | 186 | result = db.collection('jokes').findOne({id: random}); |
190 | user = result; | 187 | user = result; |
191 | //if the random picked api type is not general execute the function from the start to get another format for general type | 188 | //if the random picked api type is not general execute the function from the start to get another format for general type |
192 | user.then(function(total){ | 189 | user.then(function(total){ |
193 | - if(total.type === "general"){ | 190 | + question = total.setup; |
194 | - question = total.setup; | 191 | + joke = total.punchline; |
195 | - joke = total.punchline; | 192 | + ques_and_joke = [question, joke]; |
196 | - ques_and_joke = [question, joke]; | 193 | + return ques_and_joke; |
197 | - return ques_and_joke; | ||
198 | - } | ||
199 | - else if(total.type != "general"){ | ||
200 | - client.close(); | ||
201 | - generalJoke(user_channel); | ||
202 | - } | ||
203 | - | ||
204 | }) | 194 | }) |
205 | .then((joke_info)=>{ | 195 | .then((joke_info)=>{ |
206 | bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing')); | 196 | bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing')); |
... | @@ -223,22 +213,14 @@ programmingJoke= (user_channel)=>{ | ... | @@ -223,22 +213,14 @@ programmingJoke= (user_channel)=>{ |
223 | if (err) throw err; | 213 | if (err) throw err; |
224 | var db = client.db('jokeapi'); | 214 | var db = client.db('jokeapi'); |
225 | 215 | ||
226 | - json_max = 376; | 216 | + random = getRandomInt(0,19); |
227 | - random = getRandomInt(json_max); | ||
228 | result = db.collection('jokes').findOne({id: random}); | 217 | result = db.collection('jokes').findOne({id: random}); |
229 | user = result; | 218 | user = result; |
230 | user.then(function(total){ | 219 | user.then(function(total){ |
231 | - if(total.type === "programming"){ | 220 | + question = total.setup; |
232 | - question = total.setup; | 221 | + joke = total.punchline; |
233 | - joke = total.punchline; | 222 | + ques_and_joke = [question, joke]; |
234 | - ques_and_joke = [question, joke]; | 223 | + return ques_and_joke; |
235 | - return ques_and_joke; | ||
236 | - } | ||
237 | - else if(total.type != "programming"){ | ||
238 | - client.close(); | ||
239 | - programmingJoke(user_channel); | ||
240 | - } | ||
241 | - | ||
242 | }) | 224 | }) |
243 | .then((joke_info)=>{ | 225 | .then((joke_info)=>{ |
244 | bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing')); | 226 | bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing')); |
... | @@ -316,23 +298,15 @@ knockknockJoke= (user_channel)=>{ | ... | @@ -316,23 +298,15 @@ knockknockJoke= (user_channel)=>{ |
316 | MongoClient.connect(url, function (err, client){ | 298 | MongoClient.connect(url, function (err, client){ |
317 | if (err) throw err; | 299 | if (err) throw err; |
318 | var db = client.db('jokeapi'); | 300 | var db = client.db('jokeapi'); |
319 | - json_max = 61; | ||
320 | 301 | ||
321 | - random = getRandomInt(json_max); | 302 | + random = getRandomInt(19,24); |
322 | result = db.collection('jokes').findOne({id: random}); | 303 | result = db.collection('jokes').findOne({id: random}); |
323 | user = result; | 304 | user = result; |
324 | user.then(function(total){ | 305 | user.then(function(total){ |
325 | - if(total.type === "knock-knock"){ | 306 | + question = total.setup; |
326 | - question = total.setup; | 307 | + joke = total.punchline; |
327 | - joke = total.punchline; | 308 | + ques_and_joke = [question, joke]; |
328 | - ques_and_joke = [question, joke]; | 309 | + return ques_and_joke; |
329 | - return ques_and_joke; | ||
330 | - } | ||
331 | - else if(total.type != "knock-knock"){ | ||
332 | - client.close(); | ||
333 | - knockknockJoke(user_channel); | ||
334 | - } | ||
335 | - | ||
336 | }) | 310 | }) |
337 | .then((joke_info)=>{ | 311 | .then((joke_info)=>{ |
338 | bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing')); | 312 | bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing')); | ... | ... |
1 | [ | 1 | [ |
2 | { | 2 | { |
3 | "id": 1, | 3 | "id": 1, |
4 | - "type": "general", | 4 | + "type": "programming", |
5 | - "setup": "What did the fish say when it hit the wall?", | 5 | + "setup": "What's the best thing about a Boolean?", |
6 | - "punchline": "Dam." | 6 | + "punchline": "Even if you're wrong, you're only off by a bit." |
7 | }, | 7 | }, |
8 | { | 8 | { |
9 | "id": 2, | 9 | "id": 2, |
10 | - "type": "general", | 10 | + "type": "programming", |
11 | - "setup": "How do you make a tissue dance?", | 11 | + "setup": "What's the object-oriented way to become wealthy?", |
12 | - "punchline": "You put a little boogie on it." | 12 | + "punchline": "Inheritance" |
13 | + | ||
13 | }, | 14 | }, |
14 | { | 15 | { |
15 | "id": 3, | 16 | "id": 3, |
16 | - "type": "general", | 17 | + "type": "programming", |
17 | - "setup": "What's Forrest Gump's password?", | 18 | + "setup": "Where do programmers like to hangout?", |
18 | - "punchline": "1Forrest1" | 19 | + "punchline": "The Foo Bar." |
20 | + | ||
19 | }, | 21 | }, |
20 | { | 22 | { |
21 | "id": 4, | 23 | "id": 4, |
22 | - "type": "general", | 24 | + "type": "programming", |
23 | - "setup": "What do you call a belt made out of watches?", | 25 | + "setup": "Why did the programmer quit his job?", |
24 | - "punchline": "A waist of time." | 26 | + "punchline": "Because he didn't get arrays." |
27 | + | ||
25 | }, | 28 | }, |
26 | { | 29 | { |
27 | "id": 5, | 30 | "id": 5, |
28 | - "type": "general", | 31 | + "type": "programming", |
29 | - "setup": "Why can't bicycles stand on their own?", | 32 | + "setup": "Why do programmers always mix up Halloween and Christmas?", |
30 | - "punchline": "They are two tired" | 33 | + "punchline": "Because Oct 31 == Dec 25" |
34 | + | ||
31 | }, | 35 | }, |
32 | { | 36 | { |
33 | "id": 6, | 37 | "id": 6, |
34 | - "type": "general", | 38 | + "type": "programming", |
35 | - "setup": "How does a train eat?", | 39 | + "setup": "A SQL query walks into a bar, walks up to two tables and asks...", |
36 | - "punchline": "It goes chew, chew" | 40 | + "punchline": "'Can I join you?'" |
41 | + | ||
37 | }, | 42 | }, |
38 | { | 43 | { |
39 | "id": 7, | 44 | "id": 7, |
40 | - "type": "general", | 45 | + "type": "programming", |
41 | - "setup": "What do you call a singing Laptop", | 46 | + "setup": "How many programmers does it take to change a lightbulb?", |
42 | - "punchline": "A Dell" | 47 | + "punchline": "None that's a hardware problem" |
48 | + | ||
43 | }, | 49 | }, |
44 | { | 50 | { |
45 | "id": 8, | 51 | "id": 8, |
46 | - "type": "general", | 52 | + "type": "programming", |
47 | - "setup": "How many lips does a flower have?", | 53 | + "setup": "If you put a million monkeys at a million keyboards, one of them will eventually write a Java program", |
48 | - "punchline": "Tulips" | 54 | + "punchline": "the rest of them will write Perl" |
55 | + | ||
49 | }, | 56 | }, |
50 | { | 57 | { |
51 | "id": 9, | 58 | "id": 9, |
52 | - "type": "general", | 59 | + "type": "programming", |
53 | - "setup": "How do you organize an outer space party?", | 60 | + "setup": "['hip', 'hip']", |
54 | - "punchline": "You planet" | 61 | + "punchline": "(hip hip array)" |
62 | + | ||
55 | }, | 63 | }, |
56 | { | 64 | { |
57 | "id": 10, | 65 | "id": 10, |
58 | - "type": "general", | 66 | + "type": "programming", |
59 | - "setup": "What kind of shoes does a thief wear?", | 67 | + "setup": "To understand what recursion is...", |
60 | - "punchline": "Sneakers" | 68 | + "punchline": "You must first understand what recursion is" |
69 | + | ||
61 | }, | 70 | }, |
62 | { | 71 | { |
63 | "id": 11, | 72 | "id": 11, |
64 | - "type": "general", | 73 | + "type": "programming", |
65 | - "setup": "What's the best time to go to the dentist?", | 74 | + "setup": "There are 10 types of people in this world...", |
66 | - "punchline": "Tooth hurty." | 75 | + "punchline": "Those who understand binary and those who don't" |
76 | + | ||
67 | }, | 77 | }, |
68 | { | 78 | { |
69 | "id": 12, | 79 | "id": 12, |
70 | - "type": "knock-knock", | 80 | + "type": "programming", |
71 | - "setup": "Knock knock. \n Who's there? \n A broken pencil. \n A broken pencil who?", | 81 | + "setup": "Which song would an exception sing?", |
72 | - "punchline": "Never mind. It's pointless." | 82 | + "punchline": "Can't catch me - Avicii" |
73 | }, | 83 | }, |
74 | { | 84 | { |
75 | "id": 13, | 85 | "id": 13, |
76 | - "type": "knock-knock", | 86 | + "type": "programming", |
77 | - "setup": "Knock knock. \n Who's there? \n Cows go. \n Cows go who?", | 87 | + "setup": "Why do Java programmers wear glasses?", |
78 | - "punchline": "No, cows go moo." | 88 | + "punchline": "Because they don't C#" |
79 | }, | 89 | }, |
80 | { | 90 | { |
81 | "id": 14, | 91 | "id": 14, |
82 | - "type": "knock-knock", | 92 | + "type": "programming", |
83 | - "setup": "Knock knock. \n Who's there? \n Little old lady. \n Little old lady who?", | 93 | + "setup": "How do you check if a webpage is HTML5?", |
84 | - "punchline": "I didn't know you could yodel!" | 94 | + "punchline": "Try it out on Internet Explorer" |
85 | }, | 95 | }, |
86 | { | 96 | { |
87 | "id": 15, | 97 | "id": 15, |
88 | "type": "programming", | 98 | "type": "programming", |
89 | - "setup": "What's the best thing about a Boolean?", | 99 | + "setup": "A user interface is like a joke.", |
90 | - "punchline": "Even if you're wrong, you're only off by a bit." | 100 | + "punchline": "If you have to explain it then it is not that good." |
101 | + | ||
91 | }, | 102 | }, |
92 | { | 103 | { |
93 | "id": 16, | 104 | "id": 16, |
94 | "type": "programming", | 105 | "type": "programming", |
95 | - "setup": "What's the object-oriented way to become wealthy?", | 106 | + "setup": "I was gonna tell you a joke about UDP...", |
96 | - "punchline": "Inheritance" | 107 | + "punchline": "...but you might not get it." |
108 | + | ||
109 | + | ||
97 | }, | 110 | }, |
98 | { | 111 | { |
99 | "id": 17, | 112 | "id": 17, |
100 | "type": "programming", | 113 | "type": "programming", |
101 | - "setup": "Where do programmers like to hangout?", | 114 | + "setup": "The punchline often arrives before the set-up.", |
102 | - "punchline": "The Foo Bar." | 115 | + "punchline": "Do you know the problem with UDP jokes?" |
116 | + | ||
103 | }, | 117 | }, |
104 | { | 118 | { |
105 | "id": 18, | 119 | "id": 18, |
106 | "type": "programming", | 120 | "type": "programming", |
107 | - "setup": "Why did the programmer quit his job?", | 121 | + "setup": "Why do C# and Java developers keep breaking their keyboards?", |
108 | - "punchline": "Because he didn't get arrays." | 122 | + "punchline": "Because they use a strongly typed language." |
123 | + | ||
109 | }, | 124 | }, |
110 | { | 125 | { |
111 | "id": 19, | 126 | "id": 19, |
112 | - "type": "general", | 127 | + "type": "knock-knock", |
113 | - "setup": "Did you hear about the two silk worms in a race?", | 128 | + "setup": "Knock knock. \n Who's there? \n A broken pencil. \n A broken pencil who?", |
114 | - "punchline": "It ended in a tie." | 129 | + "punchline": "Never mind. It's pointless." |
130 | + | ||
115 | }, | 131 | }, |
116 | { | 132 | { |
117 | "id": 20, | 133 | "id": 20, |
118 | - "type": "general", | 134 | + "type": "knock-knock", |
119 | - "setup": "What do you call a laughing motorcycle?", | 135 | + "setup": "Knock knock. \n Who's there? \n Cows go. \n Cows go who?", |
120 | - "punchline": "A Yamahahahaha." | 136 | + "punchline": "No, cows go moo." |
137 | + | ||
121 | }, | 138 | }, |
122 | { | 139 | { |
123 | "id": 21, | 140 | "id": 21, |
124 | - "type": "general", | 141 | + "type": "knock-knock", |
125 | - "setup": "A termite walks into a bar and says...", | 142 | + "setup": "Knock knock. \n Who's there? \n Little old lady. \n Little old lady who?", |
126 | - "punchline": "'Where is the bar tended?'" | 143 | + "punchline": "I didn't know you could yodel!" |
144 | + | ||
127 | }, | 145 | }, |
128 | { | 146 | { |
129 | "id": 22, | 147 | "id": 22, |
130 | - "type": "general", | 148 | + "type": "knock-knock", |
131 | - "setup": "What does C.S. Lewis keep at the back of his wardrobe?", | 149 | + "setup": "Knock knock. \n Who's there? \n Opportunity.", |
132 | - "punchline": "Narnia business!" | 150 | + "punchline": "That is impossible. Opportunity doesn’t come knocking twice!" |
151 | + | ||
133 | }, | 152 | }, |
134 | { | 153 | { |
135 | "id": 23, | 154 | "id": 23, |
136 | - "type": "programming", | 155 | + "type": "knock-knock", |
137 | - "setup": "Why do programmers always mix up Halloween and Christmas?", | 156 | + "setup": "Knock knock. \n Who's there? \n Hatch. \n Hatch who?", |
138 | - "punchline": "Because Oct 31 == Dec 25" | 157 | + "punchline": "Bless you!" |
158 | + | ||
139 | }, | 159 | }, |
140 | { | 160 | { |
141 | "id": 24, | 161 | "id": 24, |
142 | - "type": "programming", | 162 | + "type": "general", |
143 | - "setup": "A SQL query walks into a bar, walks up to two tables and asks...", | 163 | + "setup": "How does a train eat?", |
144 | - "punchline": "'Can I join you?'" | 164 | + "punchline": "It goes chew, chew" |
145 | }, | 165 | }, |
146 | { | 166 | { |
147 | "id": 25, | 167 | "id": 25, |
148 | - "type": "programming", | 168 | + "type": "general", |
149 | - "setup": "How many programmers does it take to change a lightbulb?", | 169 | + "setup": "What do you call a singing Laptop", |
150 | - "punchline": "None that's a hardware problem" | 170 | + "punchline": "A Dell" |
151 | }, | 171 | }, |
152 | { | 172 | { |
153 | "id": 26, | 173 | "id": 26, |
154 | - "type": "programming", | 174 | + "type": "general", |
155 | - "setup": "If you put a million monkeys at a million keyboards, one of them will eventually write a Java program", | 175 | + "setup": "How many lips does a flower have?", |
156 | - "punchline": "the rest of them will write Perl" | 176 | + "punchline": "Tulips" |
157 | }, | 177 | }, |
158 | { | 178 | { |
159 | "id": 27, | 179 | "id": 27, |
160 | - "type": "programming", | 180 | + "type": "general", |
161 | - "setup": "['hip', 'hip']", | 181 | + "setup": "How do you organize an outer space party?", |
162 | - "punchline": "(hip hip array)" | 182 | + "punchline": "You planet" |
163 | }, | 183 | }, |
164 | { | 184 | { |
165 | "id": 28, | 185 | "id": 28, |
166 | - "type": "programming", | 186 | + "type": "general", |
167 | - "setup": "To understand what recursion is...", | 187 | + "setup": "What kind of shoes does a thief wear?", |
168 | - "punchline": "You must first understand what recursion is" | 188 | + "punchline": "Sneakers" |
169 | }, | 189 | }, |
170 | { | 190 | { |
171 | "id": 29, | 191 | "id": 29, |
172 | - "type": "programming", | 192 | + "type": "general", |
173 | - "setup": "There are 10 types of people in this world...", | 193 | + "setup": "What's the best time to go to the dentist?", |
174 | - "punchline": "Those who understand binary and those who don't" | 194 | + "punchline": "Tooth hurty." |
175 | }, | 195 | }, |
176 | { | 196 | { |
177 | "id": 30, | 197 | "id": 30, |
... | @@ -193,21 +213,23 @@ | ... | @@ -193,21 +213,23 @@ |
193 | }, | 213 | }, |
194 | { | 214 | { |
195 | "id": 33, | 215 | "id": 33, |
196 | - "type": "programming", | 216 | + "type": "general", |
197 | - "setup": "Which song would an exception sing?", | 217 | + "setup": "Did you hear about the two silk worms in a race?", |
198 | - "punchline": "Can't catch me - Avicii" | 218 | + "punchline": "It ended in a tie." |
219 | + | ||
199 | }, | 220 | }, |
200 | { | 221 | { |
201 | "id": 34, | 222 | "id": 34, |
202 | - "type": "knock-knock", | 223 | + "type": "general", |
203 | - "setup": "Knock knock. \n Who's there? \n Opportunity.", | 224 | + "setup": "What does C.S. Lewis keep at the back of his wardrobe?", |
204 | - "punchline": "That is impossible. Opportunity doesn’t come knocking twice!" | 225 | + "punchline": "Narnia business!" |
205 | }, | 226 | }, |
206 | { | 227 | { |
207 | "id": 35, | 228 | "id": 35, |
208 | - "type": "programming", | 229 | + "type": "general", |
209 | - "setup": "Why do Java programmers wear glasses?", | 230 | + "setup": "What do you call a laughing motorcycle?", |
210 | - "punchline": "Because they don't C#" | 231 | + "punchline": "A Yamahahahaha." |
232 | + | ||
211 | }, | 233 | }, |
212 | { | 234 | { |
213 | "id": 36, | 235 | "id": 36, |
... | @@ -331,9 +353,10 @@ | ... | @@ -331,9 +353,10 @@ |
331 | }, | 353 | }, |
332 | { | 354 | { |
333 | "id": 56, | 355 | "id": 56, |
334 | - "type": "programming", | 356 | + "type": "general", |
335 | - "setup": "How do you check if a webpage is HTML5?", | 357 | + "setup": "A termite walks into a bar and says...", |
336 | - "punchline": "Try it out on Internet Explorer" | 358 | + "punchline": "'Where is the bar tended?'" |
359 | + | ||
337 | }, | 360 | }, |
338 | { | 361 | { |
339 | "id": 57, | 362 | "id": 57, |
... | @@ -355,15 +378,15 @@ | ... | @@ -355,15 +378,15 @@ |
355 | }, | 378 | }, |
356 | { | 379 | { |
357 | "id": 60, | 380 | "id": 60, |
358 | - "type": "programming", | 381 | + "type": "general", |
359 | - "setup": "A user interface is like a joke.", | 382 | + "setup": "What did the fish say when it hit the wall?", |
360 | - "punchline": "If you have to explain it then it is not that good." | 383 | + "punchline": "Dam." |
361 | }, | 384 | }, |
362 | { | 385 | { |
363 | "id": 61, | 386 | "id": 61, |
364 | - "type": "knock-knock", | 387 | + "type": "general", |
365 | - "setup": "Knock knock. \n Who's there? \n Hatch. \n Hatch who?", | 388 | + "setup": "Why can't bicycles stand on their own?", |
366 | - "punchline": "Bless you!" | 389 | + "punchline": "They are two tired" |
367 | }, | 390 | }, |
368 | { | 391 | { |
369 | "id": 62, | 392 | "id": 62, |
... | @@ -427,21 +450,21 @@ | ... | @@ -427,21 +450,21 @@ |
427 | }, | 450 | }, |
428 | { | 451 | { |
429 | "id": 72, | 452 | "id": 72, |
430 | - "type": "programming", | 453 | + "type": "general", |
431 | - "setup": "I was gonna tell you a joke about UDP...", | 454 | + "setup": "How do you make a tissue dance?", |
432 | - "punchline": "...but you might not get it." | 455 | + "punchline": "You put a little boogie on it." |
433 | }, | 456 | }, |
434 | { | 457 | { |
435 | "id": 73, | 458 | "id": 73, |
436 | - "type": "programming", | 459 | + "type": "general", |
437 | - "setup": "The punchline often arrives before the set-up.", | 460 | + "setup": "What's Forrest Gump's password?", |
438 | - "punchline": "Do you know the problem with UDP jokes?" | 461 | + "punchline": "1Forrest1" |
439 | }, | 462 | }, |
440 | { | 463 | { |
441 | "id": 74, | 464 | "id": 74, |
442 | - "type": "programming", | 465 | + "type": "general", |
443 | - "setup": "Why do C# and Java developers keep breaking their keyboards?", | 466 | + "setup": "What do you call a belt made out of watches?", |
444 | - "punchline": "Because they use a strongly typed language." | 467 | + "punchline": "A waist of time." |
445 | }, | 468 | }, |
446 | { | 469 | { |
447 | "id": 75, | 470 | "id": 75, | ... | ... |
-
Please register or login to post a comment