3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 20:22:39 +01:00
This commit is contained in:
reality 2013-01-31 17:40:40 +00:00
commit b02fe22d02

View File

@ -34,17 +34,16 @@ var link = function(dbot) {
}, },
'~xkcd': function(event) { '~xkcd': function(event) {
var comicId = event.params[1]; var comicId;
if(!_.isUndefined(event.params[1])) {
comicId = event.params[1];
}
if(comicId == "*"){ if(comicId == "*"){
request("http://xkcd.com/info.0.json", function(error, response, body){ request("http://xkcd.com/info.0.json", function(error, response, body){
if (response.statusCode == "200") { if (response.statusCode == "200") {
data = JSON.parse(body); data = JSON.parse(body);
comicId = data.num; event.params[1] = (Math.floor(Math.random() * data.num) + 1);
comicId = (Math.floor(Math.random() * comicId) + 1); dbot.commands['~xkcd'](event);
event.message = '~xkcd ' + comicId;
event.action = 'PRIVMSG';
event.params = event.message.split(' ');
dbot.instance.emit(event);
} }
}); });
}else { }else {
@ -63,6 +62,7 @@ var link = function(dbot) {
} }
}); });
} }
}, },
'~ud': function(event) { '~ud': function(event) {