Skip to content

Commit 6d6abbc

Browse files
committed
delete messages quicker
1 parent 8e025ff commit 6d6abbc

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/main/java/net/discordjug/javabot/systems/help/commands/notify/ClearOldHelpNotificationJob.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ public void execute() {
4545

4646
private void deleteOldMessagesInChannel(TextChannel helpNotificationChannel, MessageHistory history, List<Message> foundSoFar) {
4747
history.retrievePast(50).queue(msgs -> {
48-
foundSoFar.addAll(
49-
msgs
48+
List<Message> toDelete = msgs
49+
.stream()
50+
.filter(msg -> msg.getAuthor().getIdLong() == msg.getJDA().getSelfUser().getIdLong())
51+
.filter(msg -> msg.getTimeCreated().isBefore(OffsetDateTime.now().minusDays(3)))
52+
.filter(msg -> msg
53+
.getButtons()
5054
.stream()
51-
.filter(msg -> msg.getAuthor().getIdLong() == msg.getJDA().getSelfUser().getIdLong())
52-
.filter(msg -> msg.getTimeCreated().isBefore(OffsetDateTime.now().minusDays(3)))
53-
.filter(msg -> msg
54-
.getButtons()
55-
.stream()
56-
.anyMatch(button -> "Mark as unacknowledged".equals(button.getLabel())))
57-
.toList()
58-
);
55+
.anyMatch(button -> "Mark as unacknowledged".equals(button.getLabel())))
56+
.toList();
57+
helpNotificationChannel.purgeMessages(toDelete);
58+
foundSoFar.addAll(toDelete);
5959
if (!msgs.isEmpty()) {
6060
deleteOldMessagesInChannel(helpNotificationChannel, history, foundSoFar);
6161
}else {
@@ -69,7 +69,6 @@ private void deleteOldMessagesInChannel(TextChannel helpNotificationChannel, Mes
6969
.addFiles(FileUpload.fromData(messageInfo.getBytes(StandardCharsets.UTF_8), "messages.txt"))
7070
.queue();
7171
}
72-
helpNotificationChannel.purgeMessages(foundSoFar);
7372
}
7473
}, e -> {
7574
ExceptionLogger.capture(e, getClass().getName());

0 commit comments

Comments
 (0)