Search in sources :

Example 1 with GuildMusicManager

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

the class Clear method handle.

@Override
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    final Member member = ctx.getMember();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    final List<AudioTrack> queue = musicManager.scheduler.queue;
    if (queue.isEmpty()) {
        channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
        return;
    }
    musicManager.scheduler.queue.clear();
    EmbedBuilder builder = Embeds.createBuilder(null, "💥 The queue has been cleared", 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) Member(net.dv8tion.jda.api.entities.Member)

Example 2 with GuildMusicManager

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

the class Favourite method handle.

@Override
public void handle(CommandContext ctx) {
    TextChannel channel = ctx.getChannel();
    long guildId = ctx.getGuild().getIdLong();
    long userId = ctx.getMember().getIdLong();
    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;
    }
    AudioTrack playingTrack = musicManager.scheduler.player.getPlayingTrack();
    ArrayList<HashMap<String, String>> favourites = RedisDataStore.getInstance().getFavourites(guildId, userId);
    for (HashMap<String, String> entry : favourites) {
        if (entry.get("identifier").equals(playingTrack.getIdentifier())) {
            channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "This track is already in your list", null, null, null).build()).queue();
            return;
        }
    }
    ObjectId objectId = new ObjectId();
    RedisDataStore.getInstance().addFavourite(guildId, userId, playingTrack, ctx.getGuild(), String.valueOf(objectId));
    DatabaseManager.INSTANCE.addFavourite(guildId, userId, playingTrack, ctx.getGuild(), String.valueOf(objectId));
    channel.sendMessageEmbeds(Embeds.createBuilder(null, "Added this track to your favourites", null, null, null).build()).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) HashMap(java.util.HashMap) ObjectId(org.bson.types.ObjectId) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 3 with GuildMusicManager

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

the class SpotifyAudioSource method searchTrack.

@Override
public void searchTrack(CommandContext ctx, String query, EventWaiter waiter) {
    try {
        TextChannel channel = ctx.getChannel();
        Paging<Track> execute = this.spi.searchTracks(query).build().execute();
        Track[] items = execute.getItems();
        if (items[0] == null) {
            ctx.getChannel().sendMessageEmbeds(Embeds.createBuilder(null, "Couldn't find anything on spotify", null, null, null).build()).queue();
            return;
        }
        EmbedBuilder builder = EmbedUtils.getDefaultEmbed();
        builder.setDescription("Select a track. You have 15 seconds");
        final int trackCount = Math.min(items.length, 20);
        String s = UUID.randomUUID().toString();
        SelectionMenu.Builder menu = SelectionMenu.create(s);
        menu.setPlaceholder("Select your track here");
        menu.setRequiredRange(1, 1);
        for (int i = 0; i < trackCount; i++) {
            final Track track = items[i];
            menu.addOption(track.getName(), track.getName() + " " + track.getArtists()[0].getName() + " index " + i, track.getArtists()[0].getName());
        }
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
        channel.sendMessageEmbeds(builder.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) -> {
                String q = e.getValues().get(0);
                q = q.substring(0, q.indexOf("index")).trim();
                final String sQuery = "ytsearch:" + q;
                PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, sQuery, new AudioLoadResultHandler() {

                    @Override
                    public void trackLoaded(AudioTrack track) {
                    }

                    @Override
                    public void playlistLoaded(AudioPlaylist playlist) {
                        List<AudioTrack> tracks = playlist.getTracks();
                        if (tracks.isEmpty())
                            return;
                        AudioTrack audioTrack = tracks.get(0);
                        message.delete().queue();
                        channel.sendMessageEmbeds(Embeds.songEmbed(ctx.getMember(), audioTrack).build()).queue();
                        audioTrack.setUserData(ctx.getAuthor().getIdLong());
                        musicManager.scheduler.queue(audioTrack);
                    }

                    @Override
                    public void noMatches() {
                    }

                    @Override
                    public void loadFailed(FriendlyException exception) {
                    }
                });
            }, 15, TimeUnit.SECONDS, () -> {
                message.delete().queue();
            });
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException) IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) ArrayList(java.util.ArrayList) List(java.util.List) SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Example 4 with GuildMusicManager

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

the class SpotifyAudioSource method getTrack.

public void getTrack(CommandContext ctx, String url) {
    final Matcher res = SPOTIFY_TRACK_REGEX.matcher(url);
    if (!res.matches()) {
        return;
    }
    try {
        GetTrackRequest request = this.spi.getTrack(res.group(res.groupCount())).build();
        Track track = request.execute();
        LOGGER.info("Name: " + track.getName());
        LOGGER.info("Artist: " + track.getArtists()[0].getName());
        String query = "ytsearch:" + track.getName() + " " + track.getArtists()[0].getName();
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
        PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, query, new AudioLoadResultHandler() {

            @Override
            public void trackLoaded(AudioTrack track) {
                System.out.println("track loaded");
            }

            @Override
            public void playlistLoaded(AudioPlaylist playlist) {
                boolean empty = playlist.getTracks().isEmpty();
                if (empty) {
                    return;
                }
                AudioTrack audioTrack = playlist.getTracks().get(0);
                audioTrack.setUserData(ctx.getAuthor().getIdLong());
                ctx.getChannel().sendMessageEmbeds(Embeds.songEmbed(ctx.getMember(), audioTrack).setDescription("[" + audioTrack.getInfo().title + " - " + audioTrack.getInfo().author + "]" + "(" + track.getExternalUrls().get("spotify") + ")").build()).queue();
                musicManager.scheduler.queue(audioTrack);
            }

            @Override
            public void noMatches() {
            }

            @Override
            public void loadFailed(FriendlyException exception) {
            }
        });
    } catch (IOException | SpotifyWebApiException | ParseException e) {
        e.printStackTrace();
    }
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) Matcher(java.util.regex.Matcher) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) IOException(java.io.IOException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) GetTrackRequest(se.michaelthelin.spotify.requests.data.tracks.GetTrackRequest) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) ParseException(org.apache.hc.core5.http.ParseException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Example 5 with GuildMusicManager

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

the class SpotifyAudioSource method getAlbum.

public void getAlbum(CommandContext ctx, String url) {
    final Matcher res = SPOTIFY_ALBUM_REGEX.matcher(url);
    if (!res.matches()) {
        return;
    }
    try {
        final Future<Album> albumFuture = this.spi.getAlbum(res.group(res.groupCount())).build().executeAsync();
        final Album album = albumFuture.get();
        TrackSimplified[] items = album.getTracks().getItems();
        ctx.getChannel().sendMessageEmbeds(Embeds.createBuilder(null, "Spotify Album Loaded : Adding " + items.length + " Tracks to the queue", null, null, null).build()).queue();
        for (final TrackSimplified track : items) {
            GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
            final String query = "ytsearch:" + track.getName() + " " + track.getArtists()[0].getName();
            PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, query, new AudioLoadResultHandler() {

                @Override
                public void trackLoaded(AudioTrack track) {
                }

                @Override
                public void playlistLoaded(AudioPlaylist playlist) {
                    boolean empty = playlist.getTracks().isEmpty();
                    if (empty) {
                        return;
                    }
                    AudioTrack audioTrack = playlist.getTracks().get(0);
                    audioTrack.setUserData(ctx.getAuthor().getIdLong());
                    musicManager.scheduler.queue(audioTrack);
                }

                @Override
                public void noMatches() {
                }

                @Override
                public void loadFailed(FriendlyException exception) {
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) Matcher(java.util.regex.Matcher) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException) IOException(java.io.IOException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

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