Skip to content

Instantly share code, notes, and snippets.

@robcowie
Created January 12, 2013 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save robcowie/4519412 to your computer and use it in GitHub Desktop.
Save robcowie/4519412 to your computer and use it in GitHub Desktop.
www.timeapi.org hubot plugin. `hubot time <timezone>` `hubot time <timezone> <query>`
# Description:
# Submit time query to www.timeapi.org
#
# Commands:
# hubot time - Current time in local timezone
# hubot time <timezone> - Current time in timezone
# hubot time <timezone> <query> - Time in timezone based on query
module.exports = (robot) ->
robot.respond /time (\D{3})([\d\D ]*)/i, (msg) ->
tz = msg.match[1] || "utc"
q = msg.match[2].trim() || "now"
url = "http://www.timeapi.org/" + tz + "/" + q
msg.http(url)
.get() (err, res, body) ->
if res.statusCode == 500
msg.send "Sorry, I don't understand that time query. See http://chronic.rubyforge.org"
else
msg.send body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment