bot: fixed some issues and updated the docs to handle permission granting

This commit is contained in:
Tyler Wilding
2025-12-04 19:10:33 -05:00
parent 37b0400503
commit 1432dc8c15
10 changed files with 13 additions and 8 deletions

View File

@@ -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
View File

View 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}"

View 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}"

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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