3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 19:52:36 +01:00

redirects

This commit is contained in:
reality 2016-03-22 22:30:06 +00:00
parent ba2ad2649f
commit b61c482a32

View File

@ -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));
}
};