This repository was archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathpagerduty_points.coffee
59 lines (51 loc) · 1.65 KB
/
pagerduty_points.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
# Description:
# Overloads pagerduty plugin commands to record and display
# override points for different users.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot pager me <number> - award <number> points to the user
# hubot pager me points - should current points
#
# Notes:
#
# Author:
# nstielau
#
#
# Thanks for brettlangdon and monde for their points plugin:
# https://github.com/github/hubot-scripts/blob/master/src/scripts/points.coffee
pager_points = {}
award_points = (msg, username, pts) ->
pager_points[username] ?= 0
pager_points[username] += parseInt(pts)
save = (robot) ->
robot.brain.data.pager_points = pager_points
module.exports = (robot) ->
robot.brain.on 'loaded', ->
points = robot.brain.data.pager_points or {}
# Catch override requests, and award points
robot.respond /pager( me)? (\d+)/i, (msg) ->
email = msg.message.user.pagerdutyEmail
minutes = parseInt msg.match[2]
award_points(msg, email, minutes)
save(robot)
# Show current point scoreboard
robot.respond /pager( me)? points/i, (msg) ->
for username, user_points of pager_points
if username and user_points:
msg.send username + ' has ' + user_points + ' override minutes clocked'
# DEBUG: helper for testing without the pagerduty plugin
robot.respond /pager(?: me)? as (.*) for points/i, (msg) ->
email = msg.match[1]
unless msg.message.user.pagerdutyEmail
msg.message.user.pagerdutyEmail = email
# DEBUG: Clear points
robot.respond /pager( me)? clear points/i, (msg) ->
pager_points = {}
save(robot)