diff --git a/modules/wikipedia/wikipedia.js b/modules/wikipedia/wikipedia.js index 2c731fe..6701e6d 100644 --- a/modules/wikipedia/wikipedia.js +++ b/modules/wikipedia/wikipedia.js @@ -24,6 +24,7 @@ var wikipedia = function(dbot) { } body = body[prop].revisions[0]['*']; + var oBody = body; var redirect = body.match(/#redirect \[\[(.+)\]\]/i); if(redirect) { @@ -53,6 +54,11 @@ var wikipedia = function(dbot) { var sentence = body[_.random(0, body.length -1)]; + if(_.isUndefined(sentence)) { + var links = oBody.match(/\[\[(.+)\]\]/g); + return this.api.randomSentence(links[_.random(0,links.length-1)], cb); + } + cb(sentence); }.bind(this)); }