aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/soundchan/LocalAudioManager.java
blob: 9a4e299fb0a8ab1bf894d3ba5f1edd0b52978af2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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";
        }
        toPrint = toPrint + "```";
        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);
            }
        }
    }


}