Skip to content

Commit

Permalink
Permission#VOICE_MOVE_OTHERS does not grant access to a voice channel (
Browse files Browse the repository at this point in the history
…#665)

Moved permission check, renamed checkUserlimit
  • Loading branch information
21Joakim authored and MinnDevelopment committed Apr 21, 2018
1 parent b8e7e4e commit 1fd0401
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.core.utils.MiscUtil;
import net.dv8tion.jda.core.utils.NativeUtil;
import net.dv8tion.jda.core.utils.PermissionUtil;

import java.io.IOException;
import java.util.EnumSet;
import java.util.concurrent.locks.ReentrantLock;

public class AudioManagerImpl implements AudioManager
Expand Down Expand Up @@ -91,12 +93,12 @@ public void openAudioConnection(VoiceChannel channel)
throw new GuildUnavailableException("Cannot open an Audio Connection with an unavailable guild. " +
"Please wait until this Guild is available to open a connection.");
final Member self = guild.getSelfMember();
if (!self.hasPermission(channel, Permission.VOICE_CONNECT) && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS))
throw new InsufficientPermissionException(Permission.VOICE_CONNECT);
//if (!self.hasPermission(channel, Permission.VOICE_CONNECT))
// throw new InsufficientPermissionException(Permission.VOICE_CONNECT);

if (audioConnection == null)
{
checkUserlimit(channel, self);
checkChannel(channel, self);
//Start establishing connection, joining provided channel
queuedAudioConnection = channel;
api.getClient().queueAudioConnect(channel);
Expand All @@ -109,17 +111,20 @@ public void openAudioConnection(VoiceChannel channel)
if (channel.equals(audioConnection.getChannel()))
return;

checkUserlimit(channel, self);
checkChannel(channel, self);

api.getClient().queueAudioConnect(channel);
audioConnection.setChannel(channel);
}
}

private void checkUserlimit(VoiceChannel channel, Member self)
private void checkChannel(VoiceChannel channel, Member self)
{
EnumSet<Permission> perms = Permission.toEnumSet(PermissionUtil.getEffectivePermission(channel, self));
if (!perms.contains(Permission.VOICE_CONNECT))
throw new InsufficientPermissionException(Permission.VOICE_CONNECT);
final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set!
if (userLimit > 0 && !self.hasPermission(Permission.ADMINISTRATOR))
if (userLimit > 0 && !perms.contains(Permission.ADMINISTRATOR))
{
// Check if we can actually join this channel
// - If there is a userlimit
Expand All @@ -128,7 +133,7 @@ private void checkUserlimit(VoiceChannel channel, Member self)
// VOICE_MOVE_OTHERS allows access because you would be able to move people out to
// open up a slot anyway
if (userLimit <= channel.getMembers().size()
&& !guild.getSelfMember().hasPermission(channel, Permission.VOICE_MOVE_OTHERS))
&& !perms.contains(Permission.VOICE_MOVE_OTHERS))
{
throw new InsufficientPermissionException(Permission.VOICE_MOVE_OTHERS,
"Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass");
Expand Down

0 comments on commit 1fd0401

Please sign in to comment.