Search in sources :

Example 16 with GuildMusicManager

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

the class LoadFav method handle.

@Override
public void handle(CommandContext ctx) {
    TextChannel channel = ctx.getChannel();
    long guildId = ctx.getGuild().getIdLong();
    long userId = ctx.getMember().getIdLong();
    ArrayList<HashMap<String, String>> favourites = RedisDataStore.getInstance().getFavourites(guildId, userId);
    if (favourites.isEmpty()) {
        channel.sendMessageEmbeds(Embeds.createBuilder(null, "Your list is empty...", null, null, null).build()).queue();
        return;
    }
    ArrayList<String> urls = new ArrayList<>();
    for (HashMap<String, String> entry : favourites) {
        urls.add(entry.get("link"));
    }
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    channel.sendMessageEmbeds(Embeds.createBuilder(null, "Loading " + ctx.getMember().getEffectiveName() + "'s favourite tracks", null, null, null).build()).queue();
    for (String url : urls) {
        PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, url, new AudioLoadResultHandler() {

            @Override
            public void trackLoaded(AudioTrack track) {
                track.setUserData(ctx.getAuthor().getIdLong());
                musicManager.scheduler.queue(track);
            }

            @Override
            public void playlistLoaded(AudioPlaylist playlist) {
            }

            @Override
            public void noMatches() {
            }

            @Override
            public void loadFailed(FriendlyException exception) {
            }
        });
    }
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) HashMap(java.util.HashMap) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) ArrayList(java.util.ArrayList) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Example 17 with GuildMusicManager

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

the class Loop method handle.

@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    final Member member = ctx.getMember();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    List<String> args = ctx.getArgs();
    EmbedBuilder builder = EmbedUtils.getDefaultEmbed();
    builder.setFooter("Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl());
    if (!args.isEmpty() && args.get(0).equalsIgnoreCase("status")) {
        builder.setDescription("➿ Loop is " + (musicManager.scheduler.isRepeating ? "Enabled" : "Disabled"));
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    final boolean newRepeating = !musicManager.scheduler.isRepeating;
    musicManager.scheduler.isRepeating = newRepeating;
    builder.setDescription("➿ Loop is " + (newRepeating ? "Enabled" : "Disabled"));
    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)

Example 18 with GuildMusicManager

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

the class Lyrics method handle.

@Override
public void handle(CommandContext ctx) {
    TextChannel channel = ctx.getChannel();
    List<String> args = ctx.getArgs();
    GLA gla = new GLA();
    if (!args.isEmpty()) {
        // try {
        // SongSearch search = gla.search(String.join(" ", args));
        // if(search.getHits().isEmpty()) {
        // channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Cannot fetch lyrics", null, null, null).build()).queue();
        // return;
        // }
        // String s = search.getHits().get(0).fetchLyrics().trim();
        // String s1 = s.replaceAll("\\[.*?\\]", "");
        // 
        // if(s1.length() >= 2000) {
        // channel.sendMessageEmbeds(Embeds.createBuilder(null, "[Click here for lyrics](" + search.getHits().get(0).getUrl() + ")", null, null, null).build()).queue();
        // return;
        // }
        // Member member = ctx.getMember();
        // channel.sendMessageEmbeds(Embeds.createBuilder(search.getHits().get(0).getTitle(), s1, "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null).build()).queue();
        // return;
        // } catch (IOException e) {
        // e.printStackTrace();
        // channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Cannot fetch lyrics", null, null, null).build()).queue();
        // return;
        // }
        this.getLyrics(String.join(" ", args));
        return;
    }
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.audioPlayer;
    if (audioPlayer.getPlayingTrack() == null) {
        EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
        channel.sendMessageEmbeds(builder.build()).queue();
        return;
    }
    AudioTrack playingTrack = audioPlayer.getPlayingTrack();
    try {
        SongSearch search = gla.search(playingTrack.getInfo().title);
        LinkedList<SongSearch.Hit> hits = search.getHits();
        if (hits.isEmpty()) {
            channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Cannot fetch lyrics", null, null, null).build()).queue();
            return;
        }
        String s = search.getHits().get(0).fetchLyrics().trim();
        String s1 = s.replaceAll("\\[.*?\\]", "");
        if (s1.length() >= 2000) {
            channel.sendMessageEmbeds(Embeds.createBuilder(null, "(Click here for lyrics)[" + search.getHits().get(0).getUrl() + "]", null, null, null).build()).queue();
            return;
        }
        Member member = ctx.getMember();
        channel.sendMessageEmbeds(Embeds.createBuilder(search.getHits().get(0).getTitle(), s1, "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null).build()).queue();
    } catch (IOException e) {
        e.printStackTrace();
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Cannot fetch lyrics", null, null, null).build()).queue();
    }
}
Also used : SongSearch(genius.SongSearch) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) IOException(java.io.IOException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GLA(core.GLA) Member(net.dv8tion.jda.api.entities.Member)

Example 19 with GuildMusicManager

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

the class Resume method handle.

@Override
@SuppressWarnings("ConstantConditions")
public void handle(@NotNull CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    AudioPlayer audioPlayer = musicManager.audioPlayer;
    if (audioPlayer.getPlayingTrack() == null) {
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "There is no track currently playing", null, null, null).build()).queue();
        return;
    }
    AudioPlayer player = musicManager.scheduler.player;
    if (!player.isPaused()) {
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Player is already playing", null, null, null).build()).queue();
        return;
    }
    player.setPaused(false);
    channel.sendMessageEmbeds(Embeds.createBuilder(null, "Player resumed", 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 20 with GuildMusicManager

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

the class RmDuplicates method handle.

@Override
public void handle(CommandContext ctx) {
    TextChannel channel = ctx.getChannel();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    if (musicManager.scheduler.queue.isEmpty()) {
        channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Queue is currently empty", null, null, null).build()).queue();
        return;
    }
    if (musicManager.scheduler.removeDuplicates()) {
        channel.sendMessageEmbeds(Embeds.createBuilder(null, "Removed duplicates from the queue.", null, null, null).build()).queue();
        return;
    }
    channel.sendMessageEmbeds(Embeds.createBuilder(null, "No duplicates found", null, null, null).build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) 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