From db9d3f09307fa006d225d9bdac38663e25f889d5 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Sat, 25 Nov 2017 23:18:10 -0800 Subject: [PATCH 01/16] Added queue position and approx wait time. #402 --- .../command/music/control/SelectCommand.java | 36 ++++++++++++++++--- .../src/main/resources/lang/en_US.properties | 3 ++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index 16d0ee0bb..b09970c75 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -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 { @@ -107,17 +113,37 @@ 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)); } @@ -125,7 +151,7 @@ static void select(CommandContext context) { 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); diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index 79b315c68..fcc2eeda0 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -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. From 8d853a55eaffc5031f9112447d680695a1be3f66 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Mon, 1 Jan 2018 21:26:08 -0800 Subject: [PATCH 02/16] Removed selection embed. --- .../command/music/control/SelectCommand.java | 18 +++++++----------- .../src/main/resources/lang/en_US.properties | 3 +-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index b09970c75..fe44b8322 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -113,9 +113,7 @@ static void select(CommandContext context) { throw new NumberFormatException(); } else { AudioTrack[] selectedTracks = new AudioTrack[validChoices.size()]; - - EmbedBuilder embedBuilder = CentralMessaging.getColoredEmbedBuilder(); - embedBuilder.setTitle(context.i18n("selectionEmbedTitle")); + StringBuilder outputMsgBuilder = new StringBuilder(); for (int i = 0; i < validChoices.size(); i++) { int positionInQueue = player.getTrackCount() + 1; @@ -127,22 +125,20 @@ static void select(CommandContext context) { // if there are more selections. if (i < validChoices.size()) { - embedBuilder.appendDescription("\n"); + outputMsgBuilder.append("\n"); } - - embedBuilder.appendDescription(msg); + outputMsgBuilder.append(msg); if (player.getTrackCount() < 1) { String nowPlayingString = context.i18nFormat("selectSuccessPartNowPlaying"); - embedBuilder.appendDescription(nowPlayingString); - embedBuilder.appendDescription("\n"); + outputMsgBuilder.append(nowPlayingString); } 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(queueAndWaitTimeString); + outputMsgBuilder.append("\n"); } player.queue(new AudioTrackContext(selectedTracks[i], invoker)); @@ -151,7 +147,7 @@ static void select(CommandContext context) { VideoSelection.remove(invoker); TextChannel tc = FredBoat.getTextChannelById(selection.channelId); if (tc != null) { - CentralMessaging.editMessage(tc, selection.outMsgId, CentralMessaging.from(embedBuilder.build())); + CentralMessaging.editMessage(tc, selection.outMsgId, CentralMessaging.from(outputMsgBuilder.toString())); } player.setPause(false); diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index fcc2eeda0..d2d64e046 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -14,9 +14,8 @@ 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* +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. From b3bc027aeb9ad5f70043536d21e7a014c973f6a5 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Mon, 8 Jan 2018 19:12:45 -0800 Subject: [PATCH 03/16] Changes on remaining time formatting and string wording. --- .../java/fredboat/command/music/control/SelectCommand.java | 5 ++++- FredBoat/src/main/resources/lang/en_US.properties | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index fe44b8322..9ae8e8392 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -127,15 +127,18 @@ static void select(CommandContext context) { if (i < validChoices.size()) { outputMsgBuilder.append("\n"); } + outputMsgBuilder.append(msg); + outputMsgBuilder.append(", "); if (player.getTrackCount() < 1) { String nowPlayingString = context.i18nFormat("selectSuccessPartNowPlaying"); outputMsgBuilder.append(nowPlayingString); + outputMsgBuilder.append("\n"); } else { long remainingTimeInMillis = player.getTotalRemainingMusicTimeMillis(); - String remainingTime = (new SimpleDateFormat("mm:ss")).format(new Date(remainingTimeInMillis)); + String remainingTime = TextUtils.formatTime(remainingTimeInMillis); String queueAndWaitTimeString = context.i18nFormat("selectSuccessPartQueueWaitTime", positionInQueue, remainingTime); outputMsgBuilder.append(queueAndWaitTimeString); outputMsgBuilder.append("\n"); diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index d2d64e046..5cf81a338 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -14,9 +14,9 @@ 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}) -selectSuccessPartNowPlaying=, *Now playing* -selectSuccessPartQueueWaitTime=, position in queue: **\#{0}**, approximate wait time: **{1}** minute. +selectSuccess=Song selected **\#{0}**\: **{1}** ({2}) +selectSuccessPartNowPlaying=*Now playing* +selectSuccessPartQueueWaitTime=queued: **\#{0}**, playing in: **{1}**. selectInterval=Must be a number 1-{0}. selectSelectionNotGiven=You must first be given a selection to choose from. shuffleOn=The player is now shuffled. From 661d6d5ae1003c172a28dbbfd17b0eaf86c95d92 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Tue, 9 Jan 2018 21:58:49 -0800 Subject: [PATCH 04/16] Modified selection string to be two lines. --- .../command/music/control/SelectCommand.java | 35 +++++++++++-------- .../src/main/resources/lang/en_US.properties | 5 +-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index 9ae8e8392..d7dc0aadc 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -120,27 +120,32 @@ static void select(CommandContext context) { selectedTracks[i] = selection.choices.get(validChoices.get(i) - 1); - String msg = context.i18nFormat("selectSuccess", validChoices.get(i), selectedTracks[i].getInfo().title, - TextUtils.formatTime(selectedTracks[i].getInfo().length)); - - // if there are more selections. - if (i < validChoices.size()) { - outputMsgBuilder.append("\n"); - } - - outputMsgBuilder.append(msg); - outputMsgBuilder.append(", "); + String playingStatusOrQueueTime = ""; if (player.getTrackCount() < 1) { - String nowPlayingString = context.i18nFormat("selectSuccessPartNowPlaying"); - outputMsgBuilder.append(nowPlayingString); - outputMsgBuilder.append("\n"); + playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartNowPlaying"); } else { long remainingTimeInMillis = player.getTotalRemainingMusicTimeMillis(); String remainingTime = TextUtils.formatTime(remainingTimeInMillis); - String queueAndWaitTimeString = context.i18nFormat("selectSuccessPartQueueWaitTime", positionInQueue, remainingTime); - outputMsgBuilder.append(queueAndWaitTimeString); + playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartQueueWaitTime", positionInQueue, remainingTime); + + } + + // Print the selection string. + String selectionSuccessString = context.i18nFormat("selectSuccess", 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", 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"); } diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index 5cf81a338..1554b795c 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -14,9 +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. -selectSuccess=Song selected **\#{0}**\: **{1}** ({2}) +selectSuccess=Song selected **\#{0}** ~ {1} +selectTitleAndLength=**{0}** ({1}) selectSuccessPartNowPlaying=*Now playing* -selectSuccessPartQueueWaitTime=queued: **\#{0}**, playing in: **{1}**. +selectSuccessPartQueueWaitTime=Queued: **{0}**, playing in: **{1}**. selectInterval=Must be a number 1-{0}. selectSelectionNotGiven=You must first be given a selection to choose from. shuffleOn=The player is now shuffled. From e516f21b5b9314222087597f6e83110de947a1b8 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Wed, 10 Jan 2018 18:05:45 -0800 Subject: [PATCH 05/16] Added live stream check for queuing message. --- .../command/music/control/SelectCommand.java | 19 ++++++++++++++++--- .../src/main/resources/lang/en_US.properties | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index d7dc0aadc..17a44d3c0 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -51,7 +51,9 @@ 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 { @@ -126,10 +128,21 @@ static void select(CommandContext context) { playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartNowPlaying"); } else { - long remainingTimeInMillis = player.getTotalRemainingMusicTimeMillis(); - String remainingTime = TextUtils.formatTime(remainingTimeInMillis); - playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartQueueWaitTime", positionInQueue, remainingTime); + 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", positionInQueue, remainingTime); + + } else { + playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartQueueHasStream", positionInQueue); + } } // Print the selection string. diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index 1554b795c..88d3d5483 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -18,6 +18,7 @@ selectSuccess=Song selected **\#{0}** ~ {1} selectTitleAndLength=**{0}** ({1}) selectSuccessPartNowPlaying=*Now playing* selectSuccessPartQueueWaitTime=Queued: **{0}**, playing in: **{1}**. +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. From db1c8b1ced254b07b3e09237fb073ac3b175d953 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Tue, 23 Jan 2018 19:56:46 -0800 Subject: [PATCH 06/16] Removed formatting in i18n file. --- .../command/music/control/SelectCommand.java | 22 ++++++++++++++----- .../main/java/fredboat/util/TextUtils.java | 20 +++++++++++++++++ .../src/main/resources/lang/en_US.properties | 10 ++++----- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index 17a44d3c0..207921f3e 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -125,7 +125,7 @@ static void select(CommandContext context) { String playingStatusOrQueueTime = ""; if (player.getTrackCount() < 1) { - playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartNowPlaying"); + playingStatusOrQueueTime = TextUtils.italicizeText(context.i18nFormat("selectSuccessPartNowPlaying")); } else { @@ -138,22 +138,32 @@ static void select(CommandContext context) { // Currently is not playing any live stream. long remainingTimeInMillis = player.getTotalRemainingMusicTimeMillis(); String remainingTime = TextUtils.formatTime(remainingTimeInMillis); - playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartQueueWaitTime", positionInQueue, remainingTime); + playingStatusOrQueueTime = context.i18nFormat( + "selectSuccessPartQueueWaitTime", + TextUtils.boldenText(positionInQueue), + TextUtils.boldenText(remainingTime)); } else { - playingStatusOrQueueTime = context.i18nFormat("selectSuccessPartQueueHasStream", positionInQueue); + playingStatusOrQueueTime = context.i18nFormat( + "selectSuccessPartQueueHasStream", + TextUtils.boldenText(positionInQueue)); } } // Print the selection string. - String selectionSuccessString = context.i18nFormat("selectSuccess", validChoices.get(i), playingStatusOrQueueTime); + 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", selectedTracks[i].getInfo().title, - TextUtils.formatTime(selectedTracks[i].getInfo().length)); + String songTitleAndMusic = context.i18nFormat( + "selectTitleAndLength", + TextUtils.boldenText(selectedTracks[i].getInfo().title), + "(" + TextUtils.formatTime(selectedTracks[i].getInfo().length) + ")"); outputMsgBuilder.append(songTitleAndMusic); outputMsgBuilder.append("\n"); diff --git a/FredBoat/src/main/java/fredboat/util/TextUtils.java b/FredBoat/src/main/java/fredboat/util/TextUtils.java index bb897b352..2704a8f67 100644 --- a/FredBoat/src/main/java/fredboat/util/TextUtils.java +++ b/FredBoat/src/main/java/fredboat/util/TextUtils.java @@ -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 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 String italicizeText(@Nonnull T input) { + return "*" + input + "*"; + } } diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index 88d3d5483..9e3c4bdea 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -14,11 +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 selected **\#{0}** ~ {1} -selectTitleAndLength=**{0}** ({1}) -selectSuccessPartNowPlaying=*Now playing* -selectSuccessPartQueueWaitTime=Queued: **{0}**, playing in: **{1}**. -selectSuccessPartQueueHasStream=Queued: **{0}**, playing after live stream. +selectSuccess=Song selected {0} {1} +selectTitleAndLength={0} {1} +selectSuccessPartNowPlaying=Now playing +selectSuccessPartQueueWaitTime=Queued: {0}, playing in: {1}. +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. From 890a0b940cca8875937d6002a031801e92f075b1 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Tue, 30 Jan 2018 18:49:32 -0800 Subject: [PATCH 07/16] Removed formatting in translation properties file. --- .../command/music/control/SelectCommand.java | 14 ++++++++------ FredBoat/src/main/resources/lang/en_US.properties | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index 207921f3e..89f1c9aab 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -153,17 +153,19 @@ static void select(CommandContext context) { // Print the selection string. String selectionSuccessString = context.i18nFormat( "selectSuccess", - TextUtils.boldenText("\\#" + validChoices.get(i)), - "~ " + playingStatusOrQueueTime); + 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) + ")"); + + // Merge title and the length in one string. + String songTitleAndMusic = + TextUtils.boldenText(selectedTracks[i].getInfo().title) + " " + + "(" + TextUtils.formatTime(selectedTracks[i].getInfo().length) + ")"; + outputMsgBuilder.append(songTitleAndMusic); outputMsgBuilder.append("\n"); diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index 9e3c4bdea..f0418f819 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -14,8 +14,7 @@ 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 selected {0} {1} -selectTitleAndLength={0} {1} +selectSuccess=Song selected {0} selectSuccessPartNowPlaying=Now playing selectSuccessPartQueueWaitTime=Queued: {0}, playing in: {1}. selectSuccessPartQueueHasStream=Queued: {0}, playing after live stream. From bb12678d9814cff8c477a119b466daa86c7baa3a Mon Sep 17 00:00:00 2001 From: Napster Date: Wed, 31 Jan 2018 18:28:42 +0100 Subject: [PATCH 08/16] Fix compiling github online editor skills too weak --- .../fredboat/command/music/control/SelectCommand.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index 269fed837..73bae888a 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -26,7 +26,6 @@ package fredboat.command.music.control; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -import fredboat.main.BotController; import fredboat.audio.player.GuildPlayer; import fredboat.audio.player.PlayerRegistry; import fredboat.audio.player.VideoSelection; @@ -35,24 +34,19 @@ import fredboat.commandmeta.abs.CommandContext; import fredboat.commandmeta.abs.ICommandRestricted; import fredboat.commandmeta.abs.IMusicCommand; +import fredboat.main.BotController; import fredboat.messaging.CentralMessaging; 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 { @@ -117,7 +111,7 @@ static void select(CommandContext context) { selectedTracks[i] = selection.choices.get(validChoices.get(i) - 1); - String playingStatusOrQueueTime = ""; + String playingStatusOrQueueTime; if (player.getTrackCount() < 1) { playingStatusOrQueueTime = TextUtils.italicizeText(context.i18nFormat("selectSuccessPartNowPlaying")); From 84461026e9d7f253cca64313bc6dadf224977d94 Mon Sep 17 00:00:00 2001 From: Napster Date: Wed, 31 Jan 2018 18:39:53 +0100 Subject: [PATCH 09/16] Fix i18n warning --- .../java/fredboat/command/music/control/SelectCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index 73bae888a..f49304d06 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -114,10 +114,8 @@ static void select(CommandContext context) { String playingStatusOrQueueTime; if (player.getTrackCount() < 1) { - playingStatusOrQueueTime = TextUtils.italicizeText(context.i18nFormat("selectSuccessPartNowPlaying")); - + playingStatusOrQueueTime = TextUtils.italicizeText(context.i18n("selectSuccessPartNowPlaying")); } else { - if (Stream.of( player.getPlayingTrack(), player.getPlayingTrack().getTrack(), From e7ba42c1cc3119e5039ff9b2c3d36479c413def0 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Sun, 4 Feb 2018 22:12:18 -0800 Subject: [PATCH 10/16] Fix live stream message if there is any live stream in queue. --- .../fredboat/command/music/control/SelectCommand.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index f49304d06..72ba45951 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -116,11 +116,10 @@ static void select(CommandContext context) { if (player.getTrackCount() < 1) { playingStatusOrQueueTime = TextUtils.italicizeText(context.i18n("selectSuccessPartNowPlaying")); } else { - if (Stream.of( - player.getPlayingTrack(), - player.getPlayingTrack().getTrack(), - player.getPlayingTrack().getTrack().getInfo()).anyMatch(Objects::isNull) - || !player.getPlayingTrack().getTrack().getInfo().isStream) { + if (player.getRemainingTracks() + .stream() + .noneMatch( + audioTrackContext -> audioTrackContext.getTrack().getInfo().isStream)) { // Currently is not playing any live stream. long remainingTimeInMillis = player.getTotalRemainingMusicTimeMillis(); From d1d36bc69b9ebd87e4d93a95aa19123fce4e8bea Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Mon, 5 Feb 2018 20:36:58 -0800 Subject: [PATCH 11/16] Added queue message support for adding url directly. --- .../fredboat/audio/queue/AudioLoader.java | 12 +++-- .../command/music/control/SelectCommand.java | 30 +---------- .../main/java/fredboat/util/PlayerUtil.java | 51 +++++++++++++++++++ 3 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 FredBoat/src/main/java/fredboat/util/PlayerUtil.java diff --git a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java index 9e935336e..3083539b3 100644 --- a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java +++ b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java @@ -38,6 +38,7 @@ import fredboat.feature.metrics.Metrics; import fredboat.feature.togglz.FeatureFlags; import fredboat.messaging.CentralMessaging; +import fredboat.util.PlayerUtil; import fredboat.util.TextUtils; import fredboat.util.ratelimit.Ratelimiter; import fredboat.util.rest.YoutubeAPI; @@ -174,11 +175,12 @@ public void trackLoaded(AudioTrack at) { } else { if (!context.isQuiet()) { - context.reply(gplayer.isPlaying() ? - context.i18nFormat("loadSingleTrack", TextUtils.escapeAndDefuse(at.getInfo().title)) - : - context.i18nFormat("loadSingleTrackAndPlay", TextUtils.escapeAndDefuse(at.getInfo().title)) - ); + String playingStatusOrQueueTime = PlayerUtil.resolveStatusOrQueueMessage(gplayer, context); + String replyMessage = playingStatusOrQueueTime + + "\n\t" + + TextUtils.boldenText(TextUtils.escapeAndDefuse(at.getInfo().title)); + + context.reply(replyMessage); } else { log.info("Quietly loaded " + at.getIdentifier()); } diff --git a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java index 72ba45951..e389175a7 100644 --- a/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java +++ b/FredBoat/src/main/java/fredboat/command/music/control/SelectCommand.java @@ -38,6 +38,7 @@ import fredboat.messaging.CentralMessaging; import fredboat.messaging.internal.Context; import fredboat.perms.PermissionLevel; +import fredboat.util.PlayerUtil; import fredboat.util.TextUtils; import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.TextChannel; @@ -46,8 +47,6 @@ import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.LinkedHashSet; -import java.util.Objects; -import java.util.stream.Stream; public class SelectCommand extends Command implements IMusicCommand, ICommandRestricted { @@ -107,34 +106,9 @@ 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 playingStatusOrQueueTime; - - if (player.getTrackCount() < 1) { - playingStatusOrQueueTime = TextUtils.italicizeText(context.i18n("selectSuccessPartNowPlaying")); - } else { - if (player.getRemainingTracks() - .stream() - .noneMatch( - audioTrackContext -> audioTrackContext.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)); - } - } + String playingStatusOrQueueTime = PlayerUtil.resolveStatusOrQueueMessage(player, context); // Print the selection string. String selectionSuccessString = context.i18nFormat( diff --git a/FredBoat/src/main/java/fredboat/util/PlayerUtil.java b/FredBoat/src/main/java/fredboat/util/PlayerUtil.java new file mode 100644 index 000000000..beb360a1b --- /dev/null +++ b/FredBoat/src/main/java/fredboat/util/PlayerUtil.java @@ -0,0 +1,51 @@ +package fredboat.util; + +import fredboat.audio.player.GuildPlayer; +import fredboat.messaging.internal.Context; + +import javax.annotation.Nonnull; + +public class PlayerUtil { + + /** + * No initialization! + */ + private PlayerUtil() { + } + + /** + * Resolve which message to be replying to the discord channel based on how many audio is in the queue. + * + * @param player Guild player. + * @param context Context object to be used for retrieving i18n strings. + * @return String represent of the current state of the player for adding audio. + */ + public static String resolveStatusOrQueueMessage(@Nonnull GuildPlayer player, @Nonnull Context context) { + String playingStatusOrQueueTime; + int positionInQueue = player.getTrackCount() + 1; + if (player.getTrackCount() < 1) { + playingStatusOrQueueTime = TextUtils.italicizeText(context.i18n("selectSuccessPartNowPlaying")); + } else { + if (player.getRemainingTracks() + .stream() + .noneMatch( + audioTrackContext -> audioTrackContext.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)); + } + } + + return playingStatusOrQueueTime; + } +} From dcde4c8ac87ff03c4b3fae35e5e579296d5aac02 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Sat, 10 Feb 2018 22:42:58 -0800 Subject: [PATCH 12/16] Added queue message to playlist, and fix timer for direct url. --- .../fredboat/audio/queue/AudioLoader.java | 71 ++++++++++++------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java index 3083539b3..8ac6e9765 100644 --- a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java +++ b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java @@ -48,8 +48,8 @@ import org.apache.commons.lang3.tuple.Pair; import org.slf4j.LoggerFactory; +import javax.annotation.Nonnull; import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -61,6 +61,7 @@ public class AudioLoader implements AudioLoadResultHandler { //Matches a timestamp and the description private static final Pattern SPLIT_DESCRIPTION_PATTERN = Pattern.compile("(.*?)[( \\[]*((?:\\d?\\d:)?\\d?\\d:\\d\\d)[) \\]]*(.*)"); private static final int QUEUE_TRACK_LIMIT = 10000; + private static final int MAX_QUEUE_MESSAGE_DISPLAY = 5; private final ITrackProvider trackProvider; private final AudioPlayerManager playerManager; @@ -175,12 +176,8 @@ public void trackLoaded(AudioTrack at) { } else { if (!context.isQuiet()) { - String playingStatusOrQueueTime = PlayerUtil.resolveStatusOrQueueMessage(gplayer, context); - String replyMessage = playingStatusOrQueueTime - + "\n\t" - + TextUtils.boldenText(TextUtils.escapeAndDefuse(at.getInfo().title)); + context.reply(buildMusicQueueMessage(at.getInfo().title, at.getInfo().length)); - context.reply(replyMessage); } else { log.info("Quietly loaded " + at.getIdentifier()); } @@ -202,18 +199,26 @@ public void trackLoaded(AudioTrack at) { public void playlistLoaded(AudioPlaylist ap) { Metrics.tracksLoaded.inc(ap.getTracks() == null ? 0 : ap.getTracks().size()); try { + int statusMessageCount = 0; if(context.isSplit()){ context.reply(context.i18n("loadPlaySplitListFail")); loadNextAsync(); return; } - List toAdd = new ArrayList<>(); + StringBuilder replyMessage = new StringBuilder(); for (AudioTrack at : ap.getTracks()) { - toAdd.add(new AudioTrackContext(at, context.getMember())); + if (statusMessageCount < MAX_QUEUE_MESSAGE_DISPLAY){ + statusMessageCount++; + + replyMessage.append(buildMusicQueueMessage(at.getInfo().title, at.getInfo().length)) + .append("\n\n"); + } + + trackProvider.add(new AudioTrackContext(at, context.getMember())); } - trackProvider.addAll(toAdd); - context.reply(context.i18nFormat("loadListSuccess", ap.getTracks().size(), ap.getName())); + + context.reply(replyMessage + context.i18nFormat("loadListSuccess", ap.getTracks().size(), ap.getName())); if (!gplayer.isPaused()) { gplayer.play(); } @@ -279,9 +284,9 @@ private void loadSplit(AudioTrack at, IdentifierContext ic){ return; } - ArrayList list = new ArrayList<>(); - int i = 0; + MessageBuilder mb = CentralMessaging.getClearThreadLocalMessageBuilder(); + for(Pair pair : pairs){ long startPos; long endPos; @@ -301,26 +306,18 @@ private void loadSplit(AudioTrack at, IdentifierContext ic){ SplitAudioTrackContext atc = new SplitAudioTrackContext(newAt, ic.getMember(), startPos, endPos, pair.getRight()); - list.add(atc); + mb.append(buildMusicQueueMessage(atc.getEffectiveTitle(), atc.getEffectiveDuration())) + .append("\n\n"); + gplayer.queue(atc); i++; } - MessageBuilder mb = CentralMessaging.getClearThreadLocalMessageBuilder() - .append(ic.i18n("loadFollowingTracksAdded")).append("\n"); - for(SplitAudioTrackContext atc : list) { - mb.append("`[") - .append(TextUtils.formatTime(atc.getEffectiveDuration())) - .append("]` ") - .append(TextUtils.escapeAndDefuse(atc.getEffectiveTitle())) - .append("\n"); - } - - //This is pretty spammy .. let's use a shorter one - if(mb.length() > 800){ + // This is pretty spammy .. let's use a shorter one + if (mb.length() > 800) { mb = CentralMessaging.getClearThreadLocalMessageBuilder() - .append(ic.i18nFormat("loadPlaylistTooMany", list.size())); + .append(ic.i18nFormat("loadPlaylistTooMany", i)); } context.reply(mb.build()); @@ -356,4 +353,26 @@ private void handleThrowable(IdentifierContext ic, Throwable th) { } } + /** + * Build queue message based on title and duration. + * It will use player and context object to determine if something is playing. + *

+ * NOTE: It will not add a new line for each string, this assume the caller will handle newline. + *

+ * + * @param title Title of the music. + * @param duration Duration of the music. + * @return String object representing the message to reply for each queue. + */ + private String buildMusicQueueMessage(@Nonnull String title, @Nonnull long duration){ + + String playingStatusOrQueueTime = PlayerUtil.resolveStatusOrQueueMessage(gplayer, context); + String songTitleAndMusic = + TextUtils.boldenText(TextUtils.escapeAndDefuse(title)) + " " + + "(" + TextUtils.formatTime(duration) + ")"; + + return playingStatusOrQueueTime + + "\n\t" + + songTitleAndMusic; + } } From f92647ae52a5de2798c1085f97c847e88c8ad98d Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Sat, 10 Feb 2018 23:01:13 -0800 Subject: [PATCH 13/16] Added limit check for split command. --- .../src/main/java/fredboat/audio/queue/AudioLoader.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java index 8ac6e9765..8b20aa089 100644 --- a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java +++ b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java @@ -306,14 +306,18 @@ private void loadSplit(AudioTrack at, IdentifierContext ic){ SplitAudioTrackContext atc = new SplitAudioTrackContext(newAt, ic.getMember(), startPos, endPos, pair.getRight()); - mb.append(buildMusicQueueMessage(atc.getEffectiveTitle(), atc.getEffectiveDuration())) - .append("\n\n"); + if (i < MAX_QUEUE_MESSAGE_DISPLAY) { + mb.append(buildMusicQueueMessage(atc.getEffectiveTitle(), atc.getEffectiveDuration())) + .append("\n\n"); + } gplayer.queue(atc); i++; } + mb.append(context.i18nFormat("loadListSuccess", i, at.getInfo().title)); + // This is pretty spammy .. let's use a shorter one if (mb.length() > 800) { mb = CentralMessaging.getClearThreadLocalMessageBuilder() From a06fa87a67b84382f6251c3cd05668db368b34d9 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Sat, 10 Feb 2018 23:09:20 -0800 Subject: [PATCH 14/16] Added a check for ignoring empty or null title on split command reply. --- .../main/java/fredboat/audio/queue/AudioLoader.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java index 8b20aa089..8b02c7299 100644 --- a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java +++ b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java @@ -44,6 +44,7 @@ import fredboat.util.rest.YoutubeAPI; import fredboat.util.rest.YoutubeVideo; import net.dv8tion.jda.core.MessageBuilder; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.LoggerFactory; @@ -176,7 +177,7 @@ public void trackLoaded(AudioTrack at) { } else { if (!context.isQuiet()) { - context.reply(buildMusicQueueMessage(at.getInfo().title, at.getInfo().length)); + context.reply(this.buildMusicQueueMessage(at.getInfo().title, at.getInfo().length)); } else { log.info("Quietly loaded " + at.getIdentifier()); @@ -211,7 +212,7 @@ public void playlistLoaded(AudioPlaylist ap) { if (statusMessageCount < MAX_QUEUE_MESSAGE_DISPLAY){ statusMessageCount++; - replyMessage.append(buildMusicQueueMessage(at.getInfo().title, at.getInfo().length)) + replyMessage.append(this.buildMusicQueueMessage(at.getInfo().title, at.getInfo().length)) .append("\n\n"); } @@ -306,8 +307,10 @@ private void loadSplit(AudioTrack at, IdentifierContext ic){ SplitAudioTrackContext atc = new SplitAudioTrackContext(newAt, ic.getMember(), startPos, endPos, pair.getRight()); - if (i < MAX_QUEUE_MESSAGE_DISPLAY) { - mb.append(buildMusicQueueMessage(atc.getEffectiveTitle(), atc.getEffectiveDuration())) + if (i < MAX_QUEUE_MESSAGE_DISPLAY + && !StringUtils.isBlank(atc.getEffectiveTitle())) { + + mb.append(this.buildMusicQueueMessage(atc.getEffectiveTitle(), atc.getEffectiveDuration())) .append("\n\n"); } @@ -368,7 +371,7 @@ private void handleThrowable(IdentifierContext ic, Throwable th) { * @param duration Duration of the music. * @return String object representing the message to reply for each queue. */ - private String buildMusicQueueMessage(@Nonnull String title, @Nonnull long duration){ + private String buildMusicQueueMessage(@Nonnull String title, long duration){ String playingStatusOrQueueTime = PlayerUtil.resolveStatusOrQueueMessage(gplayer, context); String songTitleAndMusic = From 59f7ca2dbf741adf80206253a3f5d20cb3d99022 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Mon, 12 Feb 2018 19:21:01 -0800 Subject: [PATCH 15/16] Reduced max queue message display for split and load playlist. Added a "..." line between the detail. --- .../java/fredboat/audio/queue/AudioLoader.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java index 8b02c7299..5c9e9a9d0 100644 --- a/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java +++ b/FredBoat/src/main/java/fredboat/audio/queue/AudioLoader.java @@ -62,7 +62,7 @@ public class AudioLoader implements AudioLoadResultHandler { //Matches a timestamp and the description private static final Pattern SPLIT_DESCRIPTION_PATTERN = Pattern.compile("(.*?)[( \\[]*((?:\\d?\\d:)?\\d?\\d:\\d\\d)[) \\]]*(.*)"); private static final int QUEUE_TRACK_LIMIT = 10000; - private static final int MAX_QUEUE_MESSAGE_DISPLAY = 5; + private static final int MAX_QUEUE_MESSAGE_DISPLAY = 3; private final ITrackProvider trackProvider; private final AudioPlayerManager playerManager; @@ -209,7 +209,7 @@ public void playlistLoaded(AudioPlaylist ap) { StringBuilder replyMessage = new StringBuilder(); for (AudioTrack at : ap.getTracks()) { - if (statusMessageCount < MAX_QUEUE_MESSAGE_DISPLAY){ + if (statusMessageCount < MAX_QUEUE_MESSAGE_DISPLAY) { statusMessageCount++; replyMessage.append(this.buildMusicQueueMessage(at.getInfo().title, at.getInfo().length)) @@ -219,7 +219,11 @@ public void playlistLoaded(AudioPlaylist ap) { trackProvider.add(new AudioTrackContext(at, context.getMember())); } - context.reply(replyMessage + context.i18nFormat("loadListSuccess", ap.getTracks().size(), ap.getName())); + if (ap.getTracks().size() > MAX_QUEUE_MESSAGE_DISPLAY) { + replyMessage.append("...\n"); + context.reply(replyMessage + context.i18nFormat("loadListSuccess", ap.getTracks().size(), ap.getName())); + } + if (!gplayer.isPaused()) { gplayer.play(); } @@ -276,8 +280,6 @@ private void loadSplit(AudioTrack at, IdentifierContext ic){ } else { pairs.add(new ImmutablePair<>(timestamp, title2)); } - - } if(pairs.size() < 2) { @@ -319,7 +321,10 @@ private void loadSplit(AudioTrack at, IdentifierContext ic){ i++; } - mb.append(context.i18nFormat("loadListSuccess", i, at.getInfo().title)); + if (i > MAX_QUEUE_MESSAGE_DISPLAY) { + mb.append("...\n"); + mb.append(context.i18nFormat("loadListSuccess", i, at.getInfo().title)); + } // This is pretty spammy .. let's use a shorter one if (mb.length() > 800) { From b4624495a3679a8c2fe655b445d1f526a4ea1729 Mon Sep 17 00:00:00 2001 From: Suhan Koh Date: Thu, 15 Mar 2018 21:17:59 -0700 Subject: [PATCH 16/16] Updated selection queue message. --- FredBoat/src/main/resources/lang/en_US.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FredBoat/src/main/resources/lang/en_US.properties b/FredBoat/src/main/resources/lang/en_US.properties index 180b72f30..f099b22c1 100644 --- a/FredBoat/src/main/resources/lang/en_US.properties +++ b/FredBoat/src/main/resources/lang/en_US.properties @@ -16,8 +16,8 @@ repeatOnAll=The player will now repeat the queue. repeatOff=The player is no longer on repeat. selectSuccess=Song selected {0} selectSuccessPartNowPlaying=Now playing -selectSuccessPartQueueWaitTime=Queued: {0}, playing in: {1}. -selectSuccessPartQueueHasStream=Queued: {0}, playing after live stream. +selectSuccessPartQueueWaitTime=Queued as #{0}, playing in: {1}. +selectSuccessPartQueueHasStream=Queued as #{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.