Java Code Examples for net.dv8tion.jda.api.entities.VoiceChannel#equals()

The following examples show how to use net.dv8tion.jda.api.entities.VoiceChannel#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioManagerImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
@Override
    public void openAudioConnection(VoiceChannel channel)
    {
        Checks.notNull(channel, "Provided VoiceChannel");

//        if (!AUDIO_SUPPORTED)
//            throw new UnsupportedOperationException("Sorry! Audio is disabled due to an internal JDA error! Contact Dev!");
        if (!getGuild().equals(channel.getGuild()))
            throw new IllegalArgumentException("The provided VoiceChannel is not a part of the Guild that this AudioManager handles." +
                    "Please provide a VoiceChannel from the proper Guild");
        final Member self = getGuild().getSelfMember();
        //if (!self.hasPermission(channel, Permission.VOICE_CONNECT))
        //    throw new InsufficientPermissionException(Permission.VOICE_CONNECT);

        //If we are already connected to this VoiceChannel, then do nothing.
        if (audioConnection != null && channel.equals(audioConnection.getChannel()))
            return;

        checkChannel(channel, self);

        getJDA().getDirectAudioController().connect(channel);
        if (audioConnection != null)
            audioConnection.setChannel(channel);
    }
 
Example 2
Source File: JdaLink.java    From Lavalink-Client with MIT License 5 votes vote down vote up
/**
 * Eventually connect to a channel. Takes care of disconnecting from an existing connection
 *
 * @param channel Channel to connect to
 */
@SuppressWarnings("WeakerAccess")
void connect(VoiceChannel channel, boolean checkChannel) {
    if (!channel.getGuild().equals(getJda().getGuildById(guild)))
        throw new IllegalArgumentException("The provided VoiceChannel is not a part of the Guild that this AudioManager handles." +
                "Please provide a VoiceChannel from the proper Guild");
    if (channel.getJDA().isUnavailable(channel.getGuild().getIdLong()))
        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 = channel.getGuild().getSelfMember();
    if (!self.hasPermission(channel, Permission.VOICE_CONNECT) && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS))
        throw new InsufficientPermissionException(channel, Permission.VOICE_CONNECT);

    //If we are already connected to this VoiceChannel, then do nothing.
    if (checkChannel && channel.equals(channel.getGuild().getSelfMember().getVoiceState().getChannel()))
        return;

    if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
        final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set!
        if (!self.isOwner() && !self.hasPermission(Permission.ADMINISTRATOR)) {
            if (userLimit > 0                                                      // If there is a userlimit
                    && userLimit <= channel.getMembers().size()                    // if that userlimit is reached
                    && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS)) // If we don't have voice move others permissions
                throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, // then throw exception!
                        "Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass");
        }
    }

    setState(State.CONNECTING);
    queueAudioConnect(channel.getIdLong());
}
 
Example 3
Source File: VoiceActivityListener.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private boolean isChannelAllowed(VoiceChannel channel) {
    if (channel == null || channel.equals(channel.getGuild().getAfkChannel())) {
        return false;
    }
    RankingConfig config = rankingConfigService.get(channel.getGuild());
    return config == null
            || !config.isEnabled()
            || CollectionUtils.isEmpty(config.getIgnoredVoiceChannels())
            || !config.getIgnoredVoiceChannels().contains(channel.getIdLong());
}
 
Example 4
Source File: AudioCmdUtils.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
public static CompletionStage<Boolean> connectToVoiceChannel(GuildMessageReceivedEvent event, I18nContext lang) {
    VoiceChannel userChannel = event.getMember().getVoiceState().getChannel();
    Guild guild = event.getGuild();
    TextChannel textChannel = event.getChannel();

    //I can't see you in any VC here?
    if (userChannel == null) {
        textChannel.sendMessageFormat(lang.get("commands.music_general.connect.user_no_vc"), EmoteReference.ERROR).queue();
        return completedFuture(false);
    }

    //Can't connect to this channel
    if (!guild.getSelfMember().hasPermission(userChannel, Permission.VOICE_CONNECT)) {
        textChannel.sendMessageFormat(lang.get("commands.music_general.connect.missing_permissions_connect"), EmoteReference.ERROR, lang.get("discord_permissions.voice_connect")).queue();
        return completedFuture(false);
    }

    //Can't speak on this channel
    if (!guild.getSelfMember().hasPermission(userChannel, Permission.VOICE_SPEAK)) {
        textChannel.sendMessageFormat(lang.get("commands.music_general.connect.missing_permission_speak"), EmoteReference.ERROR, lang.get("discord_permissions.voice_speak")).queue();
        return completedFuture(false);
    }

    //Set the custom guild music channel from the db value
    VoiceChannel guildMusicChannel = null;
    if (MantaroData.db().getGuild(guild).getData().getMusicChannel() != null)
        guildMusicChannel = guild.getVoiceChannelById(MantaroData.db().getGuild(guild).getData().getMusicChannel());

    //This is where we call LL.
    JdaLink link = MantaroBot.getInstance().getAudioManager().getMusicManager(guild).getLavaLink();
    if (guildMusicChannel != null) {
        //If the channel is not the set one, reject this connect.
        if (!userChannel.equals(guildMusicChannel)) {
            textChannel.sendMessageFormat(lang.get("commands.music_general.connect.channel_locked"), EmoteReference.ERROR, guildMusicChannel.getName()).queue();
            return completedFuture(false);
        }

        //If the link is not currently connected or connecting, accept connection and call openAudioConnection
        if (link.getState() != Link.State.CONNECTED && link.getState() != Link.State.CONNECTING) {
            log.debug("Connected to channel {}. Reason: Link is not CONNECTED or CONNECTING and we requested a connection from connectToVoiceChannel (custom music channel)", userChannel.getId());
            return openAudioConnection(event, link, userChannel, lang).thenApply(__ -> true);
        }

        //Nothing to connect to, but pass true so we can load the song (for example, it's already connected)
        return completedFuture(true);
    }

    //Assume last channel it's the one it was attempting to connect to? (on the one below this too)
    //If the link is CONNECTED and the lastChannel is not the one it's already connected to, reject connection
    if (link.getState() == Link.State.CONNECTED && link.getLastChannel() != null && !link.getLastChannel().equals(userChannel.getId())) {
        textChannel.sendMessageFormat(lang.get("commands.music_general.connect.already_connected"), EmoteReference.WARNING, guild.getVoiceChannelById(link.getLastChannel()).getName()).queue();
        return completedFuture(false);
    }

    //If the link is CONNECTING and the lastChannel is not the one it's already connected to, reject connection
    if (link.getState() == Link.State.CONNECTING && link.getLastChannel() != null && !link.getLastChannel().equals(userChannel.getId())) {
        textChannel.sendMessageFormat(lang.get("commands.music_general.connect.attempting_to_connect"), EmoteReference.ERROR, guild.getVoiceChannelById(link.getLastChannel()).getName()).queue();
        return completedFuture(false);
    }

    //If the link is not currently connected or connecting, accept connection and call openAudioConnection
    if (link.getState() != Link.State.CONNECTED && link.getState() != Link.State.CONNECTING) {
        log.debug("Connected to voice channel {}. Reason: Link is not CONNECTED or CONNECTING and we requested a connection from connectToVoiceChannel", userChannel.getId());
        return openAudioConnection(event, link, userChannel, lang).thenApply(__ -> true);
    }

    //Nothing to connect to, but pass true so we can load the song (for example, it's already connected)
    return completedFuture(true);
}