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 6 commits
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,21 @@
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.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

public class SelectCommand extends Command implements IMusicCommand, ICommandRestricted {

Expand Down Expand Up @@ -110,14 +118,59 @@ static void select(CommandContext context) {
StringBuilder outputMsgBuilder = new StringBuilder();

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));
String playingStatusOrQueueTime = "";

if (player.getTrackCount() < 1) {
playingStatusOrQueueTime = TextUtils.italicizeText(context.i18nFormat("selectSuccessPartNowPlaying"));

} else {

if (Stream.of(
player.getPlayingTrack(),
player.getPlayingTrack().getTrack(),
player.getPlayingTrack().getTrack().getInfo()).anyMatch(Objects::isNull)
|| !player.getPlayingTrack().getTrack().getInfo().isStream) {

// Currently is not playing any live stream.
long remainingTimeInMillis = player.getTotalRemainingMusicTimeMillis();
String remainingTime = TextUtils.formatTime(remainingTimeInMillis);
playingStatusOrQueueTime = context.i18nFormat(
"selectSuccessPartQueueWaitTime",
TextUtils.boldenText(positionInQueue),
TextUtils.boldenText(remainingTime));

} else {
playingStatusOrQueueTime = context.i18nFormat(
"selectSuccessPartQueueHasStream",
TextUtils.boldenText(positionInQueue));
}
}

// Print the selection string.
String selectionSuccessString = context.i18nFormat(
"selectSuccess",
TextUtils.boldenText("\\#" + validChoices.get(i)),
"~ " + playingStatusOrQueueTime);
outputMsgBuilder.append(selectionSuccessString);
outputMsgBuilder.append("\n");

// Print the song title and length.
outputMsgBuilder.append("\t\t");
String songTitleAndMusic = context.i18nFormat(
"selectTitleAndLength",
TextUtils.boldenText(selectedTracks[i].getInfo().title),
"(" + TextUtils.formatTime(selectedTracks[i].getInfo().length) + ")");
outputMsgBuilder.append(songTitleAndMusic);
outputMsgBuilder.append("\n");

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

player.queue(new AudioTrackContext(selectedTracks[i], invoker));
}
Expand Down
20 changes: 20 additions & 0 deletions FredBoat/src/main/java/fredboat/util/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,24 @@ public static String shorten(@Nonnull String input, int size) {
}
return shortened.toString();
}

/**
* Wraps input with discord's markdown bold marker.
*
* @param input Object#toString() to be wrapped in bold. Must be non null.
* @return String with ** wrapped.
*/
public static <T> String boldenText(@Nonnull T input) {
return "**" + input + "**";
}

/**
* Wraps input with discord's markdown italic marker.
*
* @param input Object#toString() to be wrapped in italic marker. Must be non null.
* @return String with * wrapped.
*/
public static <T> String italicizeText(@Nonnull T input) {
return "*" + input + "*";
}
}
6 changes: 5 additions & 1 deletion FredBoat/src/main/resources/lang/en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ 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.
selectSuccess=Song **\#{0}** has been selected\: **{1}** ({2})
selectSuccess=Song selected {0} {1}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not merge these into a single {0} ? Or leave it off completely? Since the content of those variables does not look to be related to the String itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge this into one, "song selected" worth to be translated imo. I overlooked at the translation file, will fix.

selectTitleAndLength={0} {1}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not translatable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix in the next commit 👍

selectSuccessPartNowPlaying=Now playing
selectSuccessPartQueueWaitTime=Queued: {0}, playing in: {1}.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it may make more sense to say "Queued as #{0}"

selectSuccessPartQueueHasStream=Queued: {0}, playing after live stream.
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