Created
February 14, 2016 19:09
-
-
Save erynofwales/5231fa34ce9293488dda to your computer and use it in GitHub Desktop.
Hubot script for countdowns
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: | |
# 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