diff --git a/bot.js b/bot.js index 086258b..c4ea85c 100644 --- a/bot.js +++ b/bot.js @@ -86,15 +86,23 @@ function subredditRequest(subreddit) { if(req.readyState == 4 && req.status == 200) { + var json = JSON.parse(req.responseText); while(true) { - var i = getRandomInt(0,json.data.children.length-1); - if(json.data.children[i].data.post_hint === "image" || json.data.children[i].data.post_hint === "link" || json.data.children.data.post_hint === "rich:video") - { - returnText = json.data.children[i].data.url; - break; - } + var i = getRandomInt(0,json.data.children.length-1); + try + { + if(json.data.children[i].data.post_hint === "image" || json.data.children[i].data.post_hint === "link" || json.data.children.data.post_hint === "rich:video") + { + returnText = json.data.children[i].data.url; + break; + } + } + catch (error) // error parsing json + { + continue; + } } } } @@ -311,7 +319,7 @@ client.on('message', message => { message.channel.send((Math.floor(Math.random() * 2) == 0) ? redditbooruRequest('bishounen') : subredditRequest('bishounen')); break; case 'kgirls': - message.channel.send((Math.floor(Math.random() * 2) == 0) ? redditbooruRequest('kpics') : imgurRequest('kpics', 5)); + message.channel.send((Math.floor(Math.random() * 2) == 0) ? redditbooruRequest('kpics') : ((Math.floor(Math.random() * 2) == 0) ? imgurRequest('kpics', 5) : subredditRequest('kpopfap'))); break; case 'kboys': message.channel.send((Math.floor(Math.random() * 2) == 0) ? imgurRequest('kfanservice',1) : ((Math.floor(Math.random() * 2) == 0) ? imgurRequest('kpecs',1) : imgurRequest('cutekboys', 1)));