Search in sources :

Example 21 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Seek method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.scheduler.player;
    if (ctx.getArgs().isEmpty()) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "Right format is MM:SS", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    if (audioPlayer.getPlayingTrack() == null) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    String arg = ctx.getArgs().get(0);
    Matcher match = Pattern.compile("([0-9]{1,2})[:ms](([0-9]{1,2})s?)?").matcher(arg);
    if (!match.matches()) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "Right format is MM:SS", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    long secs = -1;
    if (match.group(3).length() > 0) {
        int g1 = Integer.parseInt(match.group(1)) * 60;
        int g2 = Integer.parseInt(match.group(3));
        secs = g1 + g2;
    } else {
        secs = Integer.parseInt(match.group(1));
    }
    if (secs < 0) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "Error formatting timestamp !", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    audioPlayer.setPaused(false);
    audioPlayer.getPlayingTrack().setPosition(secs * 1000);
    EmbedBuilder builder = Embeds.createBuilder(null, "Sought", null, null, null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer)

Example 22 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Shuffle method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    List<AudioTrack> queue = musicManager.scheduler.queue;
    if (queue.isEmpty()) {
        channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
        return;
    }
    Collections.shuffle(musicManager.scheduler.queue);
    EmbedBuilder builder = Embeds.createBuilder(null, "Queue shuffled", null, null, null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 23 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Listener method onGuildVoiceUpdate.

@Override
public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
    if (event.getMember().getUser() != event.getGuild().getSelfMember().getUser()) {
        VoiceChannel channelLeft = event.getChannelLeft();
        if (channelLeft == null) {
            return;
        }
        List<Member> members = channelLeft.getMembers();
        List<Member> copy = new ArrayList<>();
        boolean canClose = false;
        for (Member member : members) {
            if (member.getUser() != event.getGuild().getSelfMember().getUser()) {
                copy.add(member);
            } else {
                canClose = true;
            }
        }
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
        if (canClose && !copy.isEmpty() && musicManager.scheduler.votingGoingOn) {
            musicManager.scheduler.totalMembers = copy;
        }
        if (copy.isEmpty() && canClose) {
            musicManager.scheduler.isRepeating = false;
            musicManager.scheduler.queue.clear();
            musicManager.scheduler.player.stopTrack();
            // **RESET EVERYTHING**
            musicManager.scheduler.totalMembers.clear();
            musicManager.scheduler.votes.clear();
            musicManager.scheduler.votingGoingOn = false;
            AudioManager audioManager = event.getGuild().getAudioManager();
            audioManager.closeAudioConnection();
        }
    } else if (event.getMember().getUser() == event.getGuild().getSelfMember().getUser()) {
        if (event.getChannelLeft() != null && event.getChannelJoined() != null) {
            VoiceChannel channelJoined = event.getChannelJoined();
            List<Member> members = channelJoined.getMembers();
            List<Member> copy = new ArrayList<>();
            boolean canClose = false;
            for (Member member : members) {
                if (member.getUser() != event.getGuild().getSelfMember().getUser()) {
                    copy.add(member);
                } else {
                    canClose = true;
                }
            }
            GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
            // **RESET EVERYTHING**
            musicManager.scheduler.totalMembers.clear();
            musicManager.scheduler.votes.clear();
            musicManager.scheduler.votingGoingOn = false;
            if (copy.isEmpty() && canClose) {
                musicManager.scheduler.isRepeating = false;
                musicManager.scheduler.queue.clear();
                musicManager.scheduler.player.stopTrack();
                AudioManager audioManager = event.getGuild().getAudioManager();
                audioManager.closeAudioConnection();
            }
        } else if (event.getChannelLeft() != null && event.getChannelJoined() == null) {
            GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
            musicManager.scheduler.isRepeating = false;
            musicManager.scheduler.queue.clear();
            musicManager.scheduler.player.stopTrack();
            // **RESET EVERYTHING**
            musicManager.scheduler.totalMembers.clear();
            musicManager.scheduler.votes.clear();
            musicManager.scheduler.votingGoingOn = false;
        }
    }
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class Listener method onGuildLeave.

@Override
public void onGuildLeave(@NotNull GuildLeaveEvent event) {
    this.jda.getPresence().setActivity(Activity.listening("help on " + event.getJDA().getGuilds().size() + " Guilds"));
    Member selfMember = event.getGuild().getSelfMember();
    if (selfMember.getVoiceState().inVoiceChannel()) {
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
        musicManager.scheduler.isRepeating = false;
        musicManager.scheduler.queue.clear();
        musicManager.scheduler.player.stopTrack();
        // **RESET EVERYTHING**
        musicManager.scheduler.totalMembers.clear();
        musicManager.scheduler.votes.clear();
        musicManager.scheduler.votingGoingOn = false;
        AudioManager audioManager = event.getGuild().getAudioManager();
        audioManager.closeAudioConnection();
    }
    PlayerManager.getInstance().removeGuildMusicManager(event.getGuild());
    LOGGER.info("Left " + event.getGuild().getName() + " guild Deleting the music manager");
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager)

Example 25 with GuildMusicManager

use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.

the class ForceSkip method handle.

@Override
public void handle(CommandContext ctx) {
    TextChannel channel = ctx.getChannel();
    Member member = ctx.getMember();
    GuildMusicManager manager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    if (!member.hasPermission(Permission.MESSAGE_MANAGE)) {
        channel.sendMessageEmbeds(Embeds.createBuilder(null, "You do not have enough permission", null, null, null).build()).queue();
        return;
    }
    if (manager.audioPlayer.getPlayingTrack() == null) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    if (manager.scheduler.votingGoingOn) {
        manager.scheduler.totalMembers.clear();
        manager.scheduler.votes.clear();
        manager.scheduler.votingGoingOn = false;
    }
    manager.scheduler.nextTrack();
    EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

GuildMusicManager (me.fero.ascent.lavaplayer.GuildMusicManager)26 TextChannel (net.dv8tion.jda.api.entities.TextChannel)21 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)15 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)13 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)8 Member (net.dv8tion.jda.api.entities.Member)8 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)5 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)5 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ParseException (org.apache.hc.core5.http.ParseException)4 SpotifyWebApiException (se.michaelthelin.spotify.exceptions.SpotifyWebApiException)4 List (java.util.List)3 Matcher (java.util.regex.Matcher)3 AudioManager (net.dv8tion.jda.api.managers.AudioManager)3 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)2 HashMap (java.util.HashMap)2 SelectionMenu (net.dv8tion.jda.api.interactions.components.selections.SelectionMenu)2 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)1