mirror of
https://github.com/reality/dbot.git
synced 2025-01-11 20:42:37 +01:00
updated xkcd random to use dbot api instead of function call.
This commit is contained in:
parent
5a83e78820
commit
bcdca5d002
@ -20,20 +20,7 @@ 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 = {
|
var commands = {
|
||||||
'~title': function(event) {
|
'~title': function(event) {
|
||||||
var link = this.links[event.channel.name];
|
var link = this.links[event.channel.name];
|
||||||
@ -52,21 +39,31 @@ var link = function(dbot) {
|
|||||||
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;
|
comicId = data.num;
|
||||||
comicId = Math.floor(Math.random() * comicId);
|
comicId = (Math.floor(Math.random() * comicId) + 1);
|
||||||
comicId++;
|
event.message = '~xkcd ' + comicId;
|
||||||
comicId = comicId + "/";
|
event.action = 'PRIVMSG';
|
||||||
outputComic(comicId,event);
|
event.params = event.message.split(' ');
|
||||||
}
|
dbot.instance.emit(event);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}else if(comicId){
|
}else {
|
||||||
comicId = comicId + "/";
|
if(comicId){
|
||||||
outputComic(comicId,event);
|
comicId = comicId + "/";
|
||||||
} else {
|
} else {
|
||||||
comicId = "";
|
comicId = "";
|
||||||
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"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'~ud': function(event) {
|
'~ud': function(event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user