Created
November 3, 2016 03:02
-
-
Save benwtr/9492600140fbc8ea56fdeda4daccfd5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Hubot interface for timezone.io | |
# | |
# Configuration: | |
# HUBOT_TIMEZONEIO_URL - full team url eg: https://timezone.io/team/buffer | |
# | |
# Commands: | |
# hubot tz - Show team's local time across time zones via timezone.io | |
# | |
# Dependencies: | |
# moment-timezone | |
# | |
# Author: | |
# @benwtr | |
# | |
moment = require 'moment-timezone' | |
timezoneio_url = process.env.HUBOT_TIMEZONEIO_URL || 'https://timezone.io/team/buffer' | |
data_regex = /appData = (.*);/g | |
module.exports = (robot) -> | |
robot.respond /tz/i, (res) -> | |
robot.http(timezoneio_url) | |
.get() (err, result, body) -> | |
if m = data_regex.exec body | |
d = m[1] | |
d = JSON.parse d | |
reply = '' | |
cur_time = new Date().getTime() | |
for z in d.timezones | |
tz = z.tz | |
time = moment(cur_time).tz(tz).format("ddd h:mmA|zZZ") | |
names = for person in z.people | |
person.name | |
names = names.join(', ') | |
reply += "#{tz}|#{time} - #{names}\n" | |
res.reply reply |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output