|
|
@ -14,7 +14,7 @@ import java.util.stream.Collectors; |
|
|
|
|
|
|
|
public class Resources { |
|
|
|
|
|
|
|
private static final String default_propertiesFilePath = "../rsc/Config.properties"; |
|
|
|
private static final String default_propertiesFilePath = "rsc/Config.properties"; |
|
|
|
private static String propertiesFilePath = default_propertiesFilePath; |
|
|
|
private static Properties propertiesFile; |
|
|
|
|
|
|
@ -25,14 +25,14 @@ public class Resources { |
|
|
|
|
|
|
|
private static final String[] default_restrict_commands_to_channel = null; |
|
|
|
private static String[] restrict_commands_to_channel = default_restrict_commands_to_channel; |
|
|
|
|
|
|
|
|
|
|
|
private static String[] filtered_tags; |
|
|
|
private static Map<String, List<String>> feedDetails; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized static boolean init(String pathToConfig) { |
|
|
|
Logger.log("Lade Config.properties ...", Type.INFO); |
|
|
|
|
|
|
|
|
|
|
|
if (pathToConfig != null) { |
|
|
|
if (!(new File(pathToConfig)).exists()) { |
|
|
|
Logger.log("Der in den Argumenten angegebene Pfad zur Config.properties existiert nicht.", Type.ERROR); |
|
|
@ -44,26 +44,26 @@ public class Resources { |
|
|
|
Type.ERROR); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
propertiesFile = new Properties(); |
|
|
|
try { |
|
|
|
propertiesFile.load( |
|
|
|
new FileInputStream(propertiesFilePath) |
|
|
|
); |
|
|
|
); |
|
|
|
Logger.log("Config-Datei erfolgreich geladen.", Type.INFO); |
|
|
|
} catch (IOException e) { |
|
|
|
Logger.log("Es ist ein Fehler beim Öffnen der Config.propeties aufgetreten.", Type.ERROR); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean isOk = initJdaBuilderString(); |
|
|
|
if (isOk) isOk = initChannelRestrict(); |
|
|
|
if (isOk) isOk = initAudio(); |
|
|
|
initTagFilter(); |
|
|
|
|
|
|
|
|
|
|
|
if (isOk) Logger.log("Die Konfigurationen wurden erfolgreich geladen.", Type.INFO); |
|
|
|
else Logger.log("Die Konfiguration konnte nicht geladen werden", Type.ERROR); |
|
|
|
|
|
|
|
|
|
|
|
return isOk; |
|
|
|
} |
|
|
|
|
|
|
@ -75,12 +75,12 @@ public class Resources { |
|
|
|
jda_builder_string = propertiesFile.getProperty("jda_builder_string"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String getJdaBuilderString() { |
|
|
|
return jda_builder_string; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void initTagFilter() { |
|
|
|
if (!propertiesFile.containsKey("tags_general_filter")) { |
|
|
|
Logger.log("Kein Attribut 'tags_general_filter' gefunden", Type.WARNING); |
|
|
@ -96,32 +96,39 @@ public class Resources { |
|
|
|
list -> Arrays.asList(list).subList(1, list.length))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static boolean initAudio() { |
|
|
|
if (propertiesFile.containsKey("audio_source_directory")) { |
|
|
|
audio_source_directory = propertiesFile.getProperty("audio_source_directory"); |
|
|
|
} else { |
|
|
|
Logger.log("Die Config.properties spezifiziert kein audio_source_directory. Lade default.", Type.WARNING); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
File file = new File(audio_source_directory); |
|
|
|
if (!file.exists() || !file.isDirectory()) { |
|
|
|
Logger.log("Das Audio-Verzeichnis wurde nicht gefunden.", Type.ERROR); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (file.listFiles().length < 1) |
|
|
|
Logger.log("Das Audio-Verzeichnis ist leer.", Type.WARNING); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String getAudioFilePath(String name) { |
|
|
|
name = audio_source_directory + (audio_source_directory.endsWith("/") ? "" : "/") + name + ".opus"; |
|
|
|
if ((new File(name)).exists()) return name; |
|
|
|
else return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static String getTempAudioFilePath(String name) { |
|
|
|
name = audio_source_directory + (audio_source_directory.endsWith("/")? "" : "/") + "temp/" + name + ".opus"; |
|
|
|
if((new File(name)).exists()) return name; |
|
|
|
else return null; |
|
|
|
} |
|
|
|
public static String buildTempAudioFilePath(String name){ |
|
|
|
return audio_source_directory + (audio_source_directory.endsWith("/")? "" : "/") + "temp/" + name + ".opus"; |
|
|
|
} |
|
|
|
public static String getAudioSourceDirectory() { |
|
|
|
return audio_source_directory; |
|
|
|
} |
|
|
@ -131,17 +138,17 @@ public class Resources { |
|
|
|
restrict_commands_to_channel = propertiesFile.getProperty("restrict_commands_to_channel").split(" "); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String[] getRestrictCommandsToChannel() { |
|
|
|
return restrict_commands_to_channel; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, List<String>> getFeedDetails() { |
|
|
|
return feedDetails; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String[] getGeneralFilterTags() { |
|
|
|
return filtered_tags; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |