11package net .discordjug .javabot .systems .help ;
22
3+ import java .nio .charset .StandardCharsets ;
34import java .time .OffsetDateTime ;
45import java .util .ArrayList ;
56import java .util .List ;
7+ import java .util .stream .Collectors ;
68
79import org .springframework .scheduling .annotation .Scheduled ;
810import org .springframework .stereotype .Service ;
1517import net .dv8tion .jda .api .entities .Message ;
1618import net .dv8tion .jda .api .entities .MessageHistory ;
1719import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
20+ import net .dv8tion .jda .api .utils .FileUpload ;
1821
1922/**
2023 * Automatically delete old help notifications.
@@ -46,6 +49,16 @@ private void deleteOldMessagesInChannel(TextChannel helpNotificationChannel, Mes
4649 if (deleteMore ) {
4750 deleteOldMessagesInChannel (helpNotificationChannel , history , foundSoFar );
4851 }else {
52+ if (foundSoFar .size () > 50 ) {
53+ String messageInfo = foundSoFar
54+ .stream ()
55+ .map (msg -> convertMessageToString (msg ))
56+ .collect (Collectors .joining ("\n \n ===============\n \n " ));
57+ botConfig .get (helpNotificationChannel .getGuild ()).getModerationConfig ().getLogChannel ()
58+ .sendMessageFormat ("Warning: deleting %d messages in help notification channel, this might be due to help notification spam" , foundSoFar .size ())
59+ .addFiles (FileUpload .fromData (messageInfo .getBytes (StandardCharsets .UTF_8 ), "messages.txt" ))
60+ .queue ();
61+ }
4962 helpNotificationChannel .purgeMessages (foundSoFar );
5063 }
5164 }, e -> {
@@ -54,6 +67,11 @@ private void deleteOldMessagesInChannel(TextChannel helpNotificationChannel, Mes
5467 });
5568 }
5669
70+ private String convertMessageToString (Message msg ) {
71+ return msg .getContentRaw ()+"\n " +
72+ msg .getEmbeds ().stream ().map (e ->e .toData ().toString ()).collect (Collectors .joining ("\n " ));
73+ }
74+
5775 private boolean addMessagesToDelete (List <Message > toDelete , List <Message > msgs ) {
5876 for (Message message : msgs ) {
5977 if (message .getAuthor ().getIdLong () == message .getJDA ().getSelfUser ().getIdLong () &&
0 commit comments