aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/soundchan/LocalAudioManager.java
diff options
context:
space:
mode:
authorMatt <mattkohls13@gmail.com>2018-04-10 22:11:08 -0400
committerGitHub <noreply@github.com>2018-04-10 22:11:08 -0400
commit442bf1ea125f6fa2209e9c20306f604125f612fe (patch)
tree6327a37aa53a70c368c103b866a3cfccac454635 /src/main/java/soundchan/LocalAudioManager.java
parente9010ccdbd1600065bba34a08e78c9938dc93a6e (diff)
parente9ff559c08fa0529b5c6da9cf82d0beb6e7e7e17 (diff)
downloadSoundChan-442bf1ea125f6fa2209e9c20306f604125f612fe.tar.gz
SoundChan-442bf1ea125f6fa2209e9c20306f604125f612fe.tar.bz2
SoundChan-442bf1ea125f6fa2209e9c20306f604125f612fe.zip
Merge pull request #2 from bwaggone/feature/LocalAudioFiles
Add local audio file support, including listing files
Diffstat (limited to 'src/main/java/soundchan/LocalAudioManager.java')
-rw-r--r--src/main/java/soundchan/LocalAudioManager.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main/java/soundchan/LocalAudioManager.java b/src/main/java/soundchan/LocalAudioManager.java
new file mode 100644
index 0000000..314f6b9
--- /dev/null
+++ b/src/main/java/soundchan/LocalAudioManager.java
@@ -0,0 +1,55 @@
+package soundchan;
+
+import net.dv8tion.jda.core.entities.MessageChannel;
+
+import java.io.File;
+import java.util.*;
+
+public class LocalAudioManager {
+
+ /*
+ A list of local files for the sound bot to play.
+ */
+
+ public Map<String, String> filenameDict;
+ private String filepath;
+
+ public LocalAudioManager(String filepath_in){
+ filepath = filepath_in;
+ filenameDict = new HashMap<>();
+ PopulateFiles();
+ }
+
+ public String GetFilePath(String command){
+ try{
+ return filepath + "/" + filenameDict.get(command);
+ }catch(Exception ex){
+ System.out.println("File " + command + " not found!");
+ }
+ return "";
+ }
+
+ public void ListSounds(MessageChannel channel){
+ Set<String> localSounds = filenameDict.keySet();
+ String toPrint = "The following sounds you can play are:\n";
+ for (String sound:
+ localSounds) {
+ toPrint = toPrint + " * " + sound + "\n";
+ }
+ channel.sendMessage(toPrint).queue();
+ }
+
+ private void PopulateFiles(){
+ File folder = new File(filepath);
+ File[] listOfFiles = folder.listFiles();
+
+ for (File file : listOfFiles) {
+ if (file.isFile()) {
+ String filename = file.getName();
+ filenameDict.put(filename.substring(0, filename.indexOf('.')), filename);
+ }
+ }
+ }
+
+
+}