From bf2cff6ebac6da64f1d4622929dcb0b1c6f0a213 Mon Sep 17 00:00:00 2001 From: Daniel Dowling Date: Thu, 31 Jan 2013 15:41:16 +0000 Subject: [PATCH 1/3] Cleaned up code based on feedback. --- modules/link/link.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/link/link.js b/modules/link/link.js index cf26bc6..6c987f6 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -41,10 +41,8 @@ var link = function(dbot) { 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); + event.params[1] = comicId; + dbot.commands['~xkcd'](event); } }); }else { From 451b7ea4d0bf65179f7e8ba0f49b60a3ab47ff71 Mon Sep 17 00:00:00 2001 From: Daniel Dowling Date: Thu, 31 Jan 2013 15:53:45 +0000 Subject: [PATCH 2/3] Cleaned up link slightly. --- modules/link/link.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/link/link.js b/modules/link/link.js index 6c987f6..e9e1c7f 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -39,9 +39,7 @@ var link = function(dbot) { 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.params[1] = comicId; + event.params[1] = (Math.floor(Math.random() * data.num) + 1); dbot.commands['~xkcd'](event); } }); From 4b7c2092b0ffc52fc005c2d3d065ebe42b30ba2b Mon Sep 17 00:00:00 2001 From: Daniel Dowling Date: Thu, 31 Jan 2013 17:20:51 +0000 Subject: [PATCH 3/3] Added check for params[1] to ~xkcd --- modules/link/link.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/link/link.js b/modules/link/link.js index e9e1c7f..2cdce4c 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -34,7 +34,10 @@ var link = function(dbot) { }, '~xkcd': function(event) { - var comicId = event.params[1]; + var comicId; + if(!_.isUndefined(event.params[1])) { + comicId = event.params[1]; + } if(comicId == "*"){ request("http://xkcd.com/info.0.json", function(error, response, body){ if (response.statusCode == "200") { @@ -59,6 +62,7 @@ var link = function(dbot) { } }); } + }, '~ud': function(event) {