Skip to content

Instantly share code, notes, and snippets.

@erynofwales
Created February 14, 2016 19:09
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 erynofwales/5231fa34ce9293488dda to your computer and use it in GitHub Desktop.
Save erynofwales/5231fa34ce9293488dda to your computer and use it in GitHub Desktop.
Hubot script for countdowns
# Description:
# Countdown timer. Starts at the specified number and counts down to 0.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot countdown <x> - Count down from [x] to 0, at one second intervals
#
# Author:
# erynofwales
module.exports = (robot) ->
robot.respond /countdown (\d+)/i, (msg) ->
count = parseInt(msg.match[1], 10)
tick = () ->
msg.send "#{count--}"
if count > 0
setTimeout(tick, 1000)
else
setTimeout(go, 1000)
go = () ->
msg.send "go"
if count <= 0
return
tick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment