Search in sources :

Example 41 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Rubicon by Rubicon-Bot.

the class MusicSearchResult method generateEmbed.

public EmbedBuilder generateEmbed() {
    EmbedBuilder builder = new EmbedBuilder();
    builder.setColor(Colors.COLOR_PRIMARY);
    int i = 0;
    StringBuilder description = new StringBuilder();
    for (AudioTrack track : trackList) {
        description.append(emotes[i]).append("  [").append(track.getInfo().title).append("](").append(track.getInfo().uri).append(")\n\n");
        i++;
    }
    builder.setFooter("Type in your choose. <1-5> (After 15 seconds the request will be deleted)", null);
    builder.setDescription(description.toString());
    return builder;
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 42 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project MantaroBot by Mantaro.

the class AudioLoader method loadSingle.

private void loadSingle(AudioTrack audioTrack, boolean silent) {
    AudioTrackInfo trackInfo = audioTrack.getInfo();
    audioTrack.setUserData(event.getAuthor().getId());
    DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
    DBUser dbUser = MantaroData.db().getUser(event.getMember());
    GuildData guildData = dbGuild.getData();
    String title = trackInfo.title;
    long length = trackInfo.length;
    long queueLimit = !Optional.ofNullable(dbGuild.getData().getMusicQueueSizeLimit()).isPresent() ? MAX_QUEUE_LENGTH : dbGuild.getData().getMusicQueueSizeLimit();
    int fqSize = guildData.getMaxFairQueue();
    if (musicManager.getTrackScheduler().getQueue().size() > queueLimit && !dbUser.isPremium() && !dbGuild.isPremium()) {
        if (!silent)
            event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Surpassed queue song limit!", title)).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
        return;
    }
    if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !dbUser.isPremium() && !dbGuild.isPremium()) {
        event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 32 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
        return;
    }
    // Comparing if the URLs are the same to be 100% sure they're just not spamming the same url over and over again.
    if (musicManager.getTrackScheduler().getQueue().stream().filter(track -> track.getInfo().uri.equals(audioTrack.getInfo().uri)).count() > fqSize && !silent) {
        event.getChannel().sendMessage(EmoteReference.ERROR + String.format("**Surpassed fair queue level of %d (Too many songs which are exactly equal)**", fqSize + 1)).queue();
        return;
    }
    musicManager.getTrackScheduler().queue(audioTrack, insertFirst);
    musicManager.getTrackScheduler().setRequestedChannel(event.getChannel().getIdLong());
    if (!silent) {
        event.getChannel().sendMessage(new MessageBuilder().append(String.format("\uD83D\uDCE3 Added to queue -> **%s** **(%s)**", title, AudioUtils.getLength(length))).stripMentions(event.getGuild(), Message.MentionType.EVERYONE, Message.MentionType.HERE).build()).queue();
    }
    MantaroBot.getInstance().getStatsClient().increment("tracks_loaded");
}
Also used : Utils(net.kodehawa.mantarobot.utils.Utils) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) Message(net.dv8tion.jda.core.entities.Message) MantaroBot(net.kodehawa.mantarobot.MantaroBot) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) DBUser(net.kodehawa.mantarobot.db.entities.DBUser) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) SentryHelper(net.kodehawa.mantarobot.utils.SentryHelper) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) AudioUtils(net.kodehawa.mantarobot.commands.music.utils.AudioUtils) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) DBUser(net.kodehawa.mantarobot.db.entities.DBUser)

Example 43 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project MantaroBot by Mantaro.

the class MusicCmds method skipahead.

@Subscribe
public void skipahead(CommandRegistry cr) {
    cr.register("skipahead", new SimpleCommand(Category.MUSIC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (args.length == 0) {
                onHelp(event);
                return;
            }
            GuildMusicManager manager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
            if (manager.getAudioPlayer().getPlayingTrack() == null) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "I'm not currently playing anything").queue();
                return;
            }
            if (isDJ(event.getMember())) {
                try {
                    long amt = Utils.parseTime(args[0]);
                    if (amt < 0) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "Positive integers only").queue();
                        return;
                    }
                    AudioTrack track = manager.getAudioPlayer().getPlayingTrack();
                    long position = track.getPosition();
                    if (position + amt > track.getDuration()) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "You can't skip past the duration of a song").queue();
                        return;
                    }
                    track.setPosition(position + amt);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Skipped ahead to " + AudioUtils.getLength(position + amt) + ".").queue();
                } catch (NumberFormatException ex) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You need to provide a valid query.").queue();
                }
            } else
                event.getChannel().sendMessage(EmoteReference.ERROR + "You need to be a music DJ to use this command!").queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Skip Ahead Command").addField("Description", "Fast forward the current song a specified amount of time", false).addField("Usage", "~>skipahead <time>\nTime is in this format: 1m29s (1 minute and 29s)", false).build();
        }
    });
    cr.registerAlias("skipahead", "forward");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 44 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project c0debaseBot by Biospheere.

the class MusicManager method loadTrack.

public void loadTrack(TextChannel channel, User requester, String trackUrl) {
    Guild guild = channel.getGuild();
    loadTrack(guild, trackUrl, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            queue(guild, track);
            EmbedBuilder eb = getEmbed(guild, requester).setAuthor("Track geladen", trackUrl.startsWith("http") ? trackUrl : null, bot.getJda().getSelfUser().getEffectiveAvatarUrl());
            AudioTrackInfo trackInfo = track.getInfo();
            String length;
            if (TimeUnit.MILLISECONDS.toHours(trackInfo.length) >= 24) {
                length = String.format("%dd %02d:%02d:%02d", TimeUnit.MILLISECONDS.toDays(trackInfo.length), TimeUnit.MILLISECONDS.toHours(trackInfo.length) % 24, TimeUnit.MILLISECONDS.toMinutes(trackInfo.length) % 60, TimeUnit.MILLISECONDS.toSeconds(trackInfo.length) % 60);
            } else {
                length = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(trackInfo.length) % 24, TimeUnit.MILLISECONDS.toMinutes(trackInfo.length) % 60, TimeUnit.MILLISECONDS.toSeconds(trackInfo.length) % 60);
            }
            eb.addField(trackInfo.title, "`" + trackInfo.author + " - " + (trackInfo.isStream ? "STREAM" : length) + "`", false);
            channel.sendMessage(eb.build()).queue();
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            List<AudioTrack> tracks = playlist.getTracks();
            if (playlist.isSearchResult()) {
                trackLoaded(tracks.get(0));
                return;
            }
            EmbedBuilder eb = getEmbed(guild, requester).setAuthor("Playlist geladen", playlist.isSearchResult() ? null : trackUrl, bot.getJda().getSelfUser().getEffectiveAvatarUrl());
            eb.addField(playlist.getName(), "`" + tracks.size() + " Videos gefunden`", false);
            channel.sendMessage(eb.build()).queue();
            queue(guild, tracks);
            nextTrack(guild, false);
        }

        @Override
        public void noMatches() {
            channel.sendMessage(getEmbed(guild, requester).setAuthor("Nichts gefunden", null, bot.getJda().getSelfUser().getEffectiveAvatarUrl()).addField("Keine Übereinstimmung", "`" + trackUrl + "`", false).build()).queue();
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            channel.sendMessage(getEmbed(guild, requester).setAuthor("Fehler aufgetreten", null, bot.getJda().getSelfUser().getEffectiveAvatarUrl()).addField("Fehlermeldung", "`" + exception.getMessage() + "`", false).build()).queue();
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) List(java.util.List) Guild(net.dv8tion.jda.core.entities.Guild) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 45 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project MantaroBot by Mantaro.

the class AudioRequester method playlistLoaded.

@Override
public void playlistLoaded(AudioPlaylist playlist) {
    if (playlist.isSearchResult()) {
        if (!skipSelection)
            onSearchResult(playlist);
        else
            loadSingle(playlist.getTracks().get(0), false);
        return;
    }
    int i = 0;
    for (AudioTrack track : playlist.getTracks()) {
        if (MantaroData.db().getGuild(event.getGuild()).getData().getMusicQueueSizeLimit() != null) {
            if (i < MantaroData.db().getGuild(event.getGuild()).getData().getMusicQueueSizeLimit()) {
                loadSingle(track, true);
            } else {
                event.getChannel().sendMessage(String.format(":warning: The queue you added had more than %d songs, so we added songs until this limit and ignored the rest.", MantaroData.db().getGuild(event.getGuild()).getData().getMusicQueueSizeLimit())).queue();
                break;
            }
        } else {
            if (i < MAX_QUEUE_LENGTH) {
                loadSingle(track, true);
            } else {
                event.getChannel().sendMessage(":warning: The queue you added had more than 300 songs, so we added songs until this limit and ignored the rest.").queue();
                break;
            }
        }
        i++;
    }
    event.getChannel().sendMessage(String.format("Added **%d songs** to queue on playlist: **%s** *(%s)*", i, playlist.getName(), Utils.getDurationMinutes(playlist.getTracks().stream().mapToLong(temp -> temp.getInfo().length).sum()))).queue();
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) Color(java.awt.Color) Utils(net.kodehawa.mantarobot.utils.Utils) IntConsumer(java.util.function.IntConsumer) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) ReactionOperations(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)85 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)26 ArrayList (java.util.ArrayList)23 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)21 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)18 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)17 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)11 List (java.util.List)10 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)9 IOException (java.io.IOException)9 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)8 TimeUnit (java.util.concurrent.TimeUnit)7 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)7 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)6 Optional (java.util.Optional)6 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)6 Permission (net.dv8tion.jda.core.Permission)6 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)5 InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)5 Slf4j (lombok.extern.slf4j.Slf4j)5