From a2059e082ddfbc64cdfa7c423045e6a16bab8098 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Mon, 29 Oct 2018 17:11:09 -0400 Subject: Adding status message Providing a way to get more information about the currently playing track as well as a way to get the current audio volume --- .../java/soundchan/BotListener/BotListener.java | 31 ++++++++++++++++++---- src/main/java/soundchan/BotListener/Commands.java | 1 + 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index 9bcccfe..e724f38 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -208,9 +208,12 @@ public class BotListener extends ListenerAdapter{ // Unpause the song/sound in the queue unpauseTrack(channel); - }else if(enumCommand == Commands.playingnow){ + }else if(enumCommand == Commands.playingnow) { // Print the currently playing song - printCurrentlyPlaying(channel); + printCurrentlyPlaying(channel, false); + } else if(enumCommand == Commands.status) { + // Print currently playing song with extra info + printCurrentlyPlaying(channel, true); }else if(enumCommand == Commands.summon){ connectToUserVoiceChannel(monitoredGuild.getAudioManager(), event.getMember().getEffectiveName()); }else if(enumCommand == Commands.help){ @@ -253,11 +256,29 @@ public class BotListener extends ListenerAdapter{ channel.sendMessage("Unpaused playback.").queue(); } - private void printCurrentlyPlaying(final MessageChannel channel){ + /** + * Prints out information about what is currently playing and possibly information about the track and/or the audio volume + * @param channel The channel to respond on + * @param printStatus Print out extra information such as track information and/or audio volume + */ + private void printCurrentlyPlaying(final MessageChannel channel, boolean printStatus){ GuildMusicManager musicManager = getGuildAudioPlayer(); AudioTrack currentlyPlaying = musicManager.player.getPlayingTrack(); - channel.sendMessage("Currently Playing: " + currentlyPlaying.getInfo().title + " by " + currentlyPlaying.getInfo().author).queue(); - + String message = ""; + if(currentlyPlaying != null) { + message = "Currently Playing: " + currentlyPlaying.getInfo().title + " by " + currentlyPlaying.getInfo().author; + if(printStatus) { + message += ( "\nTime : " + musicManager.player.getPlayingTrack().getPosition() + " | " + musicManager.player.getPlayingTrack().getDuration() + + "\nPaused = " + musicManager.player.isPaused() + + "\nVolume = " + musicManager.player.getVolume() + "%"); + } + } else { + message = "Nothing currently playing"; + if(printStatus) { + message += ("\nVolume = " + musicManager.player.getVolume() + "%"); + } + } + channel.sendMessage(message).queue(); } private void loadAndPlay(final MessageChannel channel, final String trackUrl, boolean preempt) { diff --git a/src/main/java/soundchan/BotListener/Commands.java b/src/main/java/soundchan/BotListener/Commands.java index e054de1..046bcab 100644 --- a/src/main/java/soundchan/BotListener/Commands.java +++ b/src/main/java/soundchan/BotListener/Commands.java @@ -11,6 +11,7 @@ public enum Commands { skip, list, playingnow, + status, summon, help } -- cgit v1.2.3 From c558cc3457dfd96089b459d34eaa43c7cc310eda Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Mon, 29 Oct 2018 17:31:33 -0400 Subject: Fixing a redundency --- src/main/java/soundchan/BotListener/BotListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index e724f38..a120a14 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -268,7 +268,7 @@ public class BotListener extends ListenerAdapter{ if(currentlyPlaying != null) { message = "Currently Playing: " + currentlyPlaying.getInfo().title + " by " + currentlyPlaying.getInfo().author; if(printStatus) { - message += ( "\nTime : " + musicManager.player.getPlayingTrack().getPosition() + " | " + musicManager.player.getPlayingTrack().getDuration() + message += ( "\nTime : " + currentlyPlaying.getPosition() + " | " + currentlyPlaying.getDuration() + "\nPaused = " + musicManager.player.isPaused() + "\nVolume = " + musicManager.player.getVolume() + "%"); } -- cgit v1.2.3 From b8e124c7ed303dfb1a3ad4295936abea79533101 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Tue, 30 Oct 2018 14:21:09 -0400 Subject: Making the format prettier --- .../java/soundchan/BotListener/BotListener.java | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index a120a14..6e928e6 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -268,9 +268,13 @@ public class BotListener extends ListenerAdapter{ if(currentlyPlaying != null) { message = "Currently Playing: " + currentlyPlaying.getInfo().title + " by " + currentlyPlaying.getInfo().author; if(printStatus) { - message += ( "\nTime : " + currentlyPlaying.getPosition() + " | " + currentlyPlaying.getDuration() - + "\nPaused = " + musicManager.player.isPaused() - + "\nVolume = " + musicManager.player.getVolume() + "%"); + message += ( "\nTime : " + genTimeStamp(currentlyPlaying.getPosition()) + " | " + genTimeStamp(currentlyPlaying.getDuration()) ); + if(musicManager.player.isPaused()) { + message += "\n**Paused**"; + } else { + message += "\n*Playing*"; + } + message += ( "\nVolume = " + musicManager.player.getVolume() + "%"); } } else { message = "Nothing currently playing"; @@ -381,6 +385,19 @@ public class BotListener extends ListenerAdapter{ } } + /** + * Creates a timestamp string from a number of milliseconds + * @param durationInMillis Number of milliseconds to turn into timestamp + * @return Timestamp in form HH:MM:ss:SSSS + */ + private static String genTimeStamp(long durationInMillis) { + long millis = durationInMillis % 1000; + long second = (durationInMillis / 1000) % 60; + long minute = (durationInMillis / (1000 * 60)) % 60; + long hour = (durationInMillis / (1000 * 60 * 60)) % 24; + return String.format("%02d:%02d:%02d.%d", hour, minute, second, millis); + } + /** * Checks the string for some reason to enable/disable a setting. * @param value A string (probably read in from config file) -- cgit v1.2.3 From 7360a197c9c09ffa239b0c56712202e8320b9e22 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Tue, 30 Oct 2018 15:27:36 -0400 Subject: Adding progressbar --- .../java/soundchan/BotListener/BotListener.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index 6e928e6..05ebec1 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -268,7 +268,7 @@ public class BotListener extends ListenerAdapter{ if(currentlyPlaying != null) { message = "Currently Playing: " + currentlyPlaying.getInfo().title + " by " + currentlyPlaying.getInfo().author; if(printStatus) { - message += ( "\nTime : " + genTimeStamp(currentlyPlaying.getPosition()) + " | " + genTimeStamp(currentlyPlaying.getDuration()) ); + message += genTimeInformation(currentlyPlaying.getPosition(), currentlyPlaying.getDuration()); if(musicManager.player.isPaused()) { message += "\n**Paused**"; } else { @@ -385,6 +385,26 @@ public class BotListener extends ListenerAdapter{ } } + /** + * Creates a block of time information with a progressbar + * @param currentMillis Current position in the audio in milliseconds + * @param durationMillis Length of audio in milliseconds + * @return Time information block + */ + private static String genTimeInformation(long currentMillis, long durationMillis) { + String message = "|"; + int fill = (int) ((double)(currentMillis / durationMillis)) * 10; + for(int i = 0; i < fill; i++) { + message += "--"; + } + message += "<>"; + for(int i = fill; i < 10; i++) { + message += "--"; + } + message += "|\nTime : " + genTimeStamp(currentMillis) + " | " + genTimeStamp(durationMillis); + return message; + } + /** * Creates a timestamp string from a number of milliseconds * @param durationInMillis Number of milliseconds to turn into timestamp -- cgit v1.2.3 From a392879a3e288c5a4714448f43d7e1d90640b825 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Tue, 30 Oct 2018 20:04:11 -0400 Subject: Tweaking things to work/look better --- src/main/java/soundchan/BotListener/BotListener.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main') diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index 05ebec1..324cdca 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -268,7 +268,7 @@ public class BotListener extends ListenerAdapter{ if(currentlyPlaying != null) { message = "Currently Playing: " + currentlyPlaying.getInfo().title + " by " + currentlyPlaying.getInfo().author; if(printStatus) { - message += genTimeInformation(currentlyPlaying.getPosition(), currentlyPlaying.getDuration()); + message += "\n" + genTimeInformation(currentlyPlaying.getPosition(), currentlyPlaying.getDuration()); if(musicManager.player.isPaused()) { message += "\n**Paused**"; } else { @@ -393,29 +393,29 @@ public class BotListener extends ListenerAdapter{ */ private static String genTimeInformation(long currentMillis, long durationMillis) { String message = "|"; - int fill = (int) ((double)(currentMillis / durationMillis)) * 10; - for(int i = 0; i < fill; i++) { + double temp = ((double) currentMillis / (double) durationMillis); + int fill = (int) (temp * 10.0); + for(int i = 0; i < fill - 1; i++) { message += "--"; } message += "<>"; for(int i = fill; i < 10; i++) { message += "--"; } - message += "|\nTime : " + genTimeStamp(currentMillis) + " | " + genTimeStamp(durationMillis); + message += "|\nTime : " + genTimeStamp(currentMillis) + " / " + genTimeStamp(durationMillis); return message; } /** * Creates a timestamp string from a number of milliseconds * @param durationInMillis Number of milliseconds to turn into timestamp - * @return Timestamp in form HH:MM:ss:SSSS + * @return Timestamp in form HH:MM:ss */ private static String genTimeStamp(long durationInMillis) { - long millis = durationInMillis % 1000; long second = (durationInMillis / 1000) % 60; long minute = (durationInMillis / (1000 * 60)) % 60; long hour = (durationInMillis / (1000 * 60 * 60)) % 24; - return String.format("%02d:%02d:%02d.%d", hour, minute, second, millis); + return String.format("%02d:%02d:%02d", hour, minute, second); } /** -- cgit v1.2.3 From 58cc4990cba0e79f75bf69e678108937d4685be5 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Tue, 30 Oct 2018 20:15:41 -0400 Subject: Adding line to help command --- src/main/java/soundchan/BotListener/BotListener.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index 324cdca..415e350 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -360,6 +360,7 @@ public class BotListener extends ListenerAdapter{ "~list sounds - prints out the names of the sounds available\n" + "~list users - prints out users with audio that will play when they join the voice channel\n" + "~playingnow - prints out the name of the currently playing song\n" + + "~status - prints out status about the currently playing song\n" + "~summon - brings SoundChan to the voice channel of the summoner\n" + "~help - prints out this help message ```"; channel.sendMessage(printMessage).queue(); -- cgit v1.2.3