@@ -23,6 +23,7 @@ module.exports = (robot) ->
23
23
24
24
# rooms where hubot is hearing for notes
25
25
hearingRooms = {}
26
+ messageKeys = [' blocking' , ' blocker' , ' yesterday' , ' today' , ' tomorrow' , ' sun' , ' mon' , ' tue' , ' wed' , ' thu' , ' fri' , ' sat' ]
26
27
27
28
getDate = ->
28
29
today = new Date ()
@@ -42,22 +43,27 @@ module.exports = (robot) ->
42
43
if (listener)
43
44
return
44
45
45
- listenersCount = robot .hear / ^ (yesterday | today | tomorrow | blocking | sun | mon | tue | wed | thu | fri | sat) [ : \- ] ( . * ) $ / i , (msg ) ->
46
+ listenersCount = robot .catchAll (msg) ->
46
47
47
48
if (! hearingRooms[msg .message .user .room ])
48
49
return
49
50
50
51
today = getDate ()
51
- name = msg .message .user .name ;
52
+ name = msg .message .user .name
52
53
53
54
robot .brain .data .scrumNotes ?= {};
54
- notes = robot .brain .data .scrumNotes [today] ?= {};
55
- notes[name] ?= {};
55
+ notes = robot .brain .data .scrumNotes [today] ?= {}
56
56
57
- key = msg .match [1 ].toLowerCase ();
57
+ notes ._raw ?= [];
58
+ notes ._raw .push ([new Date ().getTime (), name, msg .message .text ])
58
59
59
- notes[name][key] ?= [];
60
- notes[name][key].push (msg .match [2 ]);
60
+ keyValue = / ^ ([^ :\n\r\t ] + )[ :\n\t ] (. + )$ / m .exec (msg .message .text )
61
+ if (keyValue)
62
+ notes[name] ?= {}
63
+ key = keyValue[1 ].toLowerCase ()
64
+ if (key in messageKeys)
65
+ notes[name][key] ?= [];
66
+ notes[name][key].push (keyValue[2 ])
61
67
62
68
listener = robot .listeners [listenersCount - 1 ]
63
69
@@ -99,9 +105,19 @@ module.exports = (robot) ->
99
105
notes = robot .brain .data .scrumNotes ? [today]
100
106
101
107
if ! notes
102
- msg .reply (' no notes so far' );
108
+ msg .reply (' no notes so far' )
103
109
else
104
- msg .reply (JSON .stringify (robot .brain .data .scrumNotes ? [today], null , 2 ));
110
+
111
+ # build a pretty version
112
+ response = []
113
+ for own user, userNotes of notes
114
+ if user != ' _raw'
115
+ response .push (user, ' :\n ' )
116
+ for key in messageKeys
117
+ if userNotes[key]
118
+ response .push (' ' , key, ' : ' , userNotes[key].join (' , ' ), ' \n ' )
119
+
120
+ msg .reply (response .join (' ' ))
105
121
106
122
robot .respond / take scrum notes/ i , (msg ) ->
107
123
@@ -121,12 +137,20 @@ module.exports = (robot) ->
121
137
122
138
delete hearingRooms[msg .message .user .room ];
123
139
140
+ msg .reply (" not taking scrum notes anymore" );
141
+
124
142
today = getDate ()
125
143
notes = robot .brain .data .scrumNotes ? [today]
126
- count = if notes then Object .keys (notes).length else 0
127
- status = if count > 0 then " I got notes from #{ count} user#{ if count> 1 then ' s' else ' ' } today" else " I got no notes today"
128
144
129
- msg .reply (" not taking scrum notes anymore (#{ status} )" );
145
+ users = (user for user in Object .keys (notes) when user isnt ' _raw' )
146
+
147
+ count = if notes then users .length else 0
148
+
149
+ status = " I got no notes today"
150
+ if count > 0
151
+ status = [" I got notes from " , users .slice (0 ,Math .min (3 , users .length - 1 )).join (' , ' ), " and " , if users .length > 3 then (users .length - 3 )+ ' more' else users[users .length - 1 ]].join (' ' )
152
+
153
+ msg .reply (status);
130
154
131
155
if (Object .keys (hearingRooms).length < 1 )
132
156
stopHearing ()
0 commit comments