Search in sources :

Example 6 with AudioTrackContext

use of fredboat.audio.queue.AudioTrackContext in project FredBoat by Frederikam.

the class ForwardCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player == null || player.isQueueEmpty()) {
        context.replyWithName(context.i18n("unpauseQueueEmpty"));
        return;
    }
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    long t;
    try {
        t = TextUtils.parseTimeString(context.args[0]);
    } catch (IllegalStateException e) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    AudioTrackContext atc = player.getPlayingTrack();
    AudioTrack at = atc.getTrack();
    // Ensure bounds
    t = Math.max(0, t);
    t = Math.min(atc.getEffectiveDuration(), t);
    player.seekTo(player.getPosition() + t);
    context.reply(context.i18nFormat("fwdSuccess", TextUtils.escapeAndDefuse(atc.getEffectiveTitle()), TextUtils.formatTime(t)));
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 7 with AudioTrackContext

use of fredboat.audio.queue.AudioTrackContext in project FredBoat by Frederikam.

the class SelectCommand method select.

static void select(CommandContext context, VideoSelectionCache videoSelectionCache) {
    Member invoker = context.invoker;
    VideoSelection selection = videoSelectionCache.get(invoker);
    if (selection == null) {
        context.reply(context.i18n("selectSelectionNotGiven"));
        return;
    }
    try {
        // Step 1: Parse the issued command for numbers
        // LinkedHashSet to handle order of choices + duplicates
        LinkedHashSet<Integer> requestChoices = new LinkedHashSet<>();
        // Combine all args and the command trigger if it is numeric
        String commandOptions = context.rawArgs;
        if (StringUtils.isNumeric(context.trigger)) {
            commandOptions = (context.trigger + " " + commandOptions).trim();
        }
        if (StringUtils.isNumeric(commandOptions)) {
            requestChoices.add(Integer.valueOf(commandOptions));
        } else if (TextUtils.isSplitSelect(commandOptions)) {
            requestChoices.addAll(TextUtils.getSplitSelect(commandOptions));
        }
        // Step 2: Use only valid numbers (usually 1-5)
        ArrayList<Integer> validChoices = new ArrayList<>();
        // Only include valid values which are 1 to <size> of the offered selection
        for (Integer value : requestChoices) {
            if (1 <= value && value <= selection.choices.size()) {
                validChoices.add(value);
                Metrics.selectionChoiceChosen.labels(value.toString()).inc();
            }
        }
        // any valid choices at all?
        if (validChoices.isEmpty()) {
            throw new NumberFormatException();
        } else {
            if (validChoices.size() > 1) {
                Metrics.multiSelections.labels(Integer.toString(validChoices.size())).inc();
            }
            AudioTrack[] selectedTracks = new AudioTrack[validChoices.size()];
            StringBuilder outputMsgBuilder = new StringBuilder();
            GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
            for (int i = 0; i < validChoices.size(); i++) {
                selectedTracks[i] = selection.choices.get(validChoices.get(i) - 1);
                String msg = context.i18nFormat("selectSuccess", validChoices.get(i), TextUtils.escapeAndDefuse(selectedTracks[i].getInfo().title), TextUtils.formatTime(selectedTracks[i].getInfo().length));
                if (i < validChoices.size()) {
                    outputMsgBuilder.append("\n");
                }
                outputMsgBuilder.append(msg);
                player.queue(new AudioTrackContext(Launcher.getBotController().getJdaEntityProvider(), selectedTracks[i], invoker));
            }
            videoSelectionCache.remove(invoker);
            TextChannel tc = Launcher.getBotController().getJdaEntityProvider().getTextChannelById(selection.channelId);
            if (tc != null) {
                CentralMessaging.editMessage(tc, selection.outMsgId, CentralMessaging.from(outputMsgBuilder.toString()));
            }
            player.setPause(false);
            context.deleteMessage();
        }
    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
        context.reply(context.i18nFormat("selectInterval", selection.choices.size()));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) VideoSelection(fredboat.audio.player.VideoSelectionCache.VideoSelection) TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Member(net.dv8tion.jda.core.entities.Member)

Example 8 with AudioTrackContext

use of fredboat.audio.queue.AudioTrackContext in project FredBoat by Frederikam.

the class SkipCommand method skipNext.

private void skipNext(GuildPlayer player, CommandContext context) {
    AudioTrackContext atc = player.getPlayingTrack();
    if (atc == null) {
        context.reply(context.i18n("skipTrackNotFound"));
    } else {
        String successMessage = context.i18nFormat("skipSuccess", 1, TextUtils.escapeAndDefuse(atc.getEffectiveTitle()));
        player.skipTracksForMemberPerms(context, Collections.singletonList(atc.getTrackId()), successMessage);
    }
}
Also used : AudioTrackContext(fredboat.audio.queue.AudioTrackContext)

Example 9 with AudioTrackContext

use of fredboat.audio.queue.AudioTrackContext in project FredBoat by Frederikam.

the class SkipCommand method skipGivenIndex.

private void skipGivenIndex(GuildPlayer player, CommandContext context) {
    int givenIndex;
    try {
        givenIndex = Integer.parseInt(context.args[0]);
    } catch (NumberFormatException e) {
        context.reply(context.i18nFormat("skipOutOfBounds", context.args[0], player.getTrackCount()));
        return;
    }
    if (givenIndex == 1) {
        skipNext(player, context);
        return;
    }
    if (player.getRemainingTracks().size() < givenIndex) {
        context.reply(context.i18nFormat("skipOutOfBounds", givenIndex, player.getTrackCount()));
        return;
    } else if (givenIndex < 1) {
        context.reply(context.i18n("skipNumberTooLow"));
        return;
    }
    AudioTrackContext atc = player.getTracksInRange(givenIndex - 1, givenIndex).get(0);
    String successMessage = context.i18nFormat("skipSuccess", givenIndex, TextUtils.escapeAndDefuse(atc.getEffectiveTitle()));
    player.skipTracksForMemberPerms(context, Collections.singletonList(atc.getTrackId()), successMessage);
}
Also used : AudioTrackContext(fredboat.audio.queue.AudioTrackContext)

Example 10 with AudioTrackContext

use of fredboat.audio.queue.AudioTrackContext in project FredBoat by Frederikam.

the class SeekCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player == null || player.isQueueEmpty()) {
        context.replyWithName(context.i18n("queueEmpty"));
        return;
    }
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    long t;
    try {
        t = TextUtils.parseTimeString(context.args[0]);
    } catch (IllegalStateException e) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    AudioTrackContext atc = player.getPlayingTrack();
    // Ensure bounds
    t = Math.max(0, t);
    t = Math.min(atc.getEffectiveDuration(), t);
    player.seekTo(atc.getStartPosition() + t);
    context.reply(context.i18nFormat("seekSuccess", TextUtils.escapeAndDefuse(atc.getEffectiveTitle()), TextUtils.formatTime(t)));
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext)

Aggregations

AudioTrackContext (fredboat.audio.queue.AudioTrackContext)14 GuildPlayer (fredboat.audio.player.GuildPlayer)9 Member (net.dv8tion.jda.core.entities.Member)5 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)4 SplitAudioTrackContext (fredboat.audio.queue.SplitAudioTrackContext)4 ArrayList (java.util.ArrayList)4 TextChannel (net.dv8tion.jda.core.entities.TextChannel)3 File (java.io.File)2 IOException (java.io.IOException)2 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)2 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)2 JSONObject (org.json.JSONObject)2 BandcampAudioTrack (com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack)1 BeamAudioTrack (com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack)1 HttpAudioTrack (com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack)1 SoundCloudAudioTrack (com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack)1 TwitchStreamAudioTrack (com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack)1 YoutubeAudioTrack (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack)1 MessageInput (com.sedmelluq.discord.lavaplayer.tools.io.MessageInput)1 MessageOutput (com.sedmelluq.discord.lavaplayer.tools.io.MessageOutput)1