From 74b30f9f167836180f7c9dfe917061ada7df8b14 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 28 Aug 2023 09:27:52 -0700 Subject: [PATCH] Timeout member for 30 seconds if doing unnecessary ping --- .../java/us/ajg0702/bots/ajsupport/MessageListener.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/us/ajg0702/bots/ajsupport/MessageListener.java b/src/main/java/us/ajg0702/bots/ajsupport/MessageListener.java index 1b16eed..8fad1c0 100644 --- a/src/main/java/us/ajg0702/bots/ajsupport/MessageListener.java +++ b/src/main/java/us/ajg0702/bots/ajsupport/MessageListener.java @@ -22,6 +22,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -130,12 +131,14 @@ public void onMessageReceived(@NotNull MessageReceivedEvent e) { "In the future, please be patient and wait for a response.") .queue(); } + e.getMember().timeoutFor(Duration.ofSeconds(30)).queue(); } if(hasRole(mentionedMember, 615721804585107477L) && e.getMessage().getMessageReference() == null) { Long last = lastAjMentionWarns.getOrDefault(e.getChannel().getIdLong(), 0L); lastAjMentionWarns.put(e.getChannel().getIdLong(), System.currentTimeMillis()); - if(System.currentTimeMillis() - last > 15000) { + long distanceSinceLast = System.currentTimeMillis() - last; + if(distanceSinceLast > 15000) { e.getMessage().reply( "Please don't ping aj!\n" + "\naj has all notifications on, so he will see your message without you needing to ping him.\n" + @@ -144,6 +147,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent e) { "In the future, please be patient and wait for a response. (without pinging)") .queue(); } + e.getMember().timeoutFor(Duration.ofSeconds(30)).queue(); } } }