Skip to content

Instantly share code, notes, and snippets.

@barkerja
Forked from robcowie/timeapi.coffee
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barkerja/9b5ea309f2ffcea53214 to your computer and use it in GitHub Desktop.
Save barkerja/9b5ea309f2ffcea53214 to your computer and use it in GitHub Desktop.
# 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