Skip to content

Commit

Permalink
Prevent trying to kick the user multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jul 16, 2024
1 parent fd3cabf commit 983ee2a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@

public class AutoModHandler extends ListenerAdapter {
private final Cache<Long, Integer> executionCache;
private final Cache<Long, Boolean> kickCache;

public AutoModHandler() {
this.executionCache = CacheBuilder.newBuilder()
.expireAfterWrite(5, TimeUnit.MINUTES)
.build();
this.kickCache = CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.SECONDS)
.build();
}

@Override
Expand All @@ -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;

Expand Down

0 comments on commit 983ee2a

Please sign in to comment.