This commit is contained in:
reality 2013-01-31 12:58:18 +00:00
commit 63943ca2dc
2 changed files with 37 additions and 24 deletions

View File

@ -22,4 +22,4 @@ which was posted in the current channel.
#### ~ud [headword]
Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided.
#### ~xkcd <comic ID>
Returns a link to the [xkcd](http://xkcd.com) comic specified, or the latest one if a comic is not given.
Returns a link to the [xkcd](http://xkcd.com) comic specified, or the latest one if a comic is not given. Use '*' to return a link to a random comic.

View File

@ -35,33 +35,47 @@ var link = function(dbot) {
'~xkcd': function(event) {
var comicId = event.params[1];
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));
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) + 1);
event.message = '~xkcd ' + comicId;
event.action = 'PRIVMSG';
event.params = event.message.split(' ');
dbot.instance.emit(event);
}
});
}else {
if(comicId){
comicId = comicId + "/";
} else {
event.reply(dbot.t("no-hits"));
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) {
var query = event.input[1];
var query = event.input[1];
var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);
request(reqUrl, function(error, response, body) {
try {
var result = JSON.parse(body);
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
} else {
event.reply(event.user + ': No definition found.');
}
var result = JSON.parse(body);
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
} else {
event.reply(event.user + ': No definition found.');
}
} catch(err) { }
});
}
@ -73,7 +87,6 @@ var link = function(dbot) {
var urlMatches = event.message.match(this.urlRegex);
if(urlMatches !== null) {
this.links[event.channel.name] = urlMatches[0];
if(dbot.config.link.autoTitle == true) {
this.fetchTitle(event, urlMatches[0]);
}