Class: Discordrb::Events::ReactionEventHandler

Inherits:
EventHandler
  • Object
show all
Defined in:
lib/discordrb/events/reactions.rb

Overview

Generic superclass for event handlers pertaining to adding and removing reactions

Instance Method Summary collapse

Methods inherited from EventHandler

#after_call, #call, #initialize, #match, #matches_all

Constructor Details

This class inherits a constructor from Discordrb::Events::EventHandler

Instance Method Details

#matches?(event) ⇒ Boolean



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/discordrb/events/reactions.rb', line 54

def matches?(event)
  # Check for the proper event type
  return false unless event.is_a? ReactionEvent

  [
    matches_all(@attributes[:emoji], event.emoji) do |a, e|
      case a
      when Integer
        e.id == a
      when String
        e.name == a || e.name == a.delete(':') || e.id == a.resolve_id
      else
        e == a
      end
    end,
    matches_all(@attributes[:message], event.message_id) do |a, e|
      a == e
    end,
    matches_all(@attributes[:in], event.channel) do |a, e|
      case a
      when String
        # Make sure to remove the "#" from channel names in case it was specified
        a.delete('#') == e.name
      when Integer
        a == e.id
      else
        a == e
      end
    end,
    matches_all(@attributes[:from], event.user) do |a, e|
      case a
      when String
        a == e.name
      when :bot
        e.current_bot?
      else
        a == e
      end
    end
  ].reduce(true, &:&)
end