Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Added queue position and approx wait time. #402 #404

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@
import fredboat.messaging.internal.Context;
import fredboat.perms.PermissionLevel;
import fredboat.util.TextUtils;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.impl.MessageEmbedImpl;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.concurrent.TimeUnit;

public class SelectCommand extends Command implements IMusicCommand, ICommandRestricted {

Expand Down Expand Up @@ -107,25 +113,45 @@ static void select(CommandContext context) {
throw new NumberFormatException();
} else {
AudioTrack[] selectedTracks = new AudioTrack[validChoices.size()];
StringBuilder outputMsgBuilder = new StringBuilder();

EmbedBuilder embedBuilder = CentralMessaging.getColoredEmbedBuilder();
embedBuilder.setTitle(context.i18n("selectionEmbedTitle"));

for (int i = 0; i < validChoices.size(); i++) {
int positionInQueue = player.getTrackCount() + 1;

selectedTracks[i] = selection.choices.get(validChoices.get(i) - 1);

String msg = context.i18nFormat("selectSuccess", validChoices.get(i), selectedTracks[i].getInfo().title,
TextUtils.formatTime(selectedTracks[0].getInfo().length));
TextUtils.formatTime(selectedTracks[i].getInfo().length));

// if there are more selections.
if (i < validChoices.size()) {
outputMsgBuilder.append("\n");
embedBuilder.appendDescription("\n");
}

embedBuilder.appendDescription(msg);

if (player.getTrackCount() < 1) {
String nowPlayingString = context.i18nFormat("selectSuccessPartNowPlaying");
embedBuilder.appendDescription(nowPlayingString);
embedBuilder.appendDescription("\n");

} else {
long remainingTimeInMillis = player.getTotalRemainingMusicTimeMillis();
String remainingTime = (new SimpleDateFormat("mm:ss")).format(new Date(remainingTimeInMillis));
String queueAndWaitTimeString = context.i18nFormat("selectSuccessPartQueueWaitTime", positionInQueue, remainingTime);
embedBuilder.appendDescription(queueAndWaitTimeString);
embedBuilder.appendDescription("\n");
}
outputMsgBuilder.append(msg);

player.queue(new AudioTrackContext(selectedTracks[i], invoker));
}

VideoSelection.remove(invoker);
TextChannel tc = FredBoat.getTextChannelById(selection.channelId);
if (tc != null) {
CentralMessaging.editMessage(tc, selection.outMsgId, CentralMessaging.from(outputMsgBuilder.toString()));
CentralMessaging.editMessage(tc, selection.outMsgId, CentralMessaging.from(embedBuilder.build()));
}

player.setPause(false);
Expand Down
3 changes: 3 additions & 0 deletions FredBoat/src/main/resources/lang/en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ pauseSuccess=The player is now paused. You can unpause it with `{0}unpause`.
repeatOnSingle=The player will now repeat the current track.
repeatOnAll=The player will now repeat the queue.
repeatOff=The player is no longer on repeat.
selectionEmbedTitle=Selection
selectSuccess=Song **\#{0}** has been selected\: **{1}** ({2})
selectSuccessPartNowPlaying=, *now playing*
selectSuccessPartQueueWaitTime=, position in queue: **\#{0}**, approximate wait time: **{1}** minute.
selectInterval=Must be a number 1-{0}.
selectSelectionNotGiven=You must first be given a selection to choose from.
shuffleOn=The player is now shuffled.
Expand Down