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

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

Constructor Details

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

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/discordrb/events/voice_state_update.rb', line 35

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 == case a
           when String
             e.name
           when Integer
             e.id
           else
             e
           end
    end,
    matches_all(@attributes[:mute], event.mute) do |a, e|
      a == if a.is_a? String
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:deaf], event.deaf) do |a, e|
      a == if a.is_a? String
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:self_mute], event.self_mute) do |a, e|
      a == if a.is_a? String
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:self_deaf], event.self_deaf) do |a, e|
      a == if a.is_a? String
             e.to_s
           else
             e
           end
    end,
    matches_all(@attributes[:channel], event.channel) do |a, e|
      next unless e # Don't bother if the channel is nil

      a == case a
           when String
             e.name
           when Integer
             e.id
           else
             e
           end
    end,
    matches_all(@attributes[:old_channel], event.old_channel) do |a, e|
      next unless e # Don't bother if the channel is nil

      a == case a
           when String
             e.name
           when Integer
             e.id
           else
             e
           end
    end
  ].reduce(true, &:&)
end