Class: S3PO::Message
Overview
Message Event class comes from Slack, or you would create one to send a message.
Instance Attribute Summary
Attributes inherited from Event
Instance Method Summary collapse
-
#instruction ⇒ Array
Break up the message text into an Arrary per word when prefixed with bot username; e.g., “@bot echo hello”.
-
#is_instruction? ⇒ Boolean
Is the message directed to me and/or prefixed with bot username?.
- #mentions ⇒ Object
- #plain ⇒ Object
- #plain=(string) ⇒ Object
- #text ⇒ Object
- #text=(string) ⇒ Object
Methods inherited from Event
#channel, #channel=, #initialize, #is_hidden?, #is_im?, #is_message?, #is_simplemessage?, #subtype, #ts, #type, #user
Constructor Details
This class inherits a constructor from S3PO::Event
Instance Method Details
#instruction ⇒ Array
Break up the message text into an Arrary per word when prefixed with bot username; e.g., “@bot echo hello”
116 117 118 119 |
# File 'lib/s-3po/events.rb', line 116 def instruction return nil unless is_instruction? @instruction ||= Parser.instruction_from_plain(plain, [:botid]) end |
#is_instruction? ⇒ Boolean
Is the message directed to me and/or prefixed with bot username?
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/s-3po/events.rb', line 103 def is_instruction? return false unless plain withprefix = /^@#{[:botid]}[!:;,.-]*\s+\S/ withoutprefix = /^[^@]/ return true if (withprefix =~ plain) == 0 if is_im? return true if (withoutprefix =~ plain) == 0 end return false end |
#mentions ⇒ Object
97 98 99 |
# File 'lib/s-3po/events.rb', line 97 def mentions @mentions ||= Parser.mentions_from_text(text) end |
#plain ⇒ Object
86 87 88 89 |
# File 'lib/s-3po/events.rb', line 86 def plain return nil if text.nil? @plain ||= Parser.plain_from_text(text) end |
#plain=(string) ⇒ Object
91 92 93 94 95 |
# File 'lib/s-3po/events.rb', line 91 def plain=(string) fail 'Must be a String.' unless string.class == String @plain = string object[:text] = Generator.text_from_plain(@plain) end |
#text ⇒ Object
76 77 78 |
# File 'lib/s-3po/events.rb', line 76 def text object[:text] end |
#text=(string) ⇒ Object
80 81 82 83 84 |
# File 'lib/s-3po/events.rb', line 80 def text=(string) fail 'Must be a String.' unless string.class == String object[:text] = string @plain = nil end |