From a18b34b7847b7c3cb4c3be4cde7b564725275f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Fri, 26 Aug 2022 20:27:46 +0200 Subject: [PATCH] Add pause command to halt processing Useful for now since I have two instances of the bot running in the same servers and I don't want both of them to respond. --- .../wtf/beatrice/hidekobot/Configuration.java | 4 ++++ .../hidekobot/listeners/MessageListener.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/wtf/beatrice/hidekobot/Configuration.java b/src/main/java/wtf/beatrice/hidekobot/Configuration.java index a3525f6..7107efe 100644 --- a/src/main/java/wtf/beatrice/hidekobot/Configuration.java +++ b/src/main/java/wtf/beatrice/hidekobot/Configuration.java @@ -5,6 +5,7 @@ public class Configuration private static boolean verbose = false; + private static boolean paused = false; public static boolean isVerbose() { return verbose; } @@ -12,4 +13,7 @@ public class Configuration // WARNING: verbosity spams the logs a LOT! public static void setVerbose(boolean v) { verbose = v; } + public static boolean isPaused() { return paused; } + public static void setPaused(boolean p) { paused = p; } + } diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java index eba403b..8451318 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageListener.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; +import wtf.beatrice.hidekobot.Configuration; import wtf.beatrice.hidekobot.HidekoBot; import wtf.beatrice.hidekobot.utils.Logger; import wtf.beatrice.hidekobot.utils.RandomUtil; @@ -23,6 +24,21 @@ public class MessageListener extends ListenerAdapter { String eventMessage = event.getMessage().getContentDisplay(); + + if(eventMessage.equalsIgnoreCase("hideko pause")) + { + MessageChannel channel = event.getChannel(); + + boolean paused = Configuration.isPaused(); + String msg = paused ? ":white_check_mark: Resuming normal activity!" : ":pause_button: Pausing!"; + Configuration.setPaused(!paused); + channel.sendMessage(msg).queue(); + + return; + } + + if(Configuration.isPaused()) return; + if(eventMessage.equalsIgnoreCase("hideko")) { MessageChannel channel = event.getChannel();