Skip to content

Instantly share code, notes, and snippets.

@saihoooooooo
Last active December 18, 2015 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saihoooooooo/5828308 to your computer and use it in GitHub Desktop.
Save saihoooooooo/5828308 to your computer and use it in GitHub Desktop.
Message timer for hubot.
# Description:
# alarm wo narase!!
#
# Commands:
# hubot timer <int> [<text>] - <int> byou go ni <text> wo hyouji
# hubot alarm 12:34 [<text>] - 12:34 ni <text> wo hyouji
module.exports = (robot) ->
robot.respond /timer (\d+) ?(.+)?/i, (msg) ->
time = msg.match[1] * 1000
text = msg.match[2] ? 'ジリリリリリリリ'
setTimeout ->
msg.send text
, time
robot.respond /alarm (\d{2}:\d{2}) ?(.+)?/i, (msg) ->
time = msg.match[1]
text = (msg.match[2] ? 'ジリリリリリリリ') + ' > ' + msg.message.user.name
msg.send '受け付けました'
timer = setInterval ->
date = new Date()
h = date.getHours()
h = '0' + h if h < 10
m = date.getMinutes()
m = '0' + m if m < 10
console.log h + ':' +m
if time == (h + ':' +m)
msg.send text if time == (h + ':' +m)
clearTimeout timer
, 60000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment