Skip to content

Instantly share code, notes, and snippets.

@patcon
Forked from robcowie/timeapi.coffee
Last active August 29, 2015 13:56
Show Gist options
  • Save patcon/9332299 to your computer and use it in GitHub Desktop.
Save patcon/9332299 to your computer and use it in GitHub Desktop.
# Description:
# Submit time query to www.timeapi.org
#
# Commands:
# hubot time - Current time in UTC
# 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