Search in sources :

Example 11 with GuildMusicManager

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

the class Queue method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    final List<AudioTrack> queue = musicManager.scheduler.queue;
    if (queue.isEmpty()) {
        channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
        return;
    }
    final int trackCount = Math.min(queue.size(), 20);
    final List<AudioTrack> trackList = new ArrayList<>(queue);
    EmbedBuilder builder = EmbedUtils.getDefaultEmbed();
    builder.setTitle("Queue for " + ctx.getGuild().getName() + " 📀");
    builder.setFooter("Requested by " + ctx.getMember().getEffectiveName(), ctx.getMember().getEffectiveAvatarUrl());
    for (int i = 0; i < trackCount; i++) {
        final AudioTrack track = trackList.get(i);
        final AudioTrackInfo info = track.getInfo();
        builder.appendDescription(i + 1 + ". `" + info.title + "" + " by " + info.author + "`" + "\n");
    }
    if (trackList.size() > trackCount) {
        builder.appendDescription("And `" + String.valueOf(trackList.size() - trackCount) + "` more...");
    }
    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) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 12 with GuildMusicManager

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

the class Remove method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    Guild guild = ctx.getGuild();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);
    List<AudioTrack> queue = musicManager.scheduler.queue;
    if (queue.isEmpty()) {
        channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
        return;
    }
    String s = UUID.randomUUID().toString();
    SelectionMenu.Builder menu = SelectionMenu.create(s);
    menu.setPlaceholder("Select a track here");
    menu.setRequiredRange(1, 1);
    for (AudioTrack track : queue) {
        AudioTrackInfo info = track.getInfo();
        menu.addOption(info.title, String.valueOf(queue.indexOf(track)), info.author);
    }
    channel.sendMessageEmbeds(Embeds.createBuilder(null, "Select a track that you want to remove", null, null, null).build()).setActionRow(menu.build()).queue((message) -> {
        waiter.waitForEvent(SelectionMenuEvent.class, (e) -> {
            if (!(e.getChannel() == channel && e.getMember() != null && !e.getMember().getUser().isBot() && e.getComponentId().equals(s))) {
                return false;
            }
            if (e.getMember() != ctx.getMember()) {
                e.reply("This menu is not for you").setEphemeral(true).queue();
                return false;
            }
            return true;
        }, (e) -> {
            int index = Integer.parseInt(e.getValues().get(0));
            message.delete().queue();
            try {
                queue.remove(index);
                channel.sendMessageEmbeds(Embeds.createBuilder(null, "Track removed successfully", null, null, null).build()).queue();
            } catch (Exception ex) {
                channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Error removing the track", null, null, null).build()).queue();
            }
        }, 10, TimeUnit.SECONDS, () -> {
            message.delete().queue();
        });
    });
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu) Guild(net.dv8tion.jda.api.entities.Guild)

Example 13 with GuildMusicManager

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

the class Restart method handle.

@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.scheduler.player;
    if (audioPlayer.getPlayingTrack() == null) {
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "There is no track currently playing", null, null, null).build()).queue();
        return;
    }
    audioPlayer.setPaused(false);
    audioPlayer.getPlayingTrack().setPosition(0);
    channel.sendMessageEmbeds(Embeds.createBuilder(null, "Track starting from beginning", null, null, null).build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer)

Example 14 with GuildMusicManager

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

the class SkipTo method handle.

@Override
public void handle(CommandContext ctx) {
    TextChannel channel = ctx.getChannel();
    List<String> args = ctx.getArgs();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    List<AudioTrack> queue = musicManager.scheduler.queue;
    if (args.isEmpty()) {
        // TODO: ERROR
        return;
    }
    if (queue.isEmpty()) {
        channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
        return;
    }
    int i1 = -1;
    try {
        i1 = Integer.parseInt(args.get(0)) - 1;
    } catch (NumberFormatException e) {
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Wrong input", null, null, null).build()).queue();
        return;
    }
    if (i1 < 0) {
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Wrong input", null, null, null).build()).queue();
        return;
    }
    if (i1 > queue.size()) {
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Wrong input", null, null, null).build()).queue();
        return;
    }
    musicManager.scheduler.player.startTrack(queue.get(i1), false);
    for (int i = 0; i < i1 + 1; i++) {
        queue.remove(i);
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 15 with GuildMusicManager

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

the class Stop method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    if (musicManager.scheduler.player.getPlayingTrack() == null) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    musicManager.scheduler.player.stopTrack();
    musicManager.scheduler.queue.clear();
    musicManager.scheduler.isRepeating = false;
    EmbedBuilder builder = Embeds.createBuilder(null, "💥 Player stopped and cleared the queue", 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)

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