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

updated xkcd random to use dbot api instead of function call.

This commit is contained in:
Daniel Dowling 2013-01-30 17:18:07 +00:00
parent 5a83e78820
commit bcdca5d002

View File

@ -21,19 +21,6 @@ var link = function(dbot) {
});
};
function outputComic(comicId,event){
var link = "http://xkcd.com/"+comicId+"info.0.json";
request(link, function(error, response, body) {
if (response.statusCode == "200") {
data = JSON.parse(body);
event.reply(dbot.t("xkcd",data));
} else {
event.reply(dbot.t("no-hits"));
}
});
}
var commands = {
'~title': function(event) {
var link = this.links[event.channel.name];
@ -52,21 +39,31 @@ var link = function(dbot) {
if(comicId == "*"){
request("http://xkcd.com/info.0.json", function(error, response, body){
if (response.statusCode == "200") {
data = JSON.parse(body);
comicId = data.num;
comicId = Math.floor(Math.random() * comicId);
comicId++;
comicId = comicId + "/";
outputComic(comicId,event);
}
data = JSON.parse(body);
comicId = data.num;
comicId = (Math.floor(Math.random() * comicId) + 1);
event.message = '~xkcd ' + comicId;
event.action = 'PRIVMSG';
event.params = event.message.split(' ');
dbot.instance.emit(event);
}
});
}else if(comicId){
comicId = comicId + "/";
outputComic(comicId,event);
} else {
comicId = "";
outputComic(comicId,event);
}
}else {
if(comicId){
comicId = comicId + "/";
} else {
comicId = "";
}
var link = "http://xkcd.com/"+comicId+"info.0.json";
request(link, function(error, response, body) {
if (response.statusCode == "200") {
data = JSON.parse(body);
event.reply(dbot.t("xkcd",data));
} else {
event.reply(dbot.t("no-hits"));
}
});
}
},
'~ud': function(event) {