Class: Discordrb::Events::VoiceStateUpdateEventHandler

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

Overview

Event handler for VoiceStateUpdateEvent

Instance Method Summary collapse

Methods inherited from EventHandler

#call, #initialize, #match, #matches_all

Constructor Details

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

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
# File 'lib/discordrb/events/voice_state_update.rb', line 27

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

  [
    matches_all(@attributes[:from], event.user) do |a, e|
      a == if a.is_a? String
             e.name
           elsif a.is_a? Integer
             e.id
           else
             e
           end
    end,
    matches_all(@attributes[:mute], event.mute) do |a, e|
      a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:deaf], event.deaf) do |a, e|
      a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:self_mute], event.self_mute) do |a, e|
      a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:self_deaf], event.self_deaf) do |a, e|
      a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:channel], event.channel) do |a, e|
      a == if a.is_a? String
             e.name
           elsif a.is_a? Fixnum
             e.id
           else
             e
           end
    end
  ].reduce(true, &:&)
end