Class: OnyxCord::Events::ComponentEventHandler

Inherits:
InteractionCreateEventHandler show all
Defined in:
lib/onyxcord/events/interactions/components.rb

Overview

Generic handler for component events.

Instance Method Summary collapse

Methods inherited from EventHandler

#after_call, #call, #match, #matches_all

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/onyxcord/events/interactions/components.rb', line 28

def matches?(event)
  return false unless super
  return false unless event.is_a? ComponentEvent

  [
    matches_all(@attributes[:custom_id], event.custom_id) do |a, e|
      # Match regexp and strings
      case a
      when Regexp
        a.match?(e)
      else
        a == e
      end
    end,
    matches_all(@attributes[:message], event.message) do |a, e|
      case a
      when String, Integer
        a.resolve_id == e.id
      else
        a.id == e.id
      end
    end
  ].reduce(&:&)
end