Search in sources :

Example 66 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 67 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 68 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)

Example 69 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 70 with AudioTrack

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

the class GetUrl method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    AudioManager audioManager = guild.getAudioManager();
    if (audioManager.isConnected()) {
        try {
            GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
            BlockingQueue<ArdentTrack> queue = manager.scheduler.manager.getQueue();
            if (args.length > 1) {
                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();
                        AudioTrackInfo info = track.getInfo();
                        String name = info.title;
                        if (current == numberToRemove) {
                            sendTranslatedMessage("The streaming link for {0} is {1}".replace("{0}", info.title).replace("{1}", info.uri), channel, user);
                            return;
                        }
                        current++;
                    }
                }
            } else {
                ArdentMusicManager musicManager = manager.scheduler.manager;
                ArdentTrack track = musicManager.getCurrentlyPlaying();
                if (track != null) {
                    AudioTrackInfo info = track.getTrack().getInfo();
                    sendTranslatedMessage("The streaming link for {0} is {1}".replace("{0}", info.title).replace("{1}", info.uri), channel, user);
                } else {
                    sendTranslatedMessage("I'm not playing anything right now!", channel, user);
                }
            }
        } catch (NumberFormatException ex) {
            sendTranslatedMessage("Invalid arguments", channel, user);
        }
    } else
        sendTranslatedMessage("I'm not in a voice channel!", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

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