Search in sources :

Example 1 with AutoPlayException

use of main.exceptions.AutoPlayException in project Robertify-Bot by bombies.

the class SkipToCommand method handleSkip.

public EmbedBuilder handleSkip(User skipper, ConcurrentLinkedQueue<AudioTrack> queue, GuildMusicManager musicManager, int id) {
    if (id > queue.size() || id <= 0)
        return RobertifyEmbedUtils.embedMessage(musicManager.getGuild(), "ID provided isn't a valid ID!");
    final var audioPlayer = musicManager.getPlayer();
    final var scheduler = musicManager.getScheduler();
    final var guild = musicManager.getGuild();
    List<AudioTrack> currentQueue = new ArrayList<>(queue);
    List<AudioTrack> songsToRemoveFromQueue = new ArrayList<>();
    for (int i = 0; i < id - 1; i++) songsToRemoveFromQueue.add(currentQueue.get(i));
    queue.removeAll(songsToRemoveFromQueue);
    audioPlayer.seekTo(0);
    HashMap<Long, Stack<AudioTrack>> pastQueue = scheduler.getPastQueue();
    if (!pastQueue.containsKey(guild.getIdLong()))
        pastQueue.put(guild.getIdLong(), new Stack<>());
    AudioTrack playingTrack = audioPlayer.getPlayingTrack();
    pastQueue.get(guild.getIdLong()).push(playingTrack);
    try {
        scheduler.nextTrack(playingTrack, true, playingTrack.getPosition());
    } catch (AutoPlayException ignored) {
    }
    if (new DedicatedChannelConfig().isChannelSet(guild.getIdLong()))
        new DedicatedChannelConfig().updateMessage(guild);
    LofiCommand.getLofiEnabledGuilds().remove(guild.getIdLong());
    new LogUtils().sendLog(guild, LogType.TRACK_SKIP, skipper.getAsMention() + " has skipped to `track #" + id + "`");
    SkipCommand.clearVoteSkipInfo(guild);
    return RobertifyEmbedUtils.embedMessage(musicManager.getGuild(), "Skipped to **track #" + id + "**!");
}
Also used : ArrayList(java.util.ArrayList) LogUtils(main.utils.json.logs.LogUtils) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AutoPlayException(main.exceptions.AutoPlayException) DedicatedChannelConfig(main.utils.json.dedicatedchannel.DedicatedChannelConfig) Stack(java.util.Stack)

Aggregations

AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 ArrayList (java.util.ArrayList)1 Stack (java.util.Stack)1 AutoPlayException (main.exceptions.AutoPlayException)1 DedicatedChannelConfig (main.utils.json.dedicatedchannel.DedicatedChannelConfig)1 LogUtils (main.utils.json.logs.LogUtils)1