-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaudit.coffee
47 lines (40 loc) · 1.38 KB
/
audit.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
# Description
# log all hubot interaction to an audit channel
#
# Configuration:
# AUDIT_CHANNEL - the room for hubot to log all interaction to.
#
# Commands:
# None
#
# Notes:
# set your AUDIT_CHANNEL to "moderated" to avoid noise
# configure hubot to join that channel
#
# Author:
# BuJo
# cy4n
AUDIT_CHANNEL = process.env.AUDIT_CHANNEL or '#botlog'
module.exports = (robot) ->
# log hubot commands, with issuer and chatroom
robot.listenerMiddleware (context, next, done) ->
room = context.response.message.user.room
issuer = context.response.message.user.name
cmd = context.response.message.text
switch room
when 'Shell' # for interactive testing
robot.logger.info "| listenerMiddleware: #{room}: <#{issuer}> #{cmd}"
when AUDIT_CHANNEL # ignore AUDIT_CHANNEL to avoid recursion
else
robot.messageRoom(AUDIT_CHANNEL, "#{room}: <#{issuer}> #{cmd}")
next()
# log hubot's answer for the command that hubot listened to earlier
robot.responseMiddleware (context, next, done) ->
return unless context.plaintext?
switch context.response.envelope.room
when 'Shell' #for interactive testing
robot.logger.info "| responseMiddleware:" + context.strings[0]
when AUDIT_CHANNEL # ignore AUDIT_CHANNEL to avoid recursion
else
robot.messageRoom(AUDIT_CHANNEL, s) for s in context.strings
next()