Showing
3 changed files
with
21 additions
and
10 deletions
... | @@ -107,7 +107,7 @@ function handleMessage(message, current_channel){ | ... | @@ -107,7 +107,7 @@ function handleMessage(message, current_channel){ |
107 | Funnystory(current_channel); | 107 | Funnystory(current_channel); |
108 | } | 108 | } |
109 | else if(message.includes(' userjoke')){ | 109 | else if(message.includes(' userjoke')){ |
110 | - UserMakeJoke(current_channel); | 110 | + UserMakeJoke(message,current_channel); |
111 | } | 111 | } |
112 | else if(message.includes(' me')){ | 112 | else if(message.includes(' me')){ |
113 | comment = "Please use @joker --help to know what I can do!:smile::smile::smile:\n You can write type of joke[knock-knock, general, programming, funny story, reddit]"; | 113 | comment = "Please use @joker --help to know what I can do!:smile::smile::smile:\n You can write type of joke[knock-knock, general, programming, funny story, reddit]"; |
... | @@ -137,11 +137,16 @@ function MakeJoke(message,user_channel){ | ... | @@ -137,11 +137,16 @@ function MakeJoke(message,user_channel){ |
137 | } | 137 | } |
138 | var input=message.split(':'); | 138 | var input=message.split(':'); |
139 | var msg=input[1].split(','); | 139 | var msg=input[1].split(','); |
140 | - | 140 | + var temp=message.split(' '); |
141 | - fs.exists('./joke_data/user.json',function(exists){ | 141 | + var user=temp[0].substring(2,temp[0].length-1); |
142 | + console.log('유저 => '+user); | ||
143 | + | ||
144 | + var path='./joke_data/'+user+'.json'; | ||
145 | + console.log(path); | ||
146 | + fs.exists(path,function(exists){ | ||
142 | if(exists){ | 147 | if(exists){ |
143 | console.log("yes file exists"); | 148 | console.log("yes file exists"); |
144 | - fs.readFile('./joke_data/user.json',function readFileCallback(err,data){ | 149 | + fs.readFile(path,function readFileCallback(err,data){ |
145 | if(err){ | 150 | if(err){ |
146 | console.log(err); | 151 | console.log(err); |
147 | } | 152 | } |
... | @@ -150,7 +155,7 @@ function MakeJoke(message,user_channel){ | ... | @@ -150,7 +155,7 @@ function MakeJoke(message,user_channel){ |
150 | var length=obj.table.length; | 155 | var length=obj.table.length; |
151 | obj.table.push({id : length+1, type : 'userjoke', setup : msg[0], punchline : msg[1]}); | 156 | obj.table.push({id : length+1, type : 'userjoke', setup : msg[0], punchline : msg[1]}); |
152 | var json=JSON.stringify(obj); | 157 | var json=JSON.stringify(obj); |
153 | - fs.writeFile('./joke_data/user.json',json,'utf8',function(err){ | 158 | + fs.writeFile(path,json,'utf8',function(err){ |
154 | if(err){ | 159 | if(err){ |
155 | console.log(err); | 160 | console.log(err); |
156 | } | 161 | } |
... | @@ -165,7 +170,7 @@ function MakeJoke(message,user_channel){ | ... | @@ -165,7 +170,7 @@ function MakeJoke(message,user_channel){ |
165 | console.log("file not exists"); | 170 | console.log("file not exists"); |
166 | obj.table.push({id : 1, type : 'userjoke', setup : msg[0], punchline : msg[1]}); | 171 | obj.table.push({id : 1, type : 'userjoke', setup : msg[0], punchline : msg[1]}); |
167 | var json=JSON.stringify(obj); | 172 | var json=JSON.stringify(obj); |
168 | - fs.writeFile('./joke_data/user.json',json,'utf8',function(err){ | 173 | + fs.writeFile(path,json,'utf8',function(err){ |
169 | if(err){ | 174 | if(err){ |
170 | console.log(err); | 175 | console.log(err); |
171 | } | 176 | } |
... | @@ -221,8 +226,15 @@ randomJoke= (user_channel)=>{ | ... | @@ -221,8 +226,15 @@ randomJoke= (user_channel)=>{ |
221 | } | 226 | } |
222 | 227 | ||
223 | // Function for giving out users making joke | 228 | // Function for giving out users making joke |
224 | -UserMakeJoke= (user_channel)=>{ | 229 | +UserMakeJoke= (message,user_channel)=>{ |
225 | - var data=fs.readFileSync('./joke_data/user.json'); | 230 | + |
231 | + var temp=message.split(' '); | ||
232 | + var user=temp[0].substring(2,temp[0].length-1); | ||
233 | + console.log('유저 => '+user); | ||
234 | + | ||
235 | + var path='./joke_data/'+user+'.json'; | ||
236 | + | ||
237 | + var data=fs.readFileSync(path); | ||
226 | var jsondata=JSON.parse(data); | 238 | var jsondata=JSON.parse(data); |
227 | random=getRandomInt(1,jsondata.table.length+1); | 239 | random=getRandomInt(1,jsondata.table.length+1); |
228 | 240 | ||
... | @@ -233,7 +245,6 @@ UserMakeJoke= (user_channel)=>{ | ... | @@ -233,7 +245,6 @@ UserMakeJoke= (user_channel)=>{ |
233 | question=user.setup; | 245 | question=user.setup; |
234 | bot.postMessageToChannel(user_channel,question, emoji.emojis('laughing')); | 246 | bot.postMessageToChannel(user_channel,question, emoji.emojis('laughing')); |
235 | joke=user.punchline; | 247 | joke=user.punchline; |
236 | - // result=question+'\n'+joke; | ||
237 | setTimeout(function secondfunction(){ | 248 | setTimeout(function secondfunction(){ |
238 | bot.postMessageToChannel(user_channel,joke, emoji.emojis('laughing')); | 249 | bot.postMessageToChannel(user_channel,joke, emoji.emojis('laughing')); |
239 | },3000); | 250 | },3000); | ... | ... |
joke_data/UJP8BFSNP.json
0 → 100644
1 | +{"table":[{"id":1,"type":"userjoke","setup":" one plus one equals?","punchline":" window!!"}]} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
joke_data/user.json
deleted
100644 → 0
1 | -{"table":[{"id":1,"type":"userjoke","setup":" one plus one equals? ","punchline":" window!"},{"id":2,"type":"userjoke","setup":" what 6 x 3 ? ","punchline":" 63 building!"},{"id":3,"type":"userjoke","setup":" what 2 x 9 ?","punchline":" iquana!"},{"id":4,"type":"userjoke","setup":" where are you?","punchline":" your heart"},{"id":5,"type":"userjoke","setup":" jogutae ","punchline":" babo"},{"id":6,"type":"userjoke","setup":" oh","punchline":" wonserk"}]} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment