From 789064d2d59cb8f3f2ae131cda68864a8dba9298 Mon Sep 17 00:00:00 2001
From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com>
Date: Mon, 5 Sep 2022 18:39:31 +0200
Subject: [PATCH] recover from missing tty
---
Dockerfile | 7 ++-
pom.xml | 4 +-
run.sh | 5 ++
.../java/com/github/nilstrieb/core/Main.java | 57 +++++++++++--------
4 files changed, 44 insertions(+), 29 deletions(-)
create mode 100644 run.sh
diff --git a/Dockerfile b/Dockerfile
index eb0743a..ac92157 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,7 +1,8 @@
FROM maven AS build
WORKDIR /app
COPY . .
-RUN maven -f pom.xml clean package
+RUN mvn -f pom.xml clean assembly:assembly
-FROM openjdk:18-jre-slim
-COPY --from=build /app/target/1.0.0
\ No newline at end of file
+FROM gcr.io/distroless/java17
+COPY --from=build /app/target/KilluaBot-1.0.0-jar-with-dependencies.jar /app/KilluaBot.jar
+ENTRYPOINT ["java", "-jar", "/app/KilluaBot.jar"]
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 09d9e80..b046553 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,8 +9,8 @@
1.0.0
- 14
- 14
+ 18
+ 17
UTF-8
diff --git a/run.sh b/run.sh
new file mode 100644
index 0000000..3529efc
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+docker run -e "BOT_TOKEN=LOL" -e "KILLUA_JSON_PATH=/app/trivia_questions.json" \
+ -v "$(pwd)/trivia_questions.json:/app/trivia_questions.json" \
+ --name killua-bot killua-bot:1.0
\ No newline at end of file
diff --git a/src/main/java/com/github/nilstrieb/core/Main.java b/src/main/java/com/github/nilstrieb/core/Main.java
index 8dabc51..cbb9416 100644
--- a/src/main/java/com/github/nilstrieb/core/Main.java
+++ b/src/main/java/com/github/nilstrieb/core/Main.java
@@ -42,35 +42,44 @@ public class Main {
Config.setJda(jda);
Thread t = new Thread(() -> {
- Scanner scanner = new Scanner(System.in);
- String line = scanner.nextLine();
- while (!line.equals("exit") && !line.equals("quit")) {
- if (line.startsWith("send")) {
- System.out.println("GuildID");
- line = scanner.nextLine();
- Guild guild = jda.getGuildById(line);
- if (guild != null) {
- System.out.println("TextChannelID");
- line = scanner.nextLine();
- TextChannel textChannel = guild.getTextChannelById(line);
- if (textChannel != null) {
- System.out.println("Message");
- line = scanner.nextLine();
- if (!line.equals("")) {
- textChannel.sendMessage(line).queue();
- }
- }
- }
- } else if (line.startsWith("version") || line.startsWith("v")) {
- System.out.println(Config.VERSION);
- }
- line = scanner.nextLine();
+ try {
+ interactivePrompt(jda);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.println("Interactive mode failed, presumably no TTY attached. Ignoring interactive mode...");
}
- System.exit(0);
});
t.start();
}
+ private static void interactivePrompt(JDA jda) {
+ Scanner scanner = new Scanner(System.in);
+ String line = scanner.nextLine();
+ while (!line.equals("exit") && !line.equals("quit")) {
+ if (line.startsWith("send")) {
+ System.out.println("GuildID");
+ line = scanner.nextLine();
+ Guild guild = jda.getGuildById(line);
+ if (guild != null) {
+ System.out.println("TextChannelID");
+ line = scanner.nextLine();
+ TextChannel textChannel = guild.getTextChannelById(line);
+ if (textChannel != null) {
+ System.out.println("Message");
+ line = scanner.nextLine();
+ if (!line.equals("")) {
+ textChannel.sendMessage(line).queue();
+ }
+ }
+ }
+ } else if (line.startsWith("version") || line.startsWith("v")) {
+ System.out.println(Config.VERSION);
+ }
+ line = scanner.nextLine();
+ }
+ System.exit(0);
+ }
+
private static void setupCommands() {
new HelpCommand();
new EvalCommand();