Search in sources :

Example 1 with AudioTrack

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

the class AudioRequester method loadSingle.

private void loadSingle(AudioTrack audioTrack, boolean silent) {
    AudioTrackInfo trackInfo = audioTrack.getInfo();
    DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
    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 (getMusicManager().getTrackScheduler().getQueue().size() > queueLimit && !MantaroData.db().getUser(event.getMember()).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));
        if (musicManager.getTrackScheduler().isStopped())
            event.getGuild().getAudioManager().closeAudioConnection();
        return;
    }
    if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
        event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 21 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
        if (musicManager.getTrackScheduler().isStopped())
            //do you?
            event.getGuild().getAudioManager().closeAudioConnection();
        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) {
        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(new AudioTrackContext(event.getAuthor(), event.getChannel(), audioTrack.getSourceManager() instanceof YoutubeAudioSourceManager ? "https://www.youtube.com/watch?v=" + audioTrack.getIdentifier() : trackUrl, audioTrack));
    if (!silent) {
        event.getChannel().sendMessage(String.format("📣 Added to queue -> **%s** **!(%s)**", title, AudioUtils.getLength(length))).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) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 2 with AudioTrack

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

the class NowPlayingCommand method execute.

@Override
public void execute(String[] args, Message msg) {
    EmbedBuilder embedBuilder = getEmbed(msg.getGuild(), msg.getAuthor());
    if (CodebaseBot.getInstance().getMusicManager().getPlayingTrack(msg.getGuild()) != null) {
        AudioTrack audioTrack = CodebaseBot.getInstance().getMusicManager().getPlayingTrack(msg.getGuild());
        embedBuilder.setDescription("**" + audioTrack.getInfo().title + "**");
    } else {
        embedBuilder.setDescription("Es wird gerade nichts gespielt");
    }
    msg.getTextChannel().sendMessage(embedBuilder.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 3 with AudioTrack

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

the class MusicCmds method nextSong.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
            TrackScheduler scheduler = musicManager.getTrackScheduler();
            AudioTrack next = scheduler.getQueue().peek();
            if (next == null) {
                event.getChannel().sendMessage(EmoteReference.TALKING + "Ow, there isn't any song next").queue();
            } else {
                event.getChannel().sendMessage(EmoteReference.MEGA + "Next song in queue: **" + next.getInfo().title + "** (" + Utils.getDurationMinutes(next.getDuration()) + ")" + " | *Total songs in queue: " + scheduler.getQueue().size() + "*").queue();
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Next Song Command").addField("Description", "**Shows the next song in queue!**", false).build();
        }
    });
    cr.registerAlias("ns", "nextsong");
}
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) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with AudioTrack

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

the class AudioLoader method playlistLoaded.

@Override
public void playlistLoaded(AudioPlaylist playlist) {
    if (playlist.isSearchResult()) {
        if (!skipSelection)
            onSearch(playlist);
        else
            loadSingle(playlist.getTracks().get(0), false);
        return;
    }
    try {
        int i = 0;
        for (AudioTrack track : playlist.getTracks()) {
            DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
            GuildData guildData = dbGuild.getData();
            if (guildData.getMusicQueueSizeLimit() != null) {
                if (i < guildData.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.", guildData.getMusicQueueSizeLimit())).queue();
                    break;
                }
            } else {
                if (i > MAX_QUEUE_LENGTH && !dbGuild.isPremium()) {
                    event.getChannel().sendMessage(":warning: The queue you added had more than " + MAX_QUEUE_LENGTH + " songs, so we added songs until this limit and ignored the rest.").queue();
                    // stop adding songs
                    break;
                } else {
                    loadSingle(track, true);
                }
            }
            i++;
        }
        event.getChannel().sendMessage(String.format("%sAdded **%d songs** to queue on playlist: **%s** *(%s)*", EmoteReference.CORRECT, i, playlist.getName(), Utils.getDurationMinutes(playlist.getTracks().stream().mapToLong(temp -> temp.getInfo().length).sum()))).queue();
    } catch (Exception e) {
        SentryHelper.captureExceptionContext("Cannot load playlist. I guess something broke pretty hard. Please check", e, this.getClass(), "Music Loader");
    }
}
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) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 5 with AudioTrack

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

the class AudioUtils method getQueueList.

public static String getQueueList(ConcurrentLinkedDeque<AudioTrack> queue) {
    StringBuilder sb = new StringBuilder();
    int n = 1;
    for (AudioTrack audioTrack : queue) {
        long aDuration = audioTrack.getDuration();
        String duration = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(aDuration), TimeUnit.MILLISECONDS.toSeconds(aDuration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(aDuration)));
        User dj = audioTrack.getUserData() != null ? MantaroBot.getInstance().getUserById(String.valueOf(audioTrack.getUserData())) : null;
        String title = audioTrack.getInfo().title;
        if (title.length() > 30)
            title = title.substring(0, 30) + "...";
        sb.append("**").append(n).append(". [").append(title).append("](").append(audioTrack.getInfo().uri).append(")** (").append(duration).append(")").append(dj != null ? " **[" + dj.getName() + "]**" : "").append("\n");
        n++;
    }
    return sb.toString();
}
Also used : User(net.dv8tion.jda.core.entities.User) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)72 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)21 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)20 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)17 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)17 ArrayList (java.util.ArrayList)16 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)11 List (java.util.List)10 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)7 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)6 IOException (java.io.IOException)6 Optional (java.util.Optional)6 TimeUnit (java.util.concurrent.TimeUnit)6 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)6 Permission (net.dv8tion.jda.core.Permission)6 Slf4j (lombok.extern.slf4j.Slf4j)5 MantaroData (net.kodehawa.mantarobot.data.MantaroData)5 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)5 Utils (net.kodehawa.mantarobot.utils.Utils)5 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)5