Class: Slappy::Event

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Debuggable
Defined in:
lib/slappy/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Debuggable

included

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

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/slappy/event.rb', line 6

def data
  @data
end

#matchesObject

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/slappy/event.rb', line 43

def bot_message?
  @data['subtype'] && @data['subtype'] == 'bot_message'
end

#channelObject



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, options = {})
  options[:text] = text
  options[:channel] = channel
  Messenger.new(options).message
end

#textObject



14
15
16
# File 'lib/slappy/event.rb', line 14

def text
  @data['text'].to_s
end

#tsObject



28
29
30
# File 'lib/slappy/event.rb', line 28

def ts
  Time.at(@data['ts'].to_f)
end

#userObject



24
25
26
# File 'lib/slappy/event.rb', line 24

def user
  SlackAPI::User.find(id: @data['user'])
end