Search in sources :

Example 6 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.

the class StuckVoiceConnection method run.

@Override
public void run() {
    for (Shard shard : getShards()) {
        for (Guild guild : shard.jda.getGuilds()) {
            GuildMusicManager guildMusicManager = Music.getGuildAudioPlayer(guild, null, shard);
            AudioPlayer player = guildMusicManager.player;
            if (!player.isPaused() && guild.getAudioManager().getConnectedChannel() != null && guild.getAudioManager().getConnectedChannel().getMembers().size() > 1) {
                AudioTrack playingTrack = player.getPlayingTrack();
                if (playingTrack != null) {
                    long position = playingTrack.getPosition();
                    if (position == 0 || (position > 0 && !guild.getAudioManager().isConnected())) {
                        String textChannelId = voiceChannelsAtZeroDuration.get(guild.getId());
                        if (textChannelId == null) {
                            ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
                            TextChannel channel = ardentMusicManager.getChannel();
                            voiceChannelsAtZeroDuration.put(guild.getId(), channel.getId());
                        } else {
                            TextChannel channel = guild.getTextChannelById(textChannelId);
                            ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
                            if (ardentMusicManager != null) {
                                List<ArdentTrack> queue = ardentMusicManager.getQueueAsList();
                                shard.musicManagers.remove(Long.parseLong(guild.getId()));
                                GuildMusicManager manager = Music.getGuildAudioPlayer(guild, channel, shard);
                                for (ArdentTrack track : queue) {
                                    manager.scheduler.manager.addToQueue(new ArdentTrack(track.getAuthor(), track.getAddedFrom(), track.getTrack().makeClone()));
                                }
                            } else
                                shard.musicManagers.remove(Long.parseLong(guild.getId()));
                            if (channel == null)
                                channel = guild.getPublicChannel();
                            try {
                                channel.sendMessage("I detected that my audio connection was stuck and reset my player. #BlameDiscord").queue();
                            } catch (Exception e) {
                                new BotException(e);
                            }
                        }
                    }
                } else {
                    voiceChannelsAtZeroDuration.remove(guild.getId());
                }
            }
        }
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Guild(net.dv8tion.jda.core.entities.Guild) BotException(tk.ardentbot.core.misc.logging.BotException) TextChannel(net.dv8tion.jda.core.entities.TextChannel) BotException(tk.ardentbot.core.misc.logging.BotException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Shard(tk.ardentbot.main.Shard)

Example 7 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.

the class Playing method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
    ArdentMusicManager ardentMusicManager = manager.scheduler.manager;
    ArdentTrack nowPlaying = ardentMusicManager.getCurrentlyPlaying();
    if (nowPlaying != null) {
        AudioTrack track = nowPlaying.getTrack();
        AudioTrackInfo info = track.getInfo();
        StringBuilder sb = new StringBuilder();
        String queuedBy = "queued by";
        sb.append(info.title + ": " + info.author + " " + getCurrentTime(track) + "\n     *" + queuedBy + " " + UserUtils.getUserById(nowPlaying.getAuthor()).getName() + "* - [" + nowPlaying.getVotedToSkip().size() + " / " + Math.round(guild.getAudioManager().getConnectedChannel().getMembers().size() / 2) + "] votes to skip");
        sendTranslatedMessage(sb.toString(), sendTo(channel, guild), user);
    } else
        sendTranslatedMessage("I'm not playing anything right now!", channel, user);
}
Also used : AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 8 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.

the class Queue method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    StringBuilder sb = new StringBuilder();
    String queuedBy = "queued by";
    sb.append("__Music Queue__\n");
    BlockingQueue<ArdentTrack> queue = getGuildAudioPlayer(guild, channel).scheduler.manager.getQueue();
    Iterator<ArdentTrack> iterator = queue.iterator();
    int current = 1;
    ArrayList<AudioTrack> trackList = new ArrayList<>();
    while (iterator.hasNext()) {
        ArdentTrack ardentTrack = iterator.next();
        AudioTrack track = ardentTrack.getTrack();
        trackList.add(track);
        sb.append("#" + current + ": " + track.getInfo().title + ": " + track.getInfo().author + " " + getDuration(track) + "\n     *" + queuedBy + " " + GuildUtils.getShard(guild).jda.getUserById(ardentTrack.getAuthor()).getName() + "*\n");
        current++;
    }
    if (current == 1) {
        sb.append("There aren't any songs in the queue!");
    }
    sendTranslatedMessage(sb.toString(), sendTo(channel, guild), user);
}
Also used : ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 9 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.

the class Remove method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length > 1) {
        AudioManager audioManager = guild.getAudioManager();
        Member member = guild.getMember(user);
        if (audioManager.isConnected()) {
            try {
                GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
                BlockingQueue<ArdentTrack> queue = manager.scheduler.manager.getQueue();
                int numberToRemove = Integer.parseInt(args[1]) - 1;
                if (numberToRemove >= queue.size() || numberToRemove < 0)
                    sendTranslatedMessage("Invalid arguments", channel, user);
                else {
                    Iterator<ArdentTrack> iterator = queue.iterator();
                    int current = 0;
                    while (iterator.hasNext()) {
                        ArdentTrack ardentTrack = iterator.next();
                        AudioTrack track = ardentTrack.getTrack();
                        String name = track.getInfo().title;
                        if (current == numberToRemove) {
                            if (UserUtils.hasManageServerOrStaff(member) || ardentTrack.getAuthor().equalsIgnoreCase(user.getId()) || UserUtils.isBotCommander(member)) {
                                queue.remove(ardentTrack);
                                sendTranslatedMessage("Removed {0} from the queue".replace("{0}", name), sendTo(channel, guild), user);
                            } else {
                                sendTranslatedMessage("You need to have queued the song or have the Manage Server " + "permission", sendTo(channel, guild), user);
                            }
                        }
                        current++;
                    }
                }
            } catch (NumberFormatException ex) {
                sendTranslatedMessage("Invalid arguments", channel, user);
            }
        } else
            sendTranslatedMessage("I'm not in a voice channel!", channel, user);
    } else
        sendTranslatedMessage("That's not a number!", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 10 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.

the class Restart method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    GuildMusicManager musicManager = getGuildAudioPlayer(guild, channel);
    ArdentMusicManager player = musicManager.scheduler.manager;
    ArdentTrack current = player.getCurrentlyPlaying();
    if (current != null) {
        AudioManager audioManager = guild.getAudioManager();
        if (UserUtils.hasManageServerOrStaff(guild.getMember(user)) || user.getId().equalsIgnoreCase(current.getAuthor()) || UserUtils.isBotCommander(guild.getMember(user)) || (audioManager.isConnected() && audioManager.getConnectedChannel().getMembers().size() == 2)) {
            AudioTrack track = current.getTrack();
            track.setPosition(0);
            sendTranslatedMessage("Restarted the current track", channel, user);
        } else {
            sendTranslatedMessage("You need to have queued the song or have the Manage Server permission", sendTo(channel, guild), user);
        }
    } else
        sendTranslatedMessage("I'm not playing anything right now!", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)13 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)6 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)5 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)4 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)4 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)4 TimeUnit (java.util.concurrent.TimeUnit)4 Permission (net.dv8tion.jda.core.Permission)4 AudioManager (net.dv8tion.jda.core.managers.AudioManager)4 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)3 Color (java.awt.Color)3 Optional (java.util.Optional)3 IntConsumer (java.util.function.IntConsumer)3 Slf4j (lombok.extern.slf4j.Slf4j)3 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)3 ReactionOperations (net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations)3 MantaroData (net.kodehawa.mantarobot.data.MantaroData)3 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)3 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)3 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)3