Class: Slappy::Event
- Inherits:
-
Object
- Object
- Slappy::Event
- Extended by:
- Forwardable
- Includes:
- Debuggable
- Defined in:
- lib/slappy/event.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#matches ⇒ Object
Returns the value of attribute matches.
Instance Method Summary collapse
- #bot_message? ⇒ Boolean
- #channel ⇒ Object
-
#initialize(data) ⇒ Event
constructor
A new instance of Event.
- #reaction(emoji) ⇒ Object
- #reply(text, options = {}) ⇒ Object
- #text ⇒ Object
- #ts ⇒ Object
- #user ⇒ Object
Methods included from Debuggable
Constructor Details
#initialize(data) ⇒ Event
Returns a new instance of Event.
10 11 12 |
# File 'lib/slappy/event.rb', line 10 def initialize(data) @data = Hashie::Mash.new data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/slappy/event.rb', line 6 def data @data end |
#matches ⇒ Object
Returns the value of attribute matches.
6 7 8 |
# File 'lib/slappy/event.rb', line 6 def matches @matches end |
Instance Method Details
#bot_message? ⇒ Boolean
43 44 45 |
# File 'lib/slappy/event.rb', line 43 def @data['subtype'] && @data['subtype'] == 'bot_message' end |
#channel ⇒ Object
18 19 20 21 22 |
# File 'lib/slappy/event.rb', line 18 def channel SlackAPI::Channel.find(id: @data['channel']) || SlackAPI::Group.find(id: @data['channel']) || SlackAPI::Direct.find(id: @data['channel']) end |
#reaction(emoji) ⇒ Object
38 39 40 41 |
# File 'lib/slappy/event.rb', line 38 def reaction(emoji) result = ::Slack.reactions_add name: emoji, channel: @data['channel'], timestamp: @data['ts'] Debug.log "Reaction response: #{result}" end |
#reply(text, options = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/slappy/event.rb', line 32 def reply(text, = {}) [:text] = text [:channel] = channel Messenger.new(). end |
#text ⇒ Object
14 15 16 |
# File 'lib/slappy/event.rb', line 14 def text @data['text'].to_s end |
#ts ⇒ Object
28 29 30 |
# File 'lib/slappy/event.rb', line 28 def ts Time.at(@data['ts'].to_f) end |