From 73e9b218242281003f7233a2275393ea8936e3bd Mon Sep 17 00:00:00 2001 From: Daniel Dowling Date: Wed, 30 Jan 2013 14:19:52 +0000 Subject: [PATCH] added random xkcd function using "*" as the param Will get a random comic from http://dynamic.xkcd.com/random/comic/ Needs testing --- modules/link/link.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/link/link.js b/modules/link/link.js index d684cf3..f36ce71 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -35,22 +35,29 @@ var link = function(dbot) { '~xkcd': function(event) { var comicId = event.params[1]; - if(comicId){ + if(comicId){ comicId = comicId + "/"; } else { comicId = ""; } 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) { if (response.statusCode == "200") { data = JSON.parse(body); event.reply(dbot.t("xkcd",data)); - } else { + } else { event.reply(dbot.t("no-hits")); } }); }, - + '~ud': function(event) { var query = event.input[1]; var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + encodeURI(query);