Search in sources :

Example 1 with GuildVoiceState

use of net.dv8tion.jda.core.entities.GuildVoiceState in project MantaroBot by Mantaro.

the class VoiceChannelListener method onLeave.

private void onLeave(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if (validate(vs))
        return;
    if (isAlone(vc)) {
        GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
        if (gmm != null) {
            TrackScheduler scheduler = gmm.getTrackScheduler();
            if (scheduler != null && scheduler.getCurrentTrack() != null && scheduler.getRequestedChannelParsed() != null) {
                TextChannel tc = scheduler.getRequestedChannelParsed();
                if (tc.canTalk()) {
                    tc.sendMessage(EmoteReference.THINKING + "I'll leave **" + vc.getName() + "** in 2 minutes because I was left all alone :<").queue(m -> m.delete().queueAfter(30, TimeUnit.SECONDS));
                }
            }
            gmm.setAwaitingDeath(true);
            gmm.scheduleLeave();
            gmm.getAudioPlayer().setPaused(true);
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)

Example 2 with GuildVoiceState

use of net.dv8tion.jda.core.entities.GuildVoiceState in project MantaroBot by Mantaro.

the class VoiceChannelListener method onJoin.

private void onJoin(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if (validate(vs))
        return;
    if (!isAlone(vc)) {
        GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
        if (gmm != null) {
            TrackScheduler scheduler = gmm.getTrackScheduler();
            if (scheduler.getCurrentTrack() != null) {
                if (gmm.isAwaitingDeath()) {
                    TextChannel tc = scheduler.getRequestedChannelParsed();
                    if (tc.canTalk()) {
                        tc.sendMessage(EmoteReference.POPPER + "Resuming playback because someone joined!").queue();
                    }
                }
            }
            gmm.cancelLeave();
            gmm.setAwaitingDeath(false);
            gmm.getAudioPlayer().setPaused(false);
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)

Example 3 with GuildVoiceState

use of net.dv8tion.jda.core.entities.GuildVoiceState in project MantaroBot by Mantaro.

the class VoiceChannelListener method onGuildVoiceMute.

private void onGuildVoiceMute(GuildVoiceMuteEvent event) {
    if (event.getMember().getUser().getIdLong() != event.getJDA().getSelfUser().getIdLong())
        return;
    GuildVoiceState vs = event.getVoiceState();
    if (validate(vs))
        return;
    GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
    if (gmm != null) {
        if (event.isMuted()) {
            TrackScheduler scheduler = gmm.getTrackScheduler();
            if (scheduler.getCurrentTrack() != null && scheduler.getRequestedChannelParsed() != null) {
                TextChannel tc = scheduler.getRequestedChannelParsed();
                if (tc.canTalk()) {
                    tc.sendMessage(EmoteReference.SAD + "Pausing player because I got muted :(").queue();
                }
                gmm.getAudioPlayer().setPaused(true);
            }
        } else {
            if (!isAlone(vs.getChannel())) {
                if (gmm.getTrackScheduler().getCurrentTrack() != null) {
                    gmm.getAudioPlayer().setPaused(false);
                }
            }
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)

Example 4 with GuildVoiceState

use of net.dv8tion.jda.core.entities.GuildVoiceState in project MantaroBot by Mantaro.

the class VoiceLeave method run.

@Override
public void run() {
    MantaroBot.getInstance().getAudioManager().getMusicManagers().forEach((guildId, manager) -> {
        try {
            Guild guild = MantaroBot.getInstance().getGuildById(guildId);
            if (guild == null)
                return;
            GuildVoiceState voiceState = guild.getSelfMember().getVoiceState();
            if (voiceState == null)
                return;
            if (voiceState.inVoiceChannel()) {
                TextChannel channel = guild.getPublicChannel();
                if (channel != null) {
                    if (channel.canTalk()) {
                        VoiceChannel voiceChannel = voiceState.getChannel();
                        AudioPlayer player = manager.getAudioPlayer();
                        GuildMusicManager mm = MantaroBot.getInstance().getAudioManager().getMusicManager(guild);
                        if (player == null || mm == null || voiceChannel == null)
                            return;
                        if (mm.getTrackScheduler().getCurrentTrack().getRequestedChannel() != null) {
                            channel = mm.getTrackScheduler().getCurrentTrack().getRequestedChannel();
                        }
                        if (voiceState.isGuildMuted()) {
                            channel.sendMessage(EmoteReference.SAD + "Pausing player because I got muted :(").queue();
                            player.setPaused(true);
                        }
                        if (voiceChannel.getMembers().size() == 1) {
                            channel.sendMessage(EmoteReference.THINKING + "I decided to leave **" + voiceChannel.getName() + "** " + "because I was left all " + "alone :<").queue();
                            if (mm.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null) {
                                mm.getTrackScheduler().getAudioPlayer().getPlayingTrack().stop();
                                mm.getTrackScheduler().getQueue().clear();
                                mm.getTrackScheduler().next(true);
                            } else {
                                guild.getAudioManager().closeAudioConnection();
                            }
                        }
                    }
                }
            }
        } catch (Exception ignored) {
        }
    });
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Guild(net.dv8tion.jda.core.entities.Guild)

Aggregations

GuildVoiceState (net.dv8tion.jda.core.entities.GuildVoiceState)4 TextChannel (net.dv8tion.jda.core.entities.TextChannel)4 GuildMusicManager (net.kodehawa.mantarobot.commands.music.GuildMusicManager)4 TrackScheduler (net.kodehawa.mantarobot.commands.music.requester.TrackScheduler)3 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)1 Guild (net.dv8tion.jda.core.entities.Guild)1 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)1