forked from GitHub/dbot
added random xkcd function using "*" as the param
Will get a random comic from http://dynamic.xkcd.com/random/comic/ Needs testing
This commit is contained in:
parent
eb7a958352
commit
73e9b21824
@ -35,22 +35,29 @@ var link = function(dbot) {
|
|||||||
|
|
||||||
'~xkcd': function(event) {
|
'~xkcd': function(event) {
|
||||||
var comicId = event.params[1];
|
var comicId = event.params[1];
|
||||||
if(comicId){
|
if(comicId){
|
||||||
comicId = comicId + "/";
|
comicId = comicId + "/";
|
||||||
} else {
|
} else {
|
||||||
comicId = "";
|
comicId = "";
|
||||||
}
|
}
|
||||||
var link = "http://xkcd.com/"+comicId+"info.0.json";
|
var link = "http://xkcd.com/"+comicId+"info.0.json";
|
||||||
|
|
||||||
|
if(comicId == "*"){
|
||||||
|
link = "http://dynamic.xkcd.com/random/comic";
|
||||||
|
request(link, function(error, response, body)
|
||||||
|
link = response.location + "info.0.json";
|
||||||
|
}
|
||||||
|
|
||||||
request(link, function(error, response, body) {
|
request(link, function(error, response, body) {
|
||||||
if (response.statusCode == "200") {
|
if (response.statusCode == "200") {
|
||||||
data = JSON.parse(body);
|
data = JSON.parse(body);
|
||||||
event.reply(dbot.t("xkcd",data));
|
event.reply(dbot.t("xkcd",data));
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t("no-hits"));
|
event.reply(dbot.t("no-hits"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
'~ud': function(event) {
|
'~ud': function(event) {
|
||||||
var query = event.input[1];
|
var query = event.input[1];
|
||||||
var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);
|
var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);
|
||||||
|
Loading…
Reference in New Issue
Block a user