UNPKG

1.59 kBtext/coffeescriptView Raw
1{Message, TextMessage} = require 'brobbot'
2
3class SlackTextMessage extends TextMessage
4 # Represents a TextMessage created from the Slack adapter
5 #
6 # user - The User object
7 # text - The parsed message text
8 # rawText - The unparsed message text
9 # rawMessage - The Slack Message object
10 constructor: (@user, @text, @rawText, @rawMessage) ->
11 super @user, @text, @rawMessage.ts
12
13class SlackRawMessage extends Message
14 # Represents Slack messages that are not suitable to treat as text messages.
15 # These are hidden messages, or messages that have no text / attachments.
16 #
17 # Note that the `user` property may be a "fake" user, i.e. one that does not
18 # exist in brobbot's brain and that contains little to no data.
19 #
20 # user - The User object
21 # text - The parsed message text, if any, or ""
22 # rawText - The unparsed message text, if any, or ""
23 # rawMessage - The Slack Message object
24 constructor: (@user, @text = "", @rawText = "", @rawMessage) ->
25 super @user
26
27class SlackBotMessage extends SlackRawMessage
28 # Represents a message sent by a bot. Specifically, this is any message
29 # with the subtype "bot_message". Expect the `user` property to be a
30 # "fake" user.
31
32 # Determines if the message matches the given regex.
33 #
34 # regex - A Regex to check.
35 #
36 # Returns a Match object or null.
37 match: (regex) ->
38 @text.match regex
39
40 # String representation of a SlackBotMessage
41 #
42 # Returns the message text
43 toString: () ->
44 @text
45
46module.exports = {
47 SlackTextMessage
48 SlackRawMessage
49 SlackBotMessage
50}