diff --git a/lib/discordrb/container.rb b/lib/discordrb/container.rb index 38877588c9..f6b400e8bb 100644 --- a/lib/discordrb/container.rb +++ b/lib/discordrb/container.rb @@ -300,6 +300,9 @@ def channel_recipient_remove(attributes = {}, &block) # @option attributes [true, false] :deaf Matches whether or not the user is deafened server-wide. # @option attributes [true, false] :self_mute Matches whether or not the user is muted by the bot. # @option attributes [true, false] :self_deaf Matches whether or not the user is deafened by the bot. + # @option attributes [true, false] :connected Matches whether or not the user is newly connecting to voice. + # @option attributes [true, false] :disconnected Matches whether or not the user is no longer connected to any voice channel. + # @option attributes [true, false] :moved Matches whether or not the user moved to a different voice channel. # @yield The block is executed when the event is raised. # @yieldparam event [VoiceStateUpdateEvent] The event that was raised. # @return [VoiceStateUpdateEventHandler] the event handler that was registered. diff --git a/lib/discordrb/events/voice_state_update.rb b/lib/discordrb/events/voice_state_update.rb index 41c4b66e4b..e57bcfcb90 100644 --- a/lib/discordrb/events/voice_state_update.rb +++ b/lib/discordrb/events/voice_state_update.rb @@ -99,6 +99,30 @@ def matches?(event) else e end + end, + matches_all(@attributes[:connected], event.old_channel) do |a, e| + case a + when TrueClass + e.nil? + when FalseClass + !e.nil? + end + end, + matches_all(@attributes[:disconnected], event.channel) do |a, e| + case a + when TrueClass + e.nil? + when FalseClass + !e.nil? + end + end, + matches_all(@attributes[:moved], event) do |a, e| + case a + when TrueClass + (e.channel && e.old_channel) && e.channel != e.old_channel + when FalseClass + !((e.channel && e.old_channel) && e.channel != e.old_channel) + end end ].reduce(true, &:&) end