From b61c482a3249b7de1b0a05c554f20406e5524c03 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 22 Mar 2016 22:30:06 +0000 Subject: [PATCH] redirects --- modules/wikipedia/wikipedia.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/wikipedia/wikipedia.js b/modules/wikipedia/wikipedia.js index 68ab259..4067707 100644 --- a/modules/wikipedia/wikipedia.js +++ b/modules/wikipedia/wikipedia.js @@ -22,8 +22,14 @@ var wikipedia = function(dbot) { for(var prop in body) { break; } + body = body[prop].revisions[0]['*']; + var redirect = body.match(/#redirect \[\[(.+)\]\]/i); + if(redirect) { + return this.api.randomSentence(redirect[1], cb); + } + body = body.replace(/=(.+)=/g,''); body = body.replace(/\t/g,''); body = body.replace(/\{(.+)\}/g,''); @@ -39,14 +45,12 @@ var wikipedia = function(dbot) { return line != '' && !line.match(/^\s+$/) && !line.match(/^Category:/) && !line.match(/http:\/\//) && !line.match(/\|/) && !line.match(/:$/) && spaces && spaces.length > 10 && spaces.length < 60; }); - console.log(body); - var sentence = body[_.random(0, body.length -1)]; cb(sentence); - }); + }.bind(this)); } - }); + }.bind(this)); } };