|
@ -13,6 +13,7 @@ import java.nio.file.Files; |
|
|
import java.nio.file.Paths; |
|
|
import java.nio.file.Paths; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.function.Function; |
|
|
import java.util.function.Function; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.StreamSupport; |
|
|
import java.util.stream.StreamSupport; |
|
|
|
|
|
|
|
|
public final class Resources { |
|
|
public final class Resources { |
|
@ -23,7 +24,7 @@ public final class Resources { |
|
|
private static String configPath; |
|
|
private static String configPath; |
|
|
@Getter |
|
|
@Getter |
|
|
private static String audioPath; |
|
|
private static String audioPath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String tempPath; |
|
|
private static String tempPath; |
|
|
@Getter |
|
|
@Getter |
|
|
private static String activitiesPath; |
|
|
private static String activitiesPath; |
|
@ -45,6 +46,9 @@ public final class Resources { |
|
|
@Getter |
|
|
@Getter |
|
|
private static String jda_builder_string; |
|
|
private static String jda_builder_string; |
|
|
|
|
|
|
|
|
|
|
|
@Getter |
|
|
|
|
|
private static Map<String, String> redditData; |
|
|
|
|
|
|
|
|
@Getter |
|
|
@Getter |
|
|
private static Long guild_id; |
|
|
private static Long guild_id; |
|
|
|
|
|
|
|
@ -62,6 +66,7 @@ public final class Resources { |
|
|
private static final Map<String, List<String>> feedDetails = new HashMap<>(); |
|
|
private static final Map<String, List<String>> feedDetails = new HashMap<>(); |
|
|
|
|
|
|
|
|
private static Properties propertiesFile; |
|
|
private static Properties propertiesFile; |
|
|
|
|
|
private static Properties redditCreds; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized static boolean init(String resourcePathArg) { |
|
|
public synchronized static boolean init(String resourcePathArg) { |
|
@ -80,6 +85,7 @@ public final class Resources { |
|
|
if (isOk) isOk = initPatPngPath(); |
|
|
if (isOk) isOk = initPatPngPath(); |
|
|
if (isOk) isOk = initImages(); |
|
|
if (isOk) isOk = initImages(); |
|
|
if (isOk) isOk = initBonkPngPath(); |
|
|
if (isOk) isOk = initBonkPngPath(); |
|
|
|
|
|
if (isOk) isOk = initReddit(); |
|
|
|
|
|
|
|
|
if (isOk) Logger.logInfo("Die Konfigurationen wurden erfolgreich geladen."); |
|
|
if (isOk) Logger.logInfo("Die Konfigurationen wurden erfolgreich geladen."); |
|
|
else Logger.logError("Die Konfiguration konnte nicht geladen werden"); |
|
|
else Logger.logError("Die Konfiguration konnte nicht geladen werden"); |
|
@ -107,6 +113,9 @@ public final class Resources { |
|
|
propertiesFile = new Properties(); |
|
|
propertiesFile = new Properties(); |
|
|
propertiesFile.load(new FileInputStream(configPath)); |
|
|
propertiesFile.load(new FileInputStream(configPath)); |
|
|
|
|
|
|
|
|
|
|
|
redditCreds = new Properties(); |
|
|
|
|
|
redditCreds.load(new FileInputStream(resourcePath + "RedditCredentials.properties")); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -137,14 +146,23 @@ public final class Resources { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static String getTempPath(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getTempPath() { |
|
|
|
|
|
if (tempPath == null){ |
|
|
|
|
|
initTemp(); |
|
|
|
|
|
} |
|
|
File tempDir = new File(tempPath); |
|
|
File tempDir = new File(tempPath); |
|
|
if(!tempDir.isDirectory()) |
|
|
|
|
|
if(!tempDir.mkdir()) return null; |
|
|
|
|
|
|
|
|
if (!tempDir.isDirectory()) |
|
|
|
|
|
if (!tempDir.mkdir()) throw new Error("Could not make Temp directory"); |
|
|
return tempPath; |
|
|
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() { |
|
|
private static boolean initActivities() { |
|
|
activitiesPath = verifyExists(resourcePath + "activities.txt", File::isFile); |
|
|
activitiesPath = verifyExists(resourcePath + "activities.txt", File::isFile); |
|
|
return activitiesPath != null; |
|
|
return activitiesPath != null; |
|
@ -174,7 +192,7 @@ public final class Resources { |
|
|
patPngPath = verifyExists(resourcePath + "pats/", File::isDirectory); |
|
|
patPngPath = verifyExists(resourcePath + "pats/", File::isDirectory); |
|
|
return patPngPath != null; |
|
|
return patPngPath != null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean initBonkPngPath() { |
|
|
private static boolean initBonkPngPath() { |
|
|
bonkPngPath = verifyExists(resourcePath + "bonks/", File::isDirectory); |
|
|
bonkPngPath = verifyExists(resourcePath + "bonks/", File::isDirectory); |
|
|
return bonkPngPath != null; |
|
|
return bonkPngPath != null; |
|
@ -282,7 +300,7 @@ public final class Resources { |
|
|
|
|
|
|
|
|
private static String verifyExists(String filename, Function<File, Boolean> checkIsValidFile) { |
|
|
private static String verifyExists(String filename, Function<File, Boolean> checkIsValidFile) { |
|
|
String[] split = filename.split("/"); |
|
|
String[] split = filename.split("/"); |
|
|
Logger.logInfo(String.format("Versuche %s zu finden.", split[split.length - 1])); |
|
|
|
|
|
|
|
|
Logger.logDebug(String.format("Versuche %s zu finden.", split[split.length - 1])); |
|
|
if (checkIsValidFile.apply(new File(filename))) { |
|
|
if (checkIsValidFile.apply(new File(filename))) { |
|
|
return filename; |
|
|
return filename; |
|
|
} else { |
|
|
} else { |
|
|