Skip to content

Commit d1848e2

Browse files
committed
use sets
1 parent 9089bd0 commit d1848e2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/net/discordjug/javabot/systems/moderation/PurgeCommand.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
import java.time.format.DateTimeFormatter;
3232
import java.util.Collections;
3333
import java.util.HashMap;
34+
import java.util.HashSet;
3435
import java.util.List;
3536
import java.util.Map;
3637
import java.util.Map.Entry;
38+
import java.util.Set;
3739
import java.util.concurrent.CompletableFuture;
38-
import java.util.concurrent.CopyOnWriteArrayList;
3940
import java.util.concurrent.ExecutorService;
4041
import java.util.concurrent.atomic.AtomicBoolean;
4142
import java.util.stream.Collectors;
@@ -48,7 +49,7 @@ public class PurgeCommand extends ModerateCommand {
4849
private static final Path ARCHIVE_DIR = Path.of("purgeArchives");
4950
private final ExecutorService asyncPool;
5051

51-
private final Map<Long, List<RunningPurge>> currentPurges = Collections.synchronizedMap(new HashMap<>());
52+
private final Map<Long, Set<RunningPurge>> currentPurges = Collections.synchronizedMap(new HashMap<>());
5253

5354
/**
5455
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
@@ -80,7 +81,7 @@ protected ReplyCallbackAction handleModerationCommand(@NotNull SlashCommandInter
8081
return Responses.warning(event, "Invalid amount. Should be between 1 and " + maxAmount + ", inclusive.");
8182
}
8283
if (amount == 0) {
83-
List<RunningPurge> purges = currentPurges.get(event.getGuild().getIdLong());
84+
Set<RunningPurge> purges = currentPurges.get(event.getGuild().getIdLong());
8485
if (purges == null) {
8586
return Responses.warning(event, "Cannot stop purge as no purge is currently running.");
8687
} else {
@@ -98,7 +99,7 @@ protected ReplyCallbackAction handleModerationCommand(@NotNull SlashCommandInter
9899
() -> this.purge(amount, user, event.getUser(), archive, event.getChannel(), config.getLogChannel(), runningPurge.cancelled()),
99100
asyncPool);
100101
currentPurges
101-
.computeIfAbsent(event.getGuild().getIdLong(), l -> new CopyOnWriteArrayList<>())
102+
.computeIfAbsent(event.getGuild().getIdLong(), l -> Collections.synchronizedSet(new HashSet<>()))
102103
.add(runningPurge);
103104
future.whenComplete((success, failure) ->
104105
currentPurges.get(event.getGuild().getIdLong())

0 commit comments

Comments
 (0)