diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java index f70fd88..b9f173f 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java @@ -50,13 +50,13 @@ public class GrepLogCommand implements Command { boolean regex = false; if (_args[0].equals("stop")) { - bot.grepLog().future().cancel(true); - bot.grepLog().future(null); + bot.grepLog().thread().interrupt(); + bot.grepLog().thread(null); return Component.text("Log query stopped"); } - if (bot.grepLog().future() != null) return Component.text("Another query is already running").color(NamedTextColor.RED); + if (bot.grepLog().thread() != null) return Component.text("Another query is already running").color(NamedTextColor.RED); // this is a mess if (_args[0].equals("-ignorecase")) { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java index d1a7fe3..d9b932a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java @@ -13,26 +13,24 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Comparator; -import java.util.concurrent.Future; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; public class GrepLogPlugin { private final Bot bot; - @Getter @Setter private Future future = null; + @Getter @Setter private Thread thread = null; public GrepLogPlugin (Bot bot) { this.bot = bot; } public void query (String query, boolean regex, boolean ignoreCase) { - final Runnable runnable = new GrepLogRunnable(query, regex, ignoreCase); - future = bot.executorService().submit(runnable); + thread = new GrepLogThread(query, regex, ignoreCase); } // should i move this to another file or keep it here - public class GrepLogRunnable implements Runnable { + public class GrepLogThread extends Thread { private String query; private final boolean regex; private final boolean ignoreCase; @@ -44,7 +42,7 @@ public class GrepLogPlugin { private int matches = 0; private final StringBuilder results = new StringBuilder(); - public GrepLogRunnable(String query, boolean regex, boolean ignoreCase) { + public GrepLogThread(String query, boolean regex, boolean ignoreCase) { this.regex = regex; this.ignoreCase = ignoreCase; @@ -181,8 +179,13 @@ public class GrepLogPlugin { final String channelId = bot.discord().servers.get(bot.host() + ":" + bot.port()); final TextChannel logChannel = bot.discord().jda().getTextChannelById(channelId); + + if (logChannel == null) return; + logChannel.sendMessage("Log query output").addFile(results.toString().getBytes(), "report.txt").queue(); } + + thread = null; } } }