diff options
Diffstat (limited to 'src/main/java/soundchan/LocalAudioManager.java')
-rw-r--r-- | src/main/java/soundchan/LocalAudioManager.java | 55 |
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); + } + } + } + + +} |