Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit a0c3778

Browse files
committed
scrum notes: saving raw conversation, pretty output
1 parent 34ef8cb commit a0c3778

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

src/scripts/scrumnotes.coffee

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = (robot) ->
2323

2424
# rooms where hubot is hearing for notes
2525
hearingRooms = {}
26+
messageKeys = ['blocking', 'blocker', 'yesterday', 'today', 'tomorrow', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
2627

2728
getDate = ->
2829
today = new Date()
@@ -42,22 +43,27 @@ module.exports = (robot) ->
4243
if (listener)
4344
return
4445

45-
listenersCount = robot.hear /^(yesterday|today|tomorrow|blocking|sun|mon|tue|wed|thu|fri|sat)[ :\-](.*)$/i, (msg) ->
46+
listenersCount = robot.catchAll (msg) ->
4647

4748
if (!hearingRooms[msg.message.user.room])
4849
return
4950

5051
today = getDate()
51-
name = msg.message.user.name;
52+
name = msg.message.user.name
5253

5354
robot.brain.data.scrumNotes ?= {};
54-
notes = robot.brain.data.scrumNotes[today] ?= {};
55-
notes[name] ?= {};
55+
notes = robot.brain.data.scrumNotes[today] ?= {}
5656

57-
key = msg.match[1].toLowerCase();
57+
notes._raw ?= [];
58+
notes._raw.push([new Date().getTime(), name, msg.message.text])
5859

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])
6167

6268
listener = robot.listeners[listenersCount - 1]
6369

@@ -99,9 +105,19 @@ module.exports = (robot) ->
99105
notes = robot.brain.data.scrumNotes?[today]
100106

101107
if !notes
102-
msg.reply('no notes so far');
108+
msg.reply('no notes so far')
103109
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(''))
105121

106122
robot.respond /take scrum notes/i, (msg) ->
107123

@@ -121,12 +137,20 @@ module.exports = (robot) ->
121137

122138
delete hearingRooms[msg.message.user.room];
123139

140+
msg.reply("not taking scrum notes anymore");
141+
124142
today = getDate()
125143
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"
128144

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);
130154

131155
if (Object.keys(hearingRooms).length < 1)
132156
stopHearing()

0 commit comments

Comments
 (0)