From 908bbc07be9a655767a49269b4b939993ac066b3 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:20:42 +0700 Subject: [PATCH] feat: save console history to a file so we can restore it on the next boot --- build-number.txt | 2 +- .../chayapak1/chomens_bot/plugins/ConsolePlugin.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/build-number.txt b/build-number.txt index af9719be..54da69e9 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3517 \ No newline at end of file +3519 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/ConsolePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/ConsolePlugin.java index 48e9f29b..ef302de8 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/ConsolePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/ConsolePlugin.java @@ -17,10 +17,13 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import org.jetbrains.annotations.NotNull; import org.jline.reader.*; +import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; public class ConsolePlugin implements Completer { + private static final Path HISTORY_PATH = Path.of(".console_history"); private static final ConsoleFormatRenderer RENDERER = new ConsoleFormatRenderer(); private final List allBots; @@ -40,10 +43,10 @@ public class ConsolePlugin implements Completer { this.reader = LineReaderBuilder .builder() .completer(this) + .variable(LineReader.HISTORY_FILE, HISTORY_PATH) + .option(LineReader.Option.DISABLE_EVENT_EXPANSION, true) .build(); - reader.option(LineReader.Option.DISABLE_EVENT_EXPANSION, true); - final Thread thread = new Thread( () -> { while (true) { @@ -55,6 +58,10 @@ public class ConsolePlugin implements Completer { } handleLine(line); + + try { + reader.getHistory().save(); + } catch (final IOException ignored) { } } }, "Console Thread"