This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
/
pomodoro.coffee
71 lines (53 loc) · 1.82 KB
/
pomodoro.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Description:
# Hubot's pomodoro timer
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot start pomodoro - start a new pomodoro
# hubot start pomodoro <time> - start a new pomodoro with a duration of <time> minutes
# hubot stop pomodoro - stop a pomodoro
# hubot pomodoro? - shows the details of the current pomodoro
# hubot total pomodoros - shows the number of the total completed pomodoros
#
# Author:
# mcollina
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"