Skip to content

Commit

Permalink
Added check for user-limit in openAudioConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Feb 16, 2017
1 parent 1e357f6 commit e77a498
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -62,7 +62,11 @@ public interface AudioManager
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the Guild is temporarily unavailable
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#VOICE_CONNECT VOICE_CONNECT}
* <ul>
* <li>If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#VOICE_CONNECT VOICE_CONNECT}</li>
* <li>If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* and the {@link net.dv8tion.jda.core.entities.VoiceChannel#getUserLimit() user limit} has been exceeded!</li>
* </ul>
*/
void openAudioConnection(VoiceChannel channel);

Expand Down
Expand Up @@ -25,6 +25,7 @@
import net.dv8tion.jda.core.audio.hooks.ConnectionStatus;
import net.dv8tion.jda.core.audio.hooks.ListenerProxy;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.entities.impl.JDAImpl;
import net.dv8tion.jda.core.exceptions.GuildUnavailableException;
Expand Down Expand Up @@ -80,8 +81,13 @@ public void openAudioConnection(VoiceChannel channel)
if (!guild.isAvailable())
throw new GuildUnavailableException("Cannot open an Audio Connection with an unavailable guild. " +
"Please wait until this Guild is available to open a connection.");
if (!guild.getSelfMember().hasPermission(channel, Permission.VOICE_CONNECT))
final Member self = guild.getSelfMember();
if (!self.hasPermission(channel, Permission.VOICE_CONNECT))
throw new PermissionException(Permission.VOICE_CONNECT);
final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set!
if (!self.hasPermission(channel, Permission.MANAGE_CHANNEL) && userLimit > 0 && userLimit <= channel.getMembers().size())
throw new PermissionException(Permission.MANAGE_CHANNEL,
"Unable to connect to VoiceChannel due to userlimit! Requires permission MANAGE_CHANNEL to bypass");

if (audioConnection == null)
{
Expand Down

0 comments on commit e77a498

Please sign in to comment.