From 8641c37bc02a1e4234e521aa7e276ab450c116ec Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Thu, 19 Jul 2018 20:41:24 -0400 Subject: Adding default for usersound and way to see loaded usersounds --- soundchan.properties.example | 3 ++- src/main/java/soundchan/BotListener/BotListener.java | 15 +++++++++++++-- src/main/java/soundchan/LocalAudioManager.java | 17 +++++++++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/soundchan.properties.example b/soundchan.properties.example index c15a89a..0655076 100644 --- a/soundchan.properties.example +++ b/soundchan.properties.example @@ -7,7 +7,7 @@ localFilePath=C:\\PATH\\TO\\SOUNDS\\DIRECTORY //The user for the followingUser=USERNAME -//Flag conditions enabled with any of the following values: +//Flag conditions are enabled with any of the following values: // true, on, enable, yes, 1 //any other string (or empty) will leave the condition disabled @@ -16,4 +16,5 @@ followingUser=USERNAME audioOnUserJoin=on/off //The file where users and sound clips are related, see usersound.properties.example for more info +//If this is not set, it will default to usersounds.properties userAudioFilePath=C:\\PATH\\TO\\USER\\SOUND\\FILE diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index b54edbe..028f13b 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -7,6 +7,7 @@ import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import com.sun.istack.internal.NotNull; import net.dv8tion.jda.client.events.call.voice.CallVoiceJoinEvent; import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.MessageChannel; @@ -51,12 +52,18 @@ public class BotListener extends ListenerAdapter{ * Loads various properties from config file * @param properties Object holding the contents of the property file */ - private void loadProperties(Properties properties) { + private void loadProperties(@NotNull Properties properties) { localFilePath = properties.getProperty("localFilePath"); followingUser = properties.getProperty("followingUser"); audioOnUserJoin = settingEnableCheck(properties.getProperty("audioOnUserJoin")); if(audioOnUserJoin) { - localManager = new LocalAudioManager(localFilePath, properties.getProperty("userAudioFilePath")); + String userAudioPath = properties.getProperty("userAudioFilePath"); + if(userAudioPath.contentEquals("") || userAudioPath == null) { + localManager = new LocalAudioManager(localFilePath, "usersound.properties"); + } + else { + localManager = new LocalAudioManager(localFilePath, userAudioPath); + } } else localManager = new LocalAudioManager(localFilePath); @@ -189,6 +196,9 @@ public class BotListener extends ListenerAdapter{ else if(command[1].equals("sounds")){ localManager.ListSounds(channel); } + else if(command[1].equals("users")) { + localManager.ListUserAudio(channel); + } } }else if(enumCommand == Commands.pause){ @@ -323,6 +333,7 @@ public class BotListener extends ListenerAdapter{ "~skip - skips to the next song in queue\n" + "~list queue - prints out the names of the songs in the queue\n" + "~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" + "~summon - brings SoundChan to the voice channel of the summoner\n" + "~help - prints out this help message ```"; diff --git a/src/main/java/soundchan/LocalAudioManager.java b/src/main/java/soundchan/LocalAudioManager.java index e645fe7..80e3790 100644 --- a/src/main/java/soundchan/LocalAudioManager.java +++ b/src/main/java/soundchan/LocalAudioManager.java @@ -72,6 +72,21 @@ public class LocalAudioManager { channel.sendMessage(toPrint).queue(); } + /** + * Lists users with sounds that will play when they join the voice channel + * @param channel Text channel messaged on + */ + public void ListUserAudio(MessageChannel channel) { + Set userSounds = usernameDict.keySet(); + String toPrint = "The following users have sounds that will play when they join the voice channel:\n```"; + for (String user : userSounds) { + String sound = usernameDict.get(user); + toPrint = toPrint + " * " + user + "\t" + sound.substring(0, sound.indexOf('.')) + "\n"; + } + toPrint = toPrint + "```"; + channel.sendMessage(toPrint).queue(); + } + private void PopulateFiles(){ File folder = new File(filepath); File[] listOfFiles = folder.listFiles(); @@ -122,6 +137,4 @@ public class LocalAudioManager { } return properties; } - - } -- cgit v1.2.3 From 7f0976b74dff706d223c96b40fb350f09bbc2c7f Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Thu, 19 Jul 2018 21:01:40 -0400 Subject: Adding checks that usersound file exists --- .../java/soundchan/BotListener/BotListener.java | 2 +- src/main/java/soundchan/LocalAudioManager.java | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/soundchan/BotListener/BotListener.java b/src/main/java/soundchan/BotListener/BotListener.java index 028f13b..9bcccfe 100644 --- a/src/main/java/soundchan/BotListener/BotListener.java +++ b/src/main/java/soundchan/BotListener/BotListener.java @@ -58,7 +58,7 @@ public class BotListener extends ListenerAdapter{ audioOnUserJoin = settingEnableCheck(properties.getProperty("audioOnUserJoin")); if(audioOnUserJoin) { String userAudioPath = properties.getProperty("userAudioFilePath"); - if(userAudioPath.contentEquals("") || userAudioPath == null) { + if(userAudioPath == null || userAudioPath.contentEquals("")) { localManager = new LocalAudioManager(localFilePath, "usersound.properties"); } else { diff --git a/src/main/java/soundchan/LocalAudioManager.java b/src/main/java/soundchan/LocalAudioManager.java index 80e3790..4b16850 100644 --- a/src/main/java/soundchan/LocalAudioManager.java +++ b/src/main/java/soundchan/LocalAudioManager.java @@ -122,19 +122,23 @@ public class LocalAudioManager { private static Properties LoadProperties(String filename){ Properties properties = new Properties(); InputStream input = null; - try{ - input = new FileInputStream(filename); - properties.load(input); - - }catch (IOException ex){ - ex.printStackTrace(); - } finally { + File file = new File(filename); + if(file.exists() && !file.isDirectory()) { try { - input.close(); + input = new FileInputStream(filename); + properties.load(input); } catch (IOException ex) { ex.printStackTrace(); + } finally { + try { + input.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } } + return properties; + } else { + return properties; } - return properties; } } -- cgit v1.2.3 From e18d70d70c29a4b054bad8563ef91172ec9a6e78 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Thu, 19 Jul 2018 21:02:49 -0400 Subject: Updating gitignore as to not track usersounds.properties --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 60925cf..fe4c960 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ gradle.propreties build soundchan.properties +usersound.properties -- cgit v1.2.3