Class: MosEisley::S3PO::Message
- Inherits:
-
Object
- Object
- MosEisley::S3PO::Message
- Defined in:
- lib/s3po/message.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Instance Method Summary collapse
-
#add_text(t) ⇒ Object
Adds text after a space if text already exists.
- #attachments ⇒ Object
- #attachments=(a) ⇒ Object
- #channel ⇒ Object
- #for_me? ⇒ Boolean
-
#initialize(e) ⇒ Message
constructor
A new instance of Message.
- #message_type ⇒ Object
- #postable_object ⇒ Object
-
#reply(t = nil) ⇒ MosEisley::S3PO::Message
Create a new Message object for replying; pre-fills some attributes.
- #reply_in_thread ⇒ Object
- #simple_message? ⇒ Boolean
- #text ⇒ Object
-
#text=(t) ⇒ Object
Defines text; existing string will be overwritten.
- #text_body ⇒ Object
- #text_plain ⇒ Object
- #thread_ts ⇒ Object
- #ts ⇒ Object
- #user ⇒ Object
- #user=(u) ⇒ Object
Constructor Details
#initialize(e) ⇒ Message
Returns a new instance of Message.
6 7 8 |
# File 'lib/s3po/message.rb', line 6 def initialize(e) @event = e end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
4 5 6 |
# File 'lib/s3po/message.rb', line 4 def event @event end |
Instance Method Details
#add_text(t) ⇒ Object
Adds text after a space if text already exists
50 51 52 53 54 |
# File 'lib/s3po/message.rb', line 50 def add_text(t) nt = [event[:text], t].compact.join(' ') event[:text] = nt[0].upcase + nt[1..-1] return self end |
#attachments ⇒ Object
56 57 58 |
# File 'lib/s3po/message.rb', line 56 def event[:attachments] end |
#attachments=(a) ⇒ Object
60 61 62 |
# File 'lib/s3po/message.rb', line 60 def (a) event[:attachments] = a end |
#channel ⇒ Object
76 77 78 |
# File 'lib/s3po/message.rb', line 76 def channel event[:channel] end |
#for_me? ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/s3po/message.rb', line 28 def for_me? # check user is not myself myid = MosEisley.config.[:user_id] return false if event[:user] == myid return true if == :im && return true if (event[:text] =~ /^<@#{myid}[|>]/) && return false end |
#message_type ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/s3po/message.rb', line 10 def return nil if event[:channel].nil? t = :na case event[:channel][0] when 'C' t = :channel when 'D' t = :im when 'G' t = :group end return t end |
#postable_object ⇒ Object
97 98 99 100 101 102 |
# File 'lib/s3po/message.rb', line 97 def postable_object obj = @event.dup return obj unless obj[:attachments] obj[:attachments] = S3PO.json_with_object(obj[:attachments]) return obj end |
#reply(t = nil) ⇒ MosEisley::S3PO::Message
Create a new Message object for replying; pre-fills some attributes
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/s3po/message.rb', line 107 def reply(t = nil) s = { channel: channel, as_user: true, attachments: [] } s[:text] = "<@#{user}>" unless == :im if thread_ts s[:thread_ts] = thread_ts elsif t s[:thread_ts] = t end Message.new(s) end |
#reply_in_thread ⇒ Object
122 123 124 125 126 |
# File 'lib/s3po/message.rb', line 122 def reply_in_thread t = thread_ts t ||= ts reply(t) end |
#simple_message? ⇒ Boolean
24 25 26 |
# File 'lib/s3po/message.rb', line 24 def event[:subtype].nil? end |
#text ⇒ Object
37 38 39 |
# File 'lib/s3po/message.rb', line 37 def text event[:text] end |
#text=(t) ⇒ Object
Defines text; existing string will be overwritten
43 44 45 |
# File 'lib/s3po/message.rb', line 43 def text=(t) event[:text] = t end |
#text_body ⇒ Object
84 85 86 87 88 89 |
# File 'lib/s3po/message.rb', line 84 def text_body return nil unless t = event[:text] t = t.sub(/^<@#{MosEisley.config.[:user_id]}[|]?[^>]*>/, '') if for_me? return t end |
#text_plain ⇒ Object
91 92 93 94 95 |
# File 'lib/s3po/message.rb', line 91 def text_plain t = text_body return nil unless t return S3PO.decode_text(t) end |
#thread_ts ⇒ Object
80 81 82 |
# File 'lib/s3po/message.rb', line 80 def thread_ts event[:thread_ts] end |
#ts ⇒ Object
72 73 74 |
# File 'lib/s3po/message.rb', line 72 def ts event[:ts] end |
#user ⇒ Object
64 65 66 |
# File 'lib/s3po/message.rb', line 64 def user event[:user] end |
#user=(u) ⇒ Object
68 69 70 |
# File 'lib/s3po/message.rb', line 68 def user=(u) event[:user] = u end |