1
+ # Description:
2
+ # Overloads pagerduty plugin commands to record and display
3
+ # override points for different users.
4
+ #
5
+ # Dependencies:
6
+ # None
7
+ #
8
+ # Configuration:
9
+ # None
10
+ #
11
+ # Commands:
12
+ # hubot pager me <number> - award <number> points to the user
13
+ # hubot pager me points - should current points
14
+ #
15
+ # Notes:
16
+ #
17
+ # Author:
18
+ # nstielau
19
+ #
20
+ #
21
+ # Thanks for brettlangdon and monde for their points plugin:
22
+ # https://github.com/github/hubot-scripts/blob/master/src/scripts/points.coffee
23
+
24
+ pager_points = {}
25
+
26
+ award_points = (msg , username , pts ) ->
27
+ pager_points[username] ?= 0
28
+ pager_points[username] += parseInt (pts)
29
+
30
+ save = (robot ) ->
31
+ robot .brain .data .pager_points = pager_points
32
+
33
+ module .exports = (robot ) ->
34
+ robot .brain .on ' loaded' , ->
35
+ points = robot .brain .data .pager_points or {}
36
+
37
+ # Catch override requests, and award points
38
+ robot .respond / pager( me)? (\d + )/ i , (msg ) ->
39
+ email = msg .message .user .pagerdutyEmail
40
+ minutes = parseInt msg .match [2 ]
41
+ award_points (msg, email, minutes)
42
+ save (robot)
43
+
44
+ # Show current point scoreboard
45
+ robot .respond / pager( me)? points/ i , (msg ) ->
46
+ for username, user_points of pager_points
47
+ if username and user_points :
48
+ msg .send username + ' has ' + user_points + ' override minutes clocked'
49
+
50
+ # DEBUG: helper for testing without the pagerduty plugin
51
+ robot .respond / pager(?: me)? as (. * ) for points/ i , (msg ) ->
52
+ email = msg .match [1 ]
53
+ unless msg .message .user .pagerdutyEmail
54
+ msg .message .user .pagerdutyEmail = email
55
+
56
+ # DEBUG: Clear points
57
+ robot .respond / pager( me)? clear points/ i , (msg ) ->
58
+ pager_points = {}
59
+ save (robot)
0 commit comments