UNPKG

1.63 kBtext/coffeescriptView Raw
1{Listener} = require 'brobbot'
2{SlackRawMessage, SlackBotMessage} = require './message'
3
4class SlackRawListener extends Listener
5 # SlackRawListeners receive SlackRawMessages from the Slack adapter
6 # and decide if they want to act on it.
7 #
8 # robot - A Robot instance.
9 # matcher - A Function that determines if this listener should trigger the
10 # callback. The matcher takes a SlackRawMessage.
11 # callback - A Function that is triggered if the incoming message matches.
12 #
13 # To use this listener in your own script, you can say
14 #
15 # robot.listeners.push new SlackRawListener(robot, matcher, callback)
16 constructor: (@robot, @matcher, @callback) ->
17
18 # Public: Invokes super only for instances of SlackRawMessage
19 call: (message) ->
20 if message instanceof SlackRawMessage
21 super message
22 else
23 false
24
25class SlackBotListener extends Listener
26 # SlackBotListeners receive SlackBotMessages from the Slack adapter
27 # and decide if they want to act on it. SlackBotListener will only
28 # match instances of SlackBotMessage.
29 #
30 # robot - A Robot instance.
31 # regex - A Regex that determines if this listener should trigger the
32 # callback.
33 # callback - A Function that is triggered if the incoming message matches.
34 #
35 # To use this listener in your own script, you can say
36 #
37 # robot.listeners.push new SlackBotListener(robot, regex, callback)
38 constructor: (@robot, @regex, @callback) ->
39 @matcher = (message) =>
40 if message instanceof SlackBotMessage
41 message.match @regex
42
43module.exports = {
44 SlackRawListener
45 SlackBotListener
46}