|
|
@ -1,7 +1,6 @@ |
|
|
|
package de.yannicpunktdee.yoshibot.utils; |
|
|
|
|
|
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Logger.Type; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import org.json.JSONArray; |
|
|
@ -40,6 +39,8 @@ public final class Resources { |
|
|
|
private static String patPngPath; |
|
|
|
@Getter |
|
|
|
private static String imagePath; |
|
|
|
@Getter |
|
|
|
private static String bonkPngPath; |
|
|
|
|
|
|
|
@Getter |
|
|
|
private static String jda_builder_string; |
|
|
@ -78,15 +79,16 @@ public final class Resources { |
|
|
|
if (isOk) isOk = initTagFilter(); |
|
|
|
if (isOk) isOk = initPatPngPath(); |
|
|
|
if (isOk) isOk = initImages(); |
|
|
|
if (isOk) isOk = initBonkPngPath(); |
|
|
|
|
|
|
|
if (isOk) Logger.log("Die Konfigurationen wurden erfolgreich geladen.", Type.INFO); |
|
|
|
else Logger.log("Die Konfiguration konnte nicht geladen werden", Type.ERROR); |
|
|
|
if (isOk) Logger.logInfo("Die Konfigurationen wurden erfolgreich geladen."); |
|
|
|
else Logger.logError("Die Konfiguration konnte nicht geladen werden"); |
|
|
|
|
|
|
|
return isOk; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initResources(String resourcePathArg) { |
|
|
|
Logger.log("Versuche Resource-Verzeichnis zu finden.", Type.INFO); |
|
|
|
Logger.logInfo("Versuche Resource-Verzeichnis zu finden."); |
|
|
|
|
|
|
|
resourcePath = (new File((resourcePathArg == null) ? "rsc" : resourcePathArg)).getAbsolutePath() |
|
|
|
.replace('\\', '/') + "/"; |
|
|
@ -118,7 +120,7 @@ public final class Resources { |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initTemp() { |
|
|
|
Logger.log("Versuche Temp-Verzeichnis zu finden.", Type.INFO); |
|
|
|
Logger.logInfo("Versuche Temp-Verzeichnis zu finden."); |
|
|
|
|
|
|
|
String theoreticalTempPath = System.getProperty("java.io.tmpdir").replace('\\', '/') + "/yoshibot/"; |
|
|
|
|
|
|
@ -131,7 +133,7 @@ public final class Resources { |
|
|
|
if (tempDir.mkdir()) { |
|
|
|
return verifyExists(tempDir.getAbsolutePath(), File::isDirectory) != null; |
|
|
|
} else { |
|
|
|
Logger.log("Temp-Verzeichnis konnte nicht erstellt werden.", Type.ERROR); |
|
|
|
Logger.logError("Temp-Verzeichnis konnte nicht erstellt werden."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -140,7 +142,7 @@ public final class Resources { |
|
|
|
File tempDirFile = new File(tempPath); |
|
|
|
if (!tempDirFile.isDirectory()) { |
|
|
|
if (!new File(tempPath).mkdir()) { |
|
|
|
Logger.log("TempPath konnte nicht erstellt werden", Type.ERROR); |
|
|
|
Logger.logError("TempPath konnte nicht erstellt werden"); |
|
|
|
} |
|
|
|
} |
|
|
|
return tempPath + name + ".opus"; |
|
|
@ -167,7 +169,7 @@ public final class Resources { |
|
|
|
return false; |
|
|
|
} |
|
|
|
jda_builder_string = Files.readAllLines(new File(resourcePath + "PrivateJdaBuilderString.txt").toPath()).get(0); |
|
|
|
Logger.log("jda_builder_string erfolgreich geladen", Type.INFO); |
|
|
|
Logger.logInfo("jda_builder_string erfolgreich geladen"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -175,20 +177,25 @@ public final class Resources { |
|
|
|
patPngPath = verifyExists(resourcePath + "pats/", File::isDirectory); |
|
|
|
return patPngPath != null; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initBonkPngPath() { |
|
|
|
bonkPngPath = verifyExists(resourcePath + "bonks/", File::isDirectory); |
|
|
|
return bonkPngPath != null; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean initGuildId() { |
|
|
|
if (!propertiesFile.containsKey("guild_id")) { |
|
|
|
Logger.log("Die Config.properties benötigt das Attribut guild_id.", Type.ERROR); |
|
|
|
Logger.logError("Die Config.properties benötigt das Attribut guild_id."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
String raw = propertiesFile.getProperty("guild_id"); |
|
|
|
try { |
|
|
|
guild_id = Long.parseLong(raw); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
Logger.log("Die angegebene guild_id ist keine Ganzzahl", Type.ERROR); |
|
|
|
Logger.logError("Die angegebene guild_id ist keine Ganzzahl"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
Logger.log("guild_id erfolgreich geladen", Type.INFO); |
|
|
|
Logger.logInfo("guild_id erfolgreich geladen"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -257,7 +264,7 @@ public final class Resources { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
Logger.log("tags_general_filter erfolgreich geladen", Type.INFO); |
|
|
|
Logger.logInfo("tags_general_filter erfolgreich geladen"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -268,21 +275,21 @@ public final class Resources { |
|
|
|
} |
|
|
|
if (new File(resourcePath + "image/").mkdir()) { |
|
|
|
imagePath = verifyExists(resourcePath + "image/", File::isDirectory); |
|
|
|
Logger.log("Bildordner erzeugt", Type.INFO); |
|
|
|
Logger.logInfo("Bildordner erzeugt"); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
Logger.log("Konnte Bildordner nicht erzeugen!", Type.ERROR); |
|
|
|
Logger.logError("Konnte Bildordner nicht erzeugen!"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static String verifyExists(String filename, Function<File, Boolean> checkIsValidFile) { |
|
|
|
String[] split = filename.split("/"); |
|
|
|
Logger.log(String.format("Versuche %s zu finden.", split[split.length - 1]), Type.INFO); |
|
|
|
Logger.logInfo(String.format("Versuche %s zu finden.", split[split.length - 1])); |
|
|
|
if (checkIsValidFile.apply(new File(filename))) { |
|
|
|
return filename; |
|
|
|
} else { |
|
|
|
Logger.log(String.format("%s konnte nicht gefunden werden", filename), Type.ERROR); |
|
|
|
Logger.logError(String.format("%s konnte nicht gefunden werden", filename)); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|