Search in sources :

Example 11 with AudioPlayback

use of net.robinfriedli.aiode.audio.AudioPlayback in project aiode by robinfriedli.

the class ReverseCommand method onSuccess.

@Override
public void onSuccess() {
    AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(getContext().getGuild());
    long currentPositionMs = playback.getCurrentPositionMs();
    sendSuccess("Set position to " + Util.normalizeMillis(currentPositionMs));
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback)

Example 12 with AudioPlayback

use of net.robinfriedli.aiode.audio.AudioPlayback in project aiode by robinfriedli.

the class RewindCommand method doRun.

@Override
public void doRun() {
    AudioManager audioManager = Aiode.get().getAudioManager();
    Guild guild = getContext().getGuild();
    AudioPlayback playback = audioManager.getPlaybackForGuild(guild);
    AudioQueue queue = playback.getAudioQueue();
    VoiceChannel channel = getContext().getVoiceChannel();
    if (!queue.hasPrevious()) {
        throw new InvalidCommandException("No previous item in queue");
    }
    int queueSize = queue.getTracks().size();
    if (getCommandInput().isBlank()) {
        queue.reverse();
    } else {
        int offset;
        try {
            offset = Integer.parseInt(getCommandInput());
        } catch (NumberFormatException e) {
            throw new InvalidCommandException(getCommandInput() + " is not an integer");
        }
        if (offset < 1) {
            throw new InvalidCommandException("Expected a number grater than 0");
        }
        boolean deficient = queue.getPosition() - offset < 0;
        int newIndex;
        if (!playback.isRepeatAll() && deficient) {
            newIndex = 0;
        } else if (deficient) {
            // if the current index is 20 with 50 tracks in the queue and the user wants to rewind 24, the result should be 46
            int provisional = queue.getPosition() - offset;
            int page = provisional / queueSize * (-1) + 1;
            newIndex = page * queueSize + provisional;
        } else {
            newIndex = queue.getPosition() - offset;
        }
        queue.setPosition(newIndex);
    }
    audioManager.startPlayback(guild, channel);
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild) AudioQueue(net.robinfriedli.aiode.audio.AudioQueue)

Example 13 with AudioPlayback

use of net.robinfriedli.aiode.audio.AudioPlayback in project aiode by robinfriedli.

the class SkipCommand method doRun.

@Override
public void doRun() {
    AudioManager audioManager = Aiode.get().getAudioManager();
    Guild guild = getContext().getGuild();
    AudioPlayback playback = audioManager.getPlaybackForGuild(guild);
    AudioQueue queue = playback.getAudioQueue();
    VoiceChannel channel = getContext().getVoiceChannel();
    if (!queue.hasNext()) {
        throw new InvalidCommandException("No next item in queue");
    }
    if (getCommandInput().isBlank()) {
        queue.iterate();
    } else {
        int offset;
        try {
            offset = Integer.parseInt(getCommandInput());
        } catch (NumberFormatException e) {
            throw new InvalidCommandException(getCommandInput() + " is not an integer");
        }
        if (offset < 1) {
            throw new InvalidCommandException("Expected a number greater than 0");
        }
        int newIndex;
        int queueSize = queue.getTracks().size();
        boolean overflow = queue.getPosition() + offset >= queueSize;
        if (!playback.isRepeatAll() && overflow) {
            newIndex = queueSize - 1;
        } else if (overflow) {
            // if the current index is 30 with 50 tracks in the queue and the user wants to skip 24, the result should be 4
            // if the user wants to skip 20, the result be 0
            int provisional = queue.getPosition() + offset;
            int page = provisional / queueSize;
            newIndex = provisional - (page * queueSize);
        } else {
            newIndex = queue.getPosition() + offset;
        }
        queue.setPosition(newIndex);
    }
    audioManager.startPlayback(guild, channel);
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild) AudioQueue(net.robinfriedli.aiode.audio.AudioQueue)

Example 14 with AudioPlayback

use of net.robinfriedli.aiode.audio.AudioPlayback in project aiode by robinfriedli.

the class VolumeCommand method doRun.

@Override
public void doRun() {
    AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(getContext().getGuild());
    int volume;
    try {
        volume = Integer.parseInt(getCommandInput());
    } catch (NumberFormatException e) {
        throw new InvalidCommandException("'" + getCommandInput() + "' is not an integer");
    }
    if (!(volume > 0 && volume <= 200)) {
        throw new InvalidCommandException("Expected a value between 1 and 200");
    }
    playback.setVolume(volume);
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException)

Example 15 with AudioPlayback

use of net.robinfriedli.aiode.audio.AudioPlayback in project aiode by robinfriedli.

the class VolumeCommand method onSuccess.

@Override
public void onSuccess() {
    AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(getContext().getGuild());
    sendSuccess("Volume set to: " + playback.getVolume());
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback)

Aggregations

AudioPlayback (net.robinfriedli.aiode.audio.AudioPlayback)25 Guild (net.dv8tion.jda.api.entities.Guild)13 AudioManager (net.robinfriedli.aiode.audio.AudioManager)9 AudioQueue (net.robinfriedli.aiode.audio.AudioQueue)7 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)6 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)5 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)4 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 IOException (java.io.IOException)2 LocalDateTime (java.time.LocalDateTime)2 MessageChannel (net.dv8tion.jda.api.entities.MessageChannel)2 Aiode (net.robinfriedli.aiode.Aiode)2 Playable (net.robinfriedli.aiode.audio.Playable)2 AccessConfiguration (net.robinfriedli.aiode.entities.AccessConfiguration)2 GuildSpecification (net.robinfriedli.aiode.entities.GuildSpecification)2 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)2 Strings (com.google.common.base.Strings)1 Sets (com.google.common.collect.Sets)1 OutputStream (java.io.OutputStream)1 Duration (java.time.Duration)1