오원석

-help.err

...@@ -4,7 +4,7 @@ const dbname = 'jokeapi'; ...@@ -4,7 +4,7 @@ const dbname = 'jokeapi';
4 const emoji = require('../slack_emoji'); 4 const emoji = require('../slack_emoji');
5 const url = 'mongodb://localhost:27017/'; 5 const url = 'mongodb://localhost:27017/';
6 const fs=require('fs'); 6 const fs=require('fs');
7 -//const userjoke = require('./joke_data/user.json'); 7 +message_recieved = 0;
8 8
9 exports.startbot = ()=>{ 9 exports.startbot = ()=>{
10 // Get authorization to use the slackbot 10 // Get authorization to use the slackbot
...@@ -21,9 +21,8 @@ exports.startbot = ()=>{ ...@@ -21,9 +21,8 @@ exports.startbot = ()=>{
21 channel_length = data.channels.length; 21 channel_length = data.channels.length;
22 for(i=0; i< channel_length; ++i){ 22 for(i=0; i< channel_length; ++i){
23 //postMessageToChannel(name, message [, params, callback]) (return: promise) - posts a message to channel by name. 23 //postMessageToChannel(name, message [, params, callback]) (return: promise) - posts a message to channel by name.
24 - bot.postMessageToChannel(data.channels[i].name, 'Have some fun with @Joker!\nFor commands write @joker --help' 24 + bot.postMessageToChannel(data.channels[i].name, 'Have some fun with @Joker!\nFor commands write @joker --help',
25 - 25 + emoji.emojis('bowtie'));
26 - , emoji.emojis('bowtie'));
27 } 26 }
28 return data; 27 return data;
29 }) 28 })
...@@ -41,7 +40,7 @@ exports.startbot = ()=>{ ...@@ -41,7 +40,7 @@ exports.startbot = ()=>{
41 } 40 }
42 41
43 status = data; 42 status = data;
44 - message_recieved = 0; 43 +
45 44
46 //Figure out which channel the user is sending message 45 //Figure out which channel the user is sending message
47 //If it's first input from the user, go through this loop to store the data of channel names and ids 46 //If it's first input from the user, go through this loop to store the data of channel names and ids
...@@ -63,8 +62,9 @@ exports.startbot = ()=>{ ...@@ -63,8 +62,9 @@ exports.startbot = ()=>{
63 ++message_recieved; 62 ++message_recieved;
64 console.log("User Channel list: " + channel_names) 63 console.log("User Channel list: " + channel_names)
65 for(i=0; i< channel_length; ++i){ 64 for(i=0; i< channel_length; ++i){
66 - if(channel_ids[i] == status.channel) 65 + if(channel_ids[i] == status.channel){
67 handleMessage(status.text, channel_names[i]); 66 handleMessage(status.text, channel_names[i]);
67 + }
68 } 68 }
69 }) 69 })
70 } 70 }
...@@ -116,7 +116,7 @@ function handleMessage(message, current_channel){ ...@@ -116,7 +116,7 @@ function handleMessage(message, current_channel){
116 } 116 }
117 117
118 } 118 }
119 - else if(message.includes(' --help')){ 119 + else if(message.includes(' -help')){
120 runHelp(current_channel); 120 runHelp(current_channel);
121 } 121 }
122 else if(message.includes(' what jokes')){ 122 else if(message.includes(' what jokes')){
...@@ -126,18 +126,8 @@ function handleMessage(message, current_channel){ ...@@ -126,18 +126,8 @@ function handleMessage(message, current_channel){
126 } 126 }
127 else if(message.includes(' make joke : ')) 127 else if(message.includes(' make joke : '))
128 { 128 {
129 - console.log('123');
130 MakeJoke(message); 129 MakeJoke(message);
131 } 130 }
132 - // else{
133 - // console.log('456');
134 - // UserMakeJoke(current_channel);
135 -
136 - // }
137 - /*else{
138 - comment = "Sorry I'm not smart enough to understand this.....\nPlease use @joker help to know what I can do!";
139 - bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed'));
140 - }*/
141 } 131 }
142 132
143 133
...@@ -201,8 +191,7 @@ randomJoke= (user_channel)=>{ ...@@ -201,8 +191,7 @@ randomJoke= (user_channel)=>{
201 var db = client.db('jokeapi'); 191 var db = client.db('jokeapi');
202 192
203 //set the maximum number of api formats and get a random integer 193 //set the maximum number of api formats and get a random integer
204 - json_max = 376; 194 + random = getRandomInt(1,377);
205 - random = getRandomInt(json_max);
206 //Go to jokes collection inside jokeapi database and find one joke randomly by putting a random number 195 //Go to jokes collection inside jokeapi database and find one joke randomly by putting a random number
207 result = db.collection('jokes').findOne({id: random}); 196 result = db.collection('jokes').findOne({id: random});
208 197
...@@ -319,7 +308,7 @@ Funnystory= (user_channel)=>{ ...@@ -319,7 +308,7 @@ Funnystory= (user_channel)=>{
319 var db = client.db('FunnyStoryapi'); 308 var db = client.db('FunnyStoryapi');
320 309
321 310
322 - random = getRandomInt(200); 311 + random = getRandomInt(1,201);
323 result = db.collection('FunnyStory').findOne({id: random}); 312 result = db.collection('FunnyStory').findOne({id: random});
324 user = result; 313 user = result;
325 //if the random picked api type is not general execute the function from the start to get another format for general type 314 //if the random picked api type is not general execute the function from the start to get another format for general type
...@@ -346,8 +335,7 @@ redditJoke= (user_channel)=>{ ...@@ -346,8 +335,7 @@ redditJoke= (user_channel)=>{
346 if (err) throw err; 335 if (err) throw err;
347 var db = client.db('redditjoke'); 336 var db = client.db('redditjoke');
348 337
349 - json_max = 70; 338 + random = getRandomInt(1,71);
350 - random = getRandomInt(json_max);
351 result = db.collection('reddit').findOne({id: random}); 339 result = db.collection('reddit').findOne({id: random});
352 user = result; 340 user = result;
353 //if the random picked api type is not general execute the function from the start to get another format for general type 341 //if the random picked api type is not general execute the function from the start to get another format for general type
...@@ -400,8 +388,8 @@ knockknockJoke= (user_channel)=>{ ...@@ -400,8 +388,8 @@ knockknockJoke= (user_channel)=>{
400 //Function for giving out information to user to control the bot 388 //Function for giving out information to user to control the bot
401 runHelp = (user_channel) =>{ 389 runHelp = (user_channel) =>{
402 390
403 - comment = "Thanks for using Joker bot!:ghost::ghost:laugh:\nBot info: type '@joker --help' for infos\nBot functions: '@joker tell me [something] joke' will send related jokes, if I don't have what you mentioned, I will tell you I don't have that joke:smile:\n" 391 + comment = "Thanks for using Joker bot!:ghost::ghost:laugh:\nBot info: type '@joker help' for infos\nBot functions: '@joker tell-me [something] joke' will send related jokes, if I don't have what you mentioned, I will tell you I don't have that joke:smile:\n"
404 - current_jokes = "Joke types I have: general , knock-knock , programming , reddit, funny story" 392 + current_jokes = "Joke types I have: 1)general , 2)knock-knock , 3)programming , 4)reddit, 5)funny story, 6)make joke 7)userjoke"
405 bot.postMessageToChannel(user_channel, comment + current_jokes ,emoji.emojis('question')); 393 bot.postMessageToChannel(user_channel, comment + current_jokes ,emoji.emojis('question'));
406 } 394 }
407 } 395 }
......