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_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”
109 110 111 112 |
# File 'lib/s-3po/events.rb', line 109 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?
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/s-3po/events.rb', line 96 def is_instruction? return false unless plain withprefix = /^@#{options[: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
90 91 92 |
# File 'lib/s-3po/events.rb', line 90 def mentions @mentions ||= Parser.mentions_from_text(text) end |
#plain ⇒ Object
80 81 82 |
# File 'lib/s-3po/events.rb', line 80 def plain @plain ||= Parser.plain_from_text(text) end |
#plain=(string) ⇒ Object
84 85 86 87 88 |
# File 'lib/s-3po/events.rb', line 84 def plain=(string) fail 'Must be a String.' unless string.class == String @plain = string object[:text] = Generator.text_from_plain(@plain) end |
#text ⇒ Object
70 71 72 |
# File 'lib/s-3po/events.rb', line 70 def text object[:text] end |
#text=(string) ⇒ Object
74 75 76 77 78 |
# File 'lib/s-3po/events.rb', line 74 def text=(string) fail 'Must be a String.' unless string.class == String object[:text] = string @plain = nil end |