mirror of
https://github.com/PCSX2/hifumi.git
synced 2026-01-31 01:25:17 +01:00
bot: fixed some issues and updated the docs to handle permission granting
This commit is contained in:
@@ -16,5 +16,8 @@ mvn install
|
||||
- Build the container locally:
|
||||
- `docker build -t hifumi:local .`
|
||||
- Put your files (db file / json files) in `data/`
|
||||
- Ensure that the `data/` folder has the correct permissions for the container to use:
|
||||
- `docker run --rm hifumi:local sh -c "id -u app; id -g app" | { read uid; read gid; sudo chown -R $uid:$gid ./data/; }`
|
||||
- Alternatively you can just make it accessible to all users/groups: `chmod -R 777 ./data`
|
||||
- Run it via docker-compose:
|
||||
- `DISCORD_BOT_TOKEN=TOKEN_HERE SUPERUSER_ID=ID_HERE DEEPL_KEY=KEY_HERE docker compose -f ./docker-compose.local.yaml up`
|
||||
0
data/.gitignore
vendored
Normal file → Executable file
0
data/.gitignore
vendored
Normal file → Executable file
@@ -7,8 +7,8 @@ services:
|
||||
# Required environment variables
|
||||
DISCORD_BOT_TOKEN: "${DISCORD_BOT_TOKEN}"
|
||||
SUPERUSER_ID: "${SUPERUSER_ID}"
|
||||
DEEPL_KEY: "${DEEPL_KEY}"
|
||||
DATA_DIRECTORY: "/opt/data"
|
||||
DEEPL_KEY: "${DEEPL_KEY}"
|
||||
|
||||
# Optional: enable trace logs if HIFUMI_TRACE is set
|
||||
HIFUMI_TRACE: "${HIFUMI_TRACE:-false}"
|
||||
|
||||
@@ -7,8 +7,8 @@ services:
|
||||
# Required environment variables
|
||||
DISCORD_BOT_TOKEN: "${DISCORD_BOT_TOKEN}"
|
||||
SUPERUSER_ID: "${SUPERUSER_ID}"
|
||||
DEEPL_KEY: "${DEEPL_KEY}"
|
||||
DATA_DIRECTORY: "/opt/data"
|
||||
DEEPL_KEY: "${DEEPL_KEY}"
|
||||
|
||||
# Optional: enable trace logs if HIFUMI_TRACE is set
|
||||
HIFUMI_TRACE: "${HIFUMI_TRACE:-false}"
|
||||
|
||||
@@ -71,10 +71,12 @@ public class HifumiBot {
|
||||
// Just commit to using env-vars, we're the only hoster!
|
||||
discordBotToken = Strings.getEnvVarOrPanic("DISCORD_BOT_TOKEN");
|
||||
superuserId = Strings.getEnvVarOrPanic("SUPERUSER_ID");
|
||||
deepLKey = Strings.getEnvVarOrPanic("DEEPL_KEY");
|
||||
dataDirectory = Strings.getEnvVarOrPanic("DATA_DIRECTORY");
|
||||
deepLKey = Strings.getEnvVarOrPanic("DEEPL_KEY");
|
||||
ConfigManager.dataDirectory = dataDirectory;
|
||||
|
||||
System.setProperty("org.slf4j.simpleLogger.logFile", String.format("%s/trace.log", dataDirectory));
|
||||
|
||||
if (System.getenv().containsKey("HIFUMI_TRACE")) {
|
||||
traceLogs = Boolean.parseBoolean(System.getenv("HIFUMI_TRACE").toLowerCase());
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ConfigManager {
|
||||
if (dataDirectory == null) {
|
||||
throw new RuntimeException("Data Directory was not initialized in the config manager singleton");
|
||||
}
|
||||
return String.format("{}/{}", dataDirectory, configType.getFileName());
|
||||
return String.format("%s/%s", dataDirectory, configType.getFileName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,9 +16,10 @@ public class SQLite {
|
||||
// NOTE: this shouldn't be needed for modern versions of java, it should just dynamically look
|
||||
// at the classpath for you, but leaving it here incase im wrong
|
||||
// Class.forName("org.sqlite.JDBC");
|
||||
var jbdcString = String.format("jdbc:sqlite:{}/hifumibot.db", dataDirectory);
|
||||
var jbdcString = String.format("jdbc:sqlite:%s/hifumibot.db", dataDirectory);
|
||||
Log.info("Opening database with JBDC string: " + jbdcString);
|
||||
this.connection = DriverManager.getConnection(jbdcString);
|
||||
// TODO - ensure database migrations have been committed
|
||||
} catch (Exception e) {
|
||||
Messaging.logException("SQlite", "(constructor)", e);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class Messaging {
|
||||
}
|
||||
|
||||
public static void logException(String className, String methodName, Exception e) {
|
||||
if (HifumiBot.getSelf().getJDA() == null) {
|
||||
if (HifumiBot.getSelf().getJDA() == null || HifumiBot.getSelf().getConfig() == null || HifumiBot.getSelf().getConfig().channels.systemOutputChannelId.isEmpty()) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Strings {
|
||||
public static String getEnvVarOrPanic(String envVar) {
|
||||
var value = System.getenv().getOrDefault(envVar, null);
|
||||
if (value == null) {
|
||||
throw new RuntimeException(String.format("Did not provide env-var: '{}'", envVar));
|
||||
throw new RuntimeException(String.format("Did not provide env-var: '%s'", envVar));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -4,4 +4,3 @@
|
||||
org.slf4j.simpleLogger.showDateTime=true
|
||||
org.slf4j.simpleLogger.showThreadName=true
|
||||
org.slf4j.simpleLogger.showLogName=true
|
||||
org.slf4j.simpleLogger.logFile=./trace.txt
|
||||
|
||||
Reference in New Issue
Block a user