File tree Expand file tree Collapse file tree 1 file changed +8
-19
lines changed
src/main/java/net/discordjug/javabot/systems/help Expand file tree Collapse file tree 1 file changed +8
-19
lines changed Original file line number Diff line number Diff line change @@ -45,8 +45,14 @@ public void execute() {
4545
4646 private void deleteOldMessagesInChannel (TextChannel helpNotificationChannel , MessageHistory history , List <Message > foundSoFar ) {
4747 history .retrievePast (50 ).queue (msgs -> {
48- boolean deleteMore = addMessagesToDelete (foundSoFar , msgs );
49- if (deleteMore ) {
48+ foundSoFar .addAll (
49+ msgs
50+ .stream ()
51+ .filter (msg -> msg .getAuthor ().getIdLong () == msg .getJDA ().getSelfUser ().getIdLong ())
52+ .filter (msg -> msg .getTimeCreated ().isBefore (OffsetDateTime .now ().minusDays (5 )))
53+ .toList ()
54+ );
55+ if (!msgs .isEmpty ()) {
5056 deleteOldMessagesInChannel (helpNotificationChannel , history , foundSoFar );
5157 }else {
5258 if (foundSoFar .size () > 50 ) {
@@ -71,21 +77,4 @@ private String convertMessageToString(Message msg) {
7177 return msg .getContentRaw ()+"\n " +
7278 msg .getEmbeds ().stream ().map (e ->e .toData ().toString ()).collect (Collectors .joining ("\n " ));
7379 }
74-
75- private boolean addMessagesToDelete (List <Message > toDelete , List <Message > msgs ) {
76- for (Message message : msgs ) {
77- if (message .getAuthor ().getIdLong () == message .getJDA ().getSelfUser ().getIdLong () &&
78- //only delete messages older than 5 days
79- message .getTimeCreated ().isBefore (OffsetDateTime .now ().minusDays (5 ))) {
80-
81- //only messages sent within the past two weeks can be deleted
82- //stop when messages near that are found
83- if (message .getTimeCreated ().isBefore (OffsetDateTime .now ().minusDays (13 ))) {
84- return false ;
85- }
86- toDelete .add (message );
87- }
88- }
89- return true ;
90- }
9180}
You can’t perform that action at this time.
0 commit comments