오원석

code err detection

......@@ -7,8 +7,8 @@ const url = 'mongodb://localhost:27017/';
exports.startbot = ()=>{
// Get authorization to use the slackbot
const bot = new SlackBot({
token : "xoxb-651692943605-645515979745-sfNJBLVbIIb86Bz1gfFc7oT2",
name : "joker"
token : "xoxb-635297512738-635283536771-A03RoBh4Dv8qG1EiLudMpk1f",
name : "jokebot"
});
// Start the slackbot
......@@ -135,10 +135,8 @@ function MakeJoke(message){
})
}
//Gets a random integer
function getRandomInt(max_num) {
min = Math.ceil(1);
max = Math.floor(max_num);
return Math.floor(Math.random() * (max - min + 1)) + min;
function getRandomInt(start,end) {
return Math.floor((Math.random() * 100)%(end-start))+start;
}
//Function for giving out random joke
......@@ -184,23 +182,15 @@ generalJoke= (user_channel)=>{
if (err) throw err;
var db = client.db('jokeapi');
json_max = 376;
random = getRandomInt(json_max);
random = getRandomInt(24,377);
result = db.collection('jokes').findOne({id: random});
user = result;
//if the random picked api type is not general execute the function from the start to get another format for general type
user.then(function(total){
if(total.type === "general"){
question = total.setup;
joke = total.punchline;
ques_and_joke = [question, joke];
return ques_and_joke;
}
else if(total.type != "general"){
client.close();
generalJoke(user_channel);
}
question = total.setup;
joke = total.punchline;
ques_and_joke = [question, joke];
return ques_and_joke;
})
.then((joke_info)=>{
bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing'));
......@@ -223,22 +213,14 @@ programmingJoke= (user_channel)=>{
if (err) throw err;
var db = client.db('jokeapi');
json_max = 376;
random = getRandomInt(json_max);
random = getRandomInt(0,19);
result = db.collection('jokes').findOne({id: random});
user = result;
user.then(function(total){
if(total.type === "programming"){
question = total.setup;
joke = total.punchline;
ques_and_joke = [question, joke];
return ques_and_joke;
}
else if(total.type != "programming"){
client.close();
programmingJoke(user_channel);
}
question = total.setup;
joke = total.punchline;
ques_and_joke = [question, joke];
return ques_and_joke;
})
.then((joke_info)=>{
bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing'));
......@@ -316,23 +298,15 @@ knockknockJoke= (user_channel)=>{
MongoClient.connect(url, function (err, client){
if (err) throw err;
var db = client.db('jokeapi');
json_max = 61;
random = getRandomInt(json_max);
random = getRandomInt(19,24);
result = db.collection('jokes').findOne({id: random});
user = result;
user.then(function(total){
if(total.type === "knock-knock"){
question = total.setup;
joke = total.punchline;
ques_and_joke = [question, joke];
return ques_and_joke;
}
else if(total.type != "knock-knock"){
client.close();
knockknockJoke(user_channel);
}
question = total.setup;
joke = total.punchline;
ques_and_joke = [question, joke];
return ques_and_joke;
})
.then((joke_info)=>{
bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing'));
......
[
{
"id": 1,
"type": "general",
"setup": "What did the fish say when it hit the wall?",
"punchline": "Dam."
"type": "programming",
"setup": "What's the best thing about a Boolean?",
"punchline": "Even if you're wrong, you're only off by a bit."
},
{
"id": 2,
"type": "general",
"setup": "How do you make a tissue dance?",
"punchline": "You put a little boogie on it."
"type": "programming",
"setup": "What's the object-oriented way to become wealthy?",
"punchline": "Inheritance"
},
{
"id": 3,
"type": "general",
"setup": "What's Forrest Gump's password?",
"punchline": "1Forrest1"
"type": "programming",
"setup": "Where do programmers like to hangout?",
"punchline": "The Foo Bar."
},
{
"id": 4,
"type": "general",
"setup": "What do you call a belt made out of watches?",
"punchline": "A waist of time."
"type": "programming",
"setup": "Why did the programmer quit his job?",
"punchline": "Because he didn't get arrays."
},
{
"id": 5,
"type": "general",
"setup": "Why can't bicycles stand on their own?",
"punchline": "They are two tired"
"type": "programming",
"setup": "Why do programmers always mix up Halloween and Christmas?",
"punchline": "Because Oct 31 == Dec 25"
},
{
"id": 6,
"type": "general",
"setup": "How does a train eat?",
"punchline": "It goes chew, chew"
"type": "programming",
"setup": "A SQL query walks into a bar, walks up to two tables and asks...",
"punchline": "'Can I join you?'"
},
{
"id": 7,
"type": "general",
"setup": "What do you call a singing Laptop",
"punchline": "A Dell"
"type": "programming",
"setup": "How many programmers does it take to change a lightbulb?",
"punchline": "None that's a hardware problem"
},
{
"id": 8,
"type": "general",
"setup": "How many lips does a flower have?",
"punchline": "Tulips"
"type": "programming",
"setup": "If you put a million monkeys at a million keyboards, one of them will eventually write a Java program",
"punchline": "the rest of them will write Perl"
},
{
"id": 9,
"type": "general",
"setup": "How do you organize an outer space party?",
"punchline": "You planet"
"type": "programming",
"setup": "['hip', 'hip']",
"punchline": "(hip hip array)"
},
{
"id": 10,
"type": "general",
"setup": "What kind of shoes does a thief wear?",
"punchline": "Sneakers"
"type": "programming",
"setup": "To understand what recursion is...",
"punchline": "You must first understand what recursion is"
},
{
"id": 11,
"type": "general",
"setup": "What's the best time to go to the dentist?",
"punchline": "Tooth hurty."
"type": "programming",
"setup": "There are 10 types of people in this world...",
"punchline": "Those who understand binary and those who don't"
},
{
"id": 12,
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n A broken pencil. \n A broken pencil who?",
"punchline": "Never mind. It's pointless."
"type": "programming",
"setup": "Which song would an exception sing?",
"punchline": "Can't catch me - Avicii"
},
{
"id": 13,
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Cows go. \n Cows go who?",
"punchline": "No, cows go moo."
"type": "programming",
"setup": "Why do Java programmers wear glasses?",
"punchline": "Because they don't C#"
},
{
"id": 14,
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Little old lady. \n Little old lady who?",
"punchline": "I didn't know you could yodel!"
"type": "programming",
"setup": "How do you check if a webpage is HTML5?",
"punchline": "Try it out on Internet Explorer"
},
{
"id": 15,
"type": "programming",
"setup": "What's the best thing about a Boolean?",
"punchline": "Even if you're wrong, you're only off by a bit."
"setup": "A user interface is like a joke.",
"punchline": "If you have to explain it then it is not that good."
},
{
"id": 16,
"type": "programming",
"setup": "What's the object-oriented way to become wealthy?",
"punchline": "Inheritance"
"setup": "I was gonna tell you a joke about UDP...",
"punchline": "...but you might not get it."
},
{
"id": 17,
"type": "programming",
"setup": "Where do programmers like to hangout?",
"punchline": "The Foo Bar."
"setup": "The punchline often arrives before the set-up.",
"punchline": "Do you know the problem with UDP jokes?"
},
{
"id": 18,
"type": "programming",
"setup": "Why did the programmer quit his job?",
"punchline": "Because he didn't get arrays."
"setup": "Why do C# and Java developers keep breaking their keyboards?",
"punchline": "Because they use a strongly typed language."
},
{
"id": 19,
"type": "general",
"setup": "Did you hear about the two silk worms in a race?",
"punchline": "It ended in a tie."
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n A broken pencil. \n A broken pencil who?",
"punchline": "Never mind. It's pointless."
},
{
"id": 20,
"type": "general",
"setup": "What do you call a laughing motorcycle?",
"punchline": "A Yamahahahaha."
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Cows go. \n Cows go who?",
"punchline": "No, cows go moo."
},
{
"id": 21,
"type": "general",
"setup": "A termite walks into a bar and says...",
"punchline": "'Where is the bar tended?'"
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Little old lady. \n Little old lady who?",
"punchline": "I didn't know you could yodel!"
},
{
"id": 22,
"type": "general",
"setup": "What does C.S. Lewis keep at the back of his wardrobe?",
"punchline": "Narnia business!"
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Opportunity.",
"punchline": "That is impossible. Opportunity doesn’t come knocking twice!"
},
{
"id": 23,
"type": "programming",
"setup": "Why do programmers always mix up Halloween and Christmas?",
"punchline": "Because Oct 31 == Dec 25"
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Hatch. \n Hatch who?",
"punchline": "Bless you!"
},
{
"id": 24,
"type": "programming",
"setup": "A SQL query walks into a bar, walks up to two tables and asks...",
"punchline": "'Can I join you?'"
"type": "general",
"setup": "How does a train eat?",
"punchline": "It goes chew, chew"
},
{
"id": 25,
"type": "programming",
"setup": "How many programmers does it take to change a lightbulb?",
"punchline": "None that's a hardware problem"
"type": "general",
"setup": "What do you call a singing Laptop",
"punchline": "A Dell"
},
{
"id": 26,
"type": "programming",
"setup": "If you put a million monkeys at a million keyboards, one of them will eventually write a Java program",
"punchline": "the rest of them will write Perl"
"type": "general",
"setup": "How many lips does a flower have?",
"punchline": "Tulips"
},
{
"id": 27,
"type": "programming",
"setup": "['hip', 'hip']",
"punchline": "(hip hip array)"
"type": "general",
"setup": "How do you organize an outer space party?",
"punchline": "You planet"
},
{
"id": 28,
"type": "programming",
"setup": "To understand what recursion is...",
"punchline": "You must first understand what recursion is"
"type": "general",
"setup": "What kind of shoes does a thief wear?",
"punchline": "Sneakers"
},
{
"id": 29,
"type": "programming",
"setup": "There are 10 types of people in this world...",
"punchline": "Those who understand binary and those who don't"
"type": "general",
"setup": "What's the best time to go to the dentist?",
"punchline": "Tooth hurty."
},
{
"id": 30,
......@@ -193,21 +213,23 @@
},
{
"id": 33,
"type": "programming",
"setup": "Which song would an exception sing?",
"punchline": "Can't catch me - Avicii"
"type": "general",
"setup": "Did you hear about the two silk worms in a race?",
"punchline": "It ended in a tie."
},
{
"id": 34,
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Opportunity.",
"punchline": "That is impossible. Opportunity doesn’t come knocking twice!"
"type": "general",
"setup": "What does C.S. Lewis keep at the back of his wardrobe?",
"punchline": "Narnia business!"
},
{
"id": 35,
"type": "programming",
"setup": "Why do Java programmers wear glasses?",
"punchline": "Because they don't C#"
"type": "general",
"setup": "What do you call a laughing motorcycle?",
"punchline": "A Yamahahahaha."
},
{
"id": 36,
......@@ -331,9 +353,10 @@
},
{
"id": 56,
"type": "programming",
"setup": "How do you check if a webpage is HTML5?",
"punchline": "Try it out on Internet Explorer"
"type": "general",
"setup": "A termite walks into a bar and says...",
"punchline": "'Where is the bar tended?'"
},
{
"id": 57,
......@@ -355,15 +378,15 @@
},
{
"id": 60,
"type": "programming",
"setup": "A user interface is like a joke.",
"punchline": "If you have to explain it then it is not that good."
"type": "general",
"setup": "What did the fish say when it hit the wall?",
"punchline": "Dam."
},
{
"id": 61,
"type": "knock-knock",
"setup": "Knock knock. \n Who's there? \n Hatch. \n Hatch who?",
"punchline": "Bless you!"
"type": "general",
"setup": "Why can't bicycles stand on their own?",
"punchline": "They are two tired"
},
{
"id": 62,
......@@ -427,21 +450,21 @@
},
{
"id": 72,
"type": "programming",
"setup": "I was gonna tell you a joke about UDP...",
"punchline": "...but you might not get it."
"type": "general",
"setup": "How do you make a tissue dance?",
"punchline": "You put a little boogie on it."
},
{
"id": 73,
"type": "programming",
"setup": "The punchline often arrives before the set-up.",
"punchline": "Do you know the problem with UDP jokes?"
"type": "general",
"setup": "What's Forrest Gump's password?",
"punchline": "1Forrest1"
},
{
"id": 74,
"type": "programming",
"setup": "Why do C# and Java developers keep breaking their keyboards?",
"punchline": "Because they use a strongly typed language."
"type": "general",
"setup": "What do you call a belt made out of watches?",
"punchline": "A waist of time."
},
{
"id": 75,
......