From e9ff559c08fa0529b5c6da9cf82d0beb6e7e7e17 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 10 Apr 2018 21:57:14 -0400 Subject: Add local audio file support, including listing files Remove unused function, rename ConnectVoiceChannel function --- src/main/java/soundchan/LocalAudioManager.java | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/soundchan/LocalAudioManager.java (limited to 'src/main/java/soundchan/LocalAudioManager.java') 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 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 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); + } + } + } + + +} -- cgit v1.2.3