From 983ee2abe896e6636c0c15ce4f97680924eeddba Mon Sep 17 00:00:00 2001 From: rtm516 Date: Tue, 16 Jul 2024 17:46:42 +0100 Subject: [PATCH] Prevent trying to kick the user multiple times --- .../org/geysermc/discordbot/listeners/AutoModHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/geysermc/discordbot/listeners/AutoModHandler.java b/src/main/java/org/geysermc/discordbot/listeners/AutoModHandler.java index 94f13609..61f2a6c2 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/AutoModHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/AutoModHandler.java @@ -46,11 +46,15 @@ public class AutoModHandler extends ListenerAdapter { private final Cache executionCache; + private final Cache kickCache; public AutoModHandler() { this.executionCache = CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.MINUTES) .build(); + this.kickCache = CacheBuilder.newBuilder() + .expireAfterWrite(10, TimeUnit.SECONDS) + .build(); } @Override @@ -68,6 +72,10 @@ public void onAutoModExecution(@Nonnull AutoModExecutionEvent event) { if (executions < 3) return; + // Prevent trying to kick the user multiple times + if (this.kickCache.getIfPresent(userId) != null) return; + this.kickCache.put(userId, true); + Member member = event.getGuild().getMemberById(userId); if (member == null) return;