|
|
@ -9,6 +9,7 @@ import java.io.File; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.StreamSupport; |
|
|
|
|
|
|
@ -19,6 +20,12 @@ public final class Resources { |
|
|
|
private static Properties propertiesFile; |
|
|
|
|
|
|
|
private static String jda_builder_string; |
|
|
|
|
|
|
|
private static final boolean default_greetings_and_byebyes_on = true; |
|
|
|
@Getter |
|
|
|
private static boolean greetings_and_byebyes_on = default_greetings_and_byebyes_on; |
|
|
|
private static List<String> greetings; |
|
|
|
private static List<String> byebyes; |
|
|
|
|
|
|
|
private static final String default_audio_source_directory = "rsc/audio/"; |
|
|
|
private static String audio_source_directory = default_audio_source_directory; |
|
|
@ -68,12 +75,11 @@ public final class Resources { |
|
|
|
sauceConfigPath = propertiesFile.getProperty("path_to_sauce_config"); |
|
|
|
|
|
|
|
boolean isOk = initJdaBuilderString(); |
|
|
|
if (isOk) isOk = initGreetingsAndByebyes(); |
|
|
|
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); |
|
|
|
|
|
|
@ -92,6 +98,27 @@ public final class Resources { |
|
|
|
public static String getJdaBuilderString() { |
|
|
|
return jda_builder_string; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initGreetingsAndByebyes(){ |
|
|
|
if(propertiesFile.containsKey("greetings_and_byebyes_on")) |
|
|
|
greetings_and_byebyes_on = propertiesFile.getProperty("greetings_and_byebyes_on").equals("true"); |
|
|
|
if(!greetings_and_byebyes_on) return true; |
|
|
|
try { |
|
|
|
greetings = Files.readAllLines(Paths.get("rsc/greetings.txt")); |
|
|
|
byebyes = Files.readAllLines(Paths.get("rsc/byebyes.txt")); |
|
|
|
} catch (IOException e) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
public static String getRandomGreeting(String name){ |
|
|
|
if(!greetings_and_byebyes_on) return null; |
|
|
|
return greetings.get((new Random()).nextInt(greetings.size()) - 1).replace("#", name); |
|
|
|
} |
|
|
|
public static String getRandomByebye(String name){ |
|
|
|
if(!greetings_and_byebyes_on) return null; |
|
|
|
return byebyes.get(new Random().nextInt(byebyes.size()) - 1).replace("#", name); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void initTagFilter() { |
|
|
|