From 6f92f720fbf1312a8758a8d76568d4c8ff5f2863 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 4 Sep 2013 18:10:03 -0400 Subject: [PATCH 1/5] don't require separators for achewood date --- src/scripts/achewood.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/achewood.coffee b/src/scripts/achewood.coffee index 94568dcf6..d26974c2d 100644 --- a/src/scripts/achewood.coffee +++ b/src/scripts/achewood.coffee @@ -36,7 +36,7 @@ module.exports = (robot) -> msg.send "http://achewood.com" + comic.src + "#.png" msg.send comic.title - robot.respond /achewood\s?((0[1-9]|1[0-2]).(0[1-9]|[1-2][0-9]|3[0-1]).(20\d{2})$|current)?/i, (msg) -> + robot.respond /achewood\s?((0[1-9]|1[0-2]).?(0[1-9]|[1-2][0-9]|3[0-1]).?(20\d{2})$|current)?/i, (msg) -> if msg.match[1] == undefined msg.http("http://www.ohnorobot.com/random.pl?comic=636") .get() (err, res, body) -> From 10c0c817cc202be4f22e3b85e00d247ffb8fdea7 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 4 Sep 2013 18:18:34 -0400 Subject: [PATCH 2/5] get achewood based on keyword --- src/scripts/achewood.coffee | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/scripts/achewood.coffee b/src/scripts/achewood.coffee index d26974c2d..fc5abe5a3 100644 --- a/src/scripts/achewood.coffee +++ b/src/scripts/achewood.coffee @@ -12,6 +12,7 @@ # hubot achewood - A random Achewood comic # hubot achewood current - The most recent Achewood comic # hubot achewood - Achewood comic from - mm/dd/yyyy format +# hubot achewood - Achewood comic for keyword # hubot saddest thing - The saddest thing, according to Lie Bot # # Author: @@ -36,16 +37,22 @@ module.exports = (robot) -> msg.send "http://achewood.com" + comic.src + "#.png" msg.send comic.title - robot.respond /achewood\s?((0[1-9]|1[0-2]).?(0[1-9]|[1-2][0-9]|3[0-1]).?(20\d{2})$|current)?/i, (msg) -> + robot.respond /achewood\s?((0[1-9]|1[0-2]).?(0[1-9]|[1-2][0-9]|3[0-1]).?(20\d{2})$|.*)?/i, (msg) -> if msg.match[1] == undefined msg.http("http://www.ohnorobot.com/random.pl?comic=636") .get() (err, res, body) -> fetchAchewood(msg, res.headers['location']) else if msg.match[1] == "current" fetchAchewood(msg, "http://achewood.com") - else + else if msg.match[1] =~ /\d{2}.?\d{2}.?\d{4}/ date = "#{msg.match[2]}#{msg.match[3]}#{msg.match[4]}" fetchAchewood(msg, withDate(date)) + else + query = msg.match[1] + msg.http("http://www.ohnorobot.com/index.pl?comic=636&lucky=1&s=#{query}" + .get() (err, res, body) -> + fetchAchewood(msg, res.headers['location']) + robot.respond /.*saddest thing\?*/i, (msg) -> saddest = msg.random ["06022003", "11052001", "09052006", "07302007"] From 3108a3dfe4423ee1bceb871013eb60112bdbf64c Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 4 Sep 2013 18:43:27 -0400 Subject: [PATCH 3/5] cleanup achewood regex and arg-handling --- src/scripts/achewood.coffee | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/scripts/achewood.coffee b/src/scripts/achewood.coffee index fc5abe5a3..18f43b9f5 100644 --- a/src/scripts/achewood.coffee +++ b/src/scripts/achewood.coffee @@ -37,21 +37,17 @@ module.exports = (robot) -> msg.send "http://achewood.com" + comic.src + "#.png" msg.send comic.title - robot.respond /achewood\s?((0[1-9]|1[0-2]).?(0[1-9]|[1-2][0-9]|3[0-1]).?(20\d{2})$|.*)?/i, (msg) -> - if msg.match[1] == undefined + robot.respond /achewood\s?((?:0[1-9]|1[0-2]).?(?:0[1-9]|[1-2][0-9]|3[0-1]).?(?:20\d{2})$|.*)?/i, (msg) -> + arg = msg.match[1] + if arg == undefined msg.http("http://www.ohnorobot.com/random.pl?comic=636") .get() (err, res, body) -> fetchAchewood(msg, res.headers['location']) - else if msg.match[1] == "current" + else if arg == "current" fetchAchewood(msg, "http://achewood.com") - else if msg.match[1] =~ /\d{2}.?\d{2}.?\d{4}/ - date = "#{msg.match[2]}#{msg.match[3]}#{msg.match[4]}" + else if arg.match /\d{2}.?\d{2}.?\d{4}/ + date = arg.replace /\D/g, '' fetchAchewood(msg, withDate(date)) - else - query = msg.match[1] - msg.http("http://www.ohnorobot.com/index.pl?comic=636&lucky=1&s=#{query}" - .get() (err, res, body) -> - fetchAchewood(msg, res.headers['location']) robot.respond /.*saddest thing\?*/i, (msg) -> From 1f4864aa9687ba813e72eae2afbcc20711ac40a2 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 4 Sep 2013 18:51:39 -0400 Subject: [PATCH 4/5] add the keyword stuff back Now it works, no complaints about `OUTDENT` --- src/scripts/achewood.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/scripts/achewood.coffee b/src/scripts/achewood.coffee index 18f43b9f5..1e800fb52 100644 --- a/src/scripts/achewood.coffee +++ b/src/scripts/achewood.coffee @@ -48,6 +48,11 @@ module.exports = (robot) -> else if arg.match /\d{2}.?\d{2}.?\d{4}/ date = arg.replace /\D/g, '' fetchAchewood(msg, withDate(date)) + else + query = arg + msg.http("http://www.ohnorobot.com/index.pl?comic=636&lucky=1&s=#{query}") + .get() (err, res, body) -> + fetchAchewood(msg, res.headers['location']) robot.respond /.*saddest thing\?*/i, (msg) -> From 564c42fe3996123f450d6de768545a5fc4d27530 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 4 Sep 2013 18:51:50 -0400 Subject: [PATCH 5/5] watspace --- src/scripts/achewood.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripts/achewood.coffee b/src/scripts/achewood.coffee index 1e800fb52..718101386 100644 --- a/src/scripts/achewood.coffee +++ b/src/scripts/achewood.coffee @@ -53,7 +53,6 @@ module.exports = (robot) -> msg.http("http://www.ohnorobot.com/index.pl?comic=636&lucky=1&s=#{query}") .get() (err, res, body) -> fetchAchewood(msg, res.headers['location']) - robot.respond /.*saddest thing\?*/i, (msg) -> saddest = msg.random ["06022003", "11052001", "09052006", "07302007"]