Permalink
Browse files

Added pomodoro technique script.

  • Loading branch information...
1 parent 4c0a023 commit f78dbad189791df674576adaedcf5d7a0752932e @mcollina committed May 28, 2012
Showing with 60 additions and 0 deletions.
  1. +60 −0 src/scripts/pomodoro.coffee
@@ -0,0 +1,60 @@
+# Hubot's pomodoro timer
+#
+# start pomodoro - start a new pomodoro
+# start pomodoro <time> - start a new pomodoro with a duration of <time> minutes
+# stop pomodoro - stop a pomodoro
+# pomodoro? - shows the details of the current pomodoro
+# total pomodoros - shows the number of the total completed pomodoros
+
+currentPomodoro = null
+defaultLength = 25
+
+module.exports = (robot) ->
+
+ robot.brain.data.pomodoros ||= 0
+
+ robot.respond /start pomodoro ?(\d+)?/i, (msg) ->
+
+ if currentPomodoro?
+ msg.send "Pomodoro already started"
+ return
+
+ currentPomodoro = {}
+
+ currentPomodoro.func = ->
+ msg.send "Pomodoro completed!"
+ currentPomodoro = null
+ robot.brain.data.pomodoros += 1
+
+ currentPomodoro.time = new Date()
+ currentPomodoro.length = defaultLength
+ currentPomodoro.length = parseInt(msg.match[1]) if msg.match[1]?
+
+ msg.send "Pomodoro started!"
+
+ currentPomodoro.timer = setTimeout(currentPomodoro.func, currentPomodoro.length * 60 * 1000)
+
+ robot.respond /pomodoro\?/i, (msg) ->
+ unless currentPomodoro?
+ msg.send "You have not started a pomodoro"
+ return
+
+ minutes = currentPomodoro.time.getTime() + currentPomodoro.length * 60 * 1000
+ minutes -= new Date().getTime()
+
+ minutes = Math.round(minutes / 1000 / 60)
+
+ msg.send "There are still #{minutes} minutes in this pomodoro"
+
+ robot.respond /stop pomodoro/i, (msg) ->
+ unless currentPomodoro?
+ msg.send "You have not started a pomodoro"
+ return
+
+ clearTimeout(currentPomodoro.timer)
+
+ currentPomodoro = null
+ msg.send "Pomodoro stopped!"
+
+ robot.respond /total pomodoros/i, (msg) ->
+ msg.send "You have completed #{robot.brain.data.pomodoros} pomodoros"

0 comments on commit f78dbad

Please sign in to comment.