use of net.dv8tion.jda.api.entities.IPermissionContainer in project JDA by DV8FromTheWorld.
the class WebSocketClient method getNextAudioConnectRequest.
protected ConnectionRequest getNextAudioConnectRequest() {
// Don't try to setup audio connections before JDA has finished loading.
if (sessionId == null)
return null;
long now = System.currentTimeMillis();
AtomicReference<ConnectionRequest> request = new AtomicReference<>();
queuedAudioConnections.retainEntries((// we use this because it locks the mutex
guildId, // we use this because it locks the mutex
audioRequest) -> {
if (audioRequest.getNextAttemptEpoch() < now) {
// Check if the guild is ready
Guild guild = api.getGuildById(guildId);
if (guild == null) {
// Not yet ready, check if the guild is known to this shard
GuildSetupController controller = api.getGuildSetupController();
if (!controller.isKnown(guildId)) {
// The guild is not tracked anymore -> we can't connect the audio channel
LOG.debug("Removing audio connection request because the guild has been removed. {}", audioRequest);
return false;
}
return true;
}
ConnectionListener listener = guild.getAudioManager().getConnectionListener();
if (audioRequest.getStage() != ConnectionStage.DISCONNECT) {
// Check if we can connect to the target channel
AudioChannel channel = (AudioChannel) guild.getGuildChannelById(audioRequest.getChannelId());
if (channel == null) {
if (listener != null)
listener.onStatusChange(ConnectionStatus.DISCONNECTED_CHANNEL_DELETED);
return false;
}
IPermissionContainer permChannel = (IPermissionContainer) channel;
if (!guild.getSelfMember().hasPermission(permChannel, Permission.VOICE_CONNECT)) {
if (listener != null)
listener.onStatusChange(ConnectionStatus.DISCONNECTED_LOST_PERMISSION);
return false;
}
}
// This will take the first result
request.compareAndSet(null, audioRequest);
}
return true;
});
return request.get();
}
use of net.dv8tion.jda.api.entities.IPermissionContainer in project JDA by DV8FromTheWorld.
the class PermOverrideManagerImpl method checkPermissions.
@Override
protected boolean checkPermissions() {
Member selfMember = getGuild().getSelfMember();
IPermissionContainer channel = getChannel();
if (!selfMember.hasPermission(channel, Permission.VIEW_CHANNEL))
throw new MissingAccessException(channel, Permission.VIEW_CHANNEL);
if (!selfMember.hasAccess(channel))
throw new MissingAccessException(channel, Permission.VOICE_CONNECT);
if (!selfMember.hasPermission(channel, Permission.MANAGE_PERMISSIONS))
throw new InsufficientPermissionException(channel, Permission.MANAGE_PERMISSIONS);
return super.checkPermissions();
}
Aggregations