From 658ccf842e7d39a692745dd5de237ec6ac35f9a2 Mon Sep 17 00:00:00 2001 From: Ishmael Rufus Date: Tue, 12 Nov 2019 13:26:29 -0600 Subject: [PATCH 1/3] Moving bot.properties --- ...{bot.properties => bot.properties.example} | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) rename src/main/resources/{bot.properties => bot.properties.example} (97%) diff --git a/src/main/resources/bot.properties b/src/main/resources/bot.properties.example similarity index 97% rename from src/main/resources/bot.properties rename to src/main/resources/bot.properties.example index f4658b5..b56b78a 100644 --- a/src/main/resources/bot.properties +++ b/src/main/resources/bot.properties.example @@ -1,29 +1,29 @@ -# The prefix for commands -prefix=!jshell -# Th 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 +# The prefix for commands +prefix=!jshell +# Th 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 From 312ee41f822360e8e3e14399a0ede4900bb2979b Mon Sep 17 00:00:00 2001 From: Ishmael Rufus Date: Wed, 11 Dec 2019 17:56:06 -0600 Subject: [PATCH 2/3] Basic docker support Fixed typo in bot.properties.example --- Dockerfile | 11 ++++ bot.properties.standard | 29 ++++++++++ .../togetherjava/discord/server/Config.java | 10 ++++ .../discord/server/JShellBot.java | 9 +++ src/main/resources/bot.properties.example | 58 +++++++++---------- 5 files changed, 88 insertions(+), 29 deletions(-) create mode 100644 Dockerfile create mode 100644 bot.properties.standard 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/bot.properties.standard b/bot.properties.standard new file mode 100644 index 0000000..7c9bb57 --- /dev/null +++ b/bot.properties.standard @@ -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 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..4f5425b 100644 --- a/src/main/java/org/togetherjava/discord/server/JShellBot.java +++ b/src/main/java/org/togetherjava/discord/server/JShellBot.java @@ -44,6 +44,7 @@ private void start() throws Exception { private Config getConfig() throws IOException { String botConfigPath = System.getenv("JSHELL_BOT_CONFIG"); + // todo instead we should check env variables if (botConfigPath == null) { botConfigPath = "bot.properties"; } @@ -56,6 +57,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 index b56b78a..7c9bb57 100644 --- a/src/main/resources/bot.properties.example +++ b/src/main/resources/bot.properties.example @@ -1,29 +1,29 @@ -# The prefix for commands -prefix=!jshell -# Th 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 +# 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 From da3519ef1dc754c0601926897e8fb6eb904043fb Mon Sep 17 00:00:00 2001 From: Ishmael Rufus Date: Wed, 11 Dec 2019 17:56:41 -0600 Subject: [PATCH 3/3] Removed TODO --- src/main/java/org/togetherjava/discord/server/JShellBot.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/togetherjava/discord/server/JShellBot.java b/src/main/java/org/togetherjava/discord/server/JShellBot.java index 4f5425b..f83bb02 100644 --- a/src/main/java/org/togetherjava/discord/server/JShellBot.java +++ b/src/main/java/org/togetherjava/discord/server/JShellBot.java @@ -44,7 +44,6 @@ private void start() throws Exception { private Config getConfig() throws IOException { String botConfigPath = System.getenv("JSHELL_BOT_CONFIG"); - // todo instead we should check env variables if (botConfigPath == null) { botConfigPath = "bot.properties"; }