diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..95eb1e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM adoptopenjdk/openjdk11:latest +ARG token +ARG config_file=bot.properties.standard +ENV JSHELL_TOKEN=$token +# ENV JSHELL_BOT_CONFIG=/opt/app/$config_file +RUN mkdir /opt/app +WORKDIR /opt/app +COPY ./target/JShellBot.jar ./app.jar +COPY ./$config_file ./bot.properties + +CMD ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/src/main/resources/bot.properties b/bot.properties.standard similarity index 98% rename from src/main/resources/bot.properties rename to bot.properties.standard index f4658b5..7c9bb57 100644 --- a/src/main/resources/bot.properties +++ b/bot.properties.standard @@ -1,6 +1,6 @@ # The prefix for commands prefix=!jshell -# Th bot token +# The bot token token=yourtokengoeshere # How long a JShell session is kept around. Short means the history will be lost earlier, # but it will need less server resources, if many people use it. diff --git a/src/main/java/org/togetherjava/discord/server/Config.java b/src/main/java/org/togetherjava/discord/server/Config.java index 6b97ba8..f23c2be 100644 --- a/src/main/java/org/togetherjava/discord/server/Config.java +++ b/src/main/java/org/togetherjava/discord/server/Config.java @@ -57,6 +57,16 @@ public String getString(String key) { return properties.getProperty(key); } + /** + * Sets a property with a string + * + * @param key the key + * @param value the value of the property + */ + public void setString(String key, String value) { + properties.setProperty(key, value); + } + /** * Tries to parse an entry in ISO-8601 duration format. * diff --git a/src/main/java/org/togetherjava/discord/server/JShellBot.java b/src/main/java/org/togetherjava/discord/server/JShellBot.java index 6eb9b8e..f83bb02 100644 --- a/src/main/java/org/togetherjava/discord/server/JShellBot.java +++ b/src/main/java/org/togetherjava/discord/server/JShellBot.java @@ -56,6 +56,14 @@ private Config getConfig() throws IOException { + " or provide a 'bot.properties' file in the same directory as this jar file" ); System.exit(1); + } else { + Config config = new Config(path); + String token = System.getenv("JSHELL_TOKEN"); + if(token != null){ + //environment variable override for token i.e. building from container + config.setString("token", token); + } + return config; } return new Config(path); diff --git a/src/main/resources/bot.properties.example b/src/main/resources/bot.properties.example new file mode 100644 index 0000000..7c9bb57 --- /dev/null +++ b/src/main/resources/bot.properties.example @@ -0,0 +1,29 @@ +# The prefix for commands +prefix=!jshell +# The bot token +token=yourtokengoeshere +# How long a JShell session is kept around. Short means the history will be lost earlier, +# but it will need less server resources, if many people use it. +session.ttl=PT15M +# The maximum time a single command can take before it is killed +computation.allotted_time=PT15S +# Whether to auto delete the bot's messages +messages.auto_delete=false +# Defines after what timeout the bot messages should be deleted +messages.auto_delete.duration=PT15M +# Packages listed here will not be able to be used in JShell commands +blocked.packages=sun,\ + jdk,\ + java.lang.reflect,\ + java.lang.invoke,\ + org.togetherjava +# Classes listed here will not be able to be used in JShell commands +blocked.classes=java.lang.ProcessBuilder,\ + java.lang.ProcessHandle,\ + java.lang.Runtime +# Methods listed here will not be able to be used in JShell commands +blocked.methods=java.lang.System#exit,\ + java.lang.Thread#sleep,\ + java.lang.Thread#wait,\ + java.lang.Thread#notify,\ + java.lang.Thread#currentThread