|
|
@ -13,73 +13,35 @@ import java.nio.file.Files; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.StreamSupport; |
|
|
|
|
|
|
|
public final class Resources { |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static String resourcePath; |
|
|
|
@Getter |
|
|
|
private static String configPath; |
|
|
|
@Getter |
|
|
|
private static String audioPath; |
|
|
|
|
|
|
|
private static String tempPath; |
|
|
|
@Getter |
|
|
|
private static String activitiesPath; |
|
|
|
@Getter |
|
|
|
private static String greetingsPath; |
|
|
|
@Getter |
|
|
|
private static String byebyesPath; |
|
|
|
@Getter |
|
|
|
private static String sauceConfigPath; |
|
|
|
@Getter |
|
|
|
private static String ttsPath; |
|
|
|
@Getter |
|
|
|
private static String patPngPath; |
|
|
|
@Getter |
|
|
|
private static String imagePath; |
|
|
|
@Getter |
|
|
|
private static String bonkPngPath; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static String jda_builder_string; |
|
|
|
private static boolean greetings_and_byebyes_on; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static Map<String, String> redditData; |
|
|
|
private static int status_update; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static Long guild_id; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static boolean greetings_and_byebyes_on; |
|
|
|
private static List<String> greetings; |
|
|
|
private static List<String> byebyes; |
|
|
|
private static String resourcePath, configPath, audioPath, tempPath, activitiesPath, greetingsPath, byebyesPath, |
|
|
|
sauceConfigPath, ttsPath, patPngPath, imagePath, bonkPngPath, jda_builder_string, mc_server, status_channel, |
|
|
|
status_message_vanilla, status_message_modded, status_message_18, path_to_mcstatus, comebacksPath, |
|
|
|
departsPath; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static String[] restrict_commands_to_channel; |
|
|
|
private static List<String> greetings, byebyes, departs, comebacks; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static String[] filteredTags; |
|
|
|
private static String[] restrict_commands_to_channel, filteredTags; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static final Map<String, List<String>> feedDetails = new HashMap<>(); |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static String mc_server; |
|
|
|
@Getter |
|
|
|
private static String status_channel; |
|
|
|
@Getter |
|
|
|
private static String status_message_vanilla; |
|
|
|
@Getter |
|
|
|
private static String status_message_modded; |
|
|
|
@Getter |
|
|
|
private static int status_update; |
|
|
|
@Getter |
|
|
|
private static String path_to_mcstatus; |
|
|
|
|
|
|
|
private static Properties propertiesFile; |
|
|
|
private static Properties redditCreds; |
|
|
|
|
|
|
|
|
|
|
|
public synchronized static boolean init(String resourcePathArg) { |
|
|
@ -98,7 +60,6 @@ public final class Resources { |
|
|
|
if (isOk) isOk = initPatPngPath(); |
|
|
|
if (isOk) isOk = initImages(); |
|
|
|
if (isOk) isOk = initBonkPngPath(); |
|
|
|
if (isOk) isOk = initReddit(); |
|
|
|
if (isOk) isOk = initStatusMessage(); |
|
|
|
|
|
|
|
if (isOk) Logger.logInfo("Die Konfigurationen wurden erfolgreich geladen."); |
|
|
@ -127,15 +88,11 @@ public final class Resources { |
|
|
|
propertiesFile = new Properties(); |
|
|
|
propertiesFile.load(new FileInputStream(configPath)); |
|
|
|
|
|
|
|
redditCreds = new Properties(); |
|
|
|
redditCreds.load(new FileInputStream(resourcePath + "RedditCredentials.properties")); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initAudio() { |
|
|
|
audioPath = verifyExists(resourcePath + "audio/", File::isDirectory); |
|
|
|
return audioPath != null; |
|
|
|
return (audioPath = verifyExists(resourcePath + "audio/", File::isDirectory)) != null; |
|
|
|
} |
|
|
|
|
|
|
|
public static String getPathToAudioFile(String name) { |
|
|
@ -161,7 +118,7 @@ public final class Resources { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static String getTempPath() { |
|
|
|
public static String getEnsuredTempPath() { |
|
|
|
if (tempPath == null) { |
|
|
|
initTemp(); |
|
|
|
} |
|
|
@ -171,12 +128,6 @@ public final class Resources { |
|
|
|
return tempPath; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initReddit() { |
|
|
|
redditData = redditCreds.stringPropertyNames().stream() |
|
|
|
.collect(Collectors.toMap(p -> p, property -> redditCreds.getProperty(property))); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initActivities() { |
|
|
|
activitiesPath = verifyExists(resourcePath + "activities.txt", File::isFile); |
|
|
|
return activitiesPath != null; |
|
|
@ -231,12 +182,12 @@ public final class Resources { |
|
|
|
@SneakyThrows |
|
|
|
private static boolean initGreetingsAndByebyes() { |
|
|
|
greetingsPath = verifyExists(resourcePath + "greetings.txt", File::isFile); |
|
|
|
|
|
|
|
if (greetingsPath == null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
byebyesPath = verifyExists(resourcePath + "byebyes.txt", File::isFile); |
|
|
|
byebyesPath = verifyExists(resourcePath + "byebyes.txt", File::isFile); |
|
|
|
comebacksPath = verifyExists(resourcePath + "comebacks.txt", File::isFile); |
|
|
|
departsPath = verifyExists(resourcePath + "departs.txt", File::isFile); |
|
|
|
|
|
|
|
if (propertiesFile.containsKey("greetings_and_byebyes_on")) { |
|
|
|
greetings_and_byebyes_on = Boolean.parseBoolean(propertiesFile.getProperty("greetings_and_byebyes_on")); |
|
|
@ -245,6 +196,8 @@ public final class Resources { |
|
|
|
|
|
|
|
greetings = Files.readAllLines(Paths.get(greetingsPath)); |
|
|
|
byebyes = Files.readAllLines(Paths.get(byebyesPath)); |
|
|
|
comebacks = Files.readAllLines(Paths.get(comebacksPath)); |
|
|
|
departs = Files.readAllLines(Paths.get(departsPath)); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -256,6 +209,10 @@ public final class Resources { |
|
|
|
return greetings_and_byebyes_on ? String.format(getRandomFrom(byebyes), name) : null; |
|
|
|
} |
|
|
|
|
|
|
|
public static String getRandomAfk(String name, boolean didComeBack) { |
|
|
|
return greetings_and_byebyes_on ? String.format(getRandomFrom(didComeBack ? comebacks : departs), name) : null; |
|
|
|
} |
|
|
|
|
|
|
|
private static String getRandomFrom(List<String> pool) { |
|
|
|
return pool.get(YoshiBot.getInstance().getRandom().nextInt(pool.size())); |
|
|
|
} |
|
|
@ -331,7 +288,8 @@ public final class Resources { |
|
|
|
status_channel = propertiesFile.getProperty("status_channel"); |
|
|
|
status_message_vanilla = propertiesFile.getProperty("status_message_vanilla"); |
|
|
|
status_message_modded = propertiesFile.getProperty("status_message_modded"); |
|
|
|
path_to_mcstatus = propertiesFile.getProperty("path_to_mcstatus"); |
|
|
|
status_message_18 = propertiesFile.getProperty("status_message_eighteen"); |
|
|
|
path_to_mcstatus = propertiesFile.getProperty("path_to_mcstatus"); |
|
|
|
try { |
|
|
|
status_update = Integer.parseInt(propertiesFile.getProperty("status_update")); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|