From bc114a10e6d80d5115bbc99edfbdc28d15b49be0 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 22 Mar 2016 22:54:17 +0000 Subject: [PATCH] redirects --- modules/wikipedia/wikipedia.js | 6 ++++++ 1 file changed, 6 insertions(+) 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)); }