Class: Discordrb::Events::PresenceEventHandler

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

Overview

Event handler for PresenceEvent

Instance Method Summary collapse

Methods inherited from EventHandler

#initialize, #match, #matches_all

Constructor Details

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

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/discordrb/events/presence.rb', line 18

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

  [
    matches_all(@attributes[:from], event.user) do |a, e|
      if a.is_a? String
        a == e.name
      elsif a.is_a? Fixnum
        a == e.id
      else
        a == e
      end
    end,
    matches_all(@attributes[:status], event.status) do |a, e|
      if a.is_a? String
        a == e.to_s
      else
        a == e
      end
    end
  ].reduce(true, &:&)
end