3
0
mirror of https://github.com/reality/dbot.git synced 2025-01-24 11:04:13 +01:00
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,6 +35,19 @@ var link = function(dbot) {
'~xkcd': function(event) {
var comicId = event.params[1];
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 {
@ -49,6 +62,7 @@ var link = function(dbot) {
event.reply(dbot.t("no-hits"));
}
});
}
},
'~ud': function(event) {
@ -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]);
}