44import lombok .extern .slf4j .Slf4j ;
55import net .dv8tion .jda .api .JDA ;
66import net .dv8tion .jda .api .entities .Guild ;
7+ import net .dv8tion .jda .api .entities .Message ;
78import net .dv8tion .jda .api .entities .channel .concrete .ForumChannel ;
89import net .dv8tion .jda .api .entities .channel .concrete .ThreadChannel ;
910import net .javadiscord .javabot .data .config .BotConfig ;
@@ -47,7 +48,7 @@ public void execute() {
4748 private void checkForumPost (@ NotNull ThreadChannel post , HelpConfig config ) {
4849 post .retrieveMessageById (post .getLatestMessageId ()).queue (latest -> {
4950 long minutesAgo = (Instant .now ().getEpochSecond () - latest .getTimeCreated ().toEpochSecond ()) / 60 ;
50- if (minutesAgo > config .getInactivityTimeoutMinutes ()) {
51+ if (minutesAgo > config .getInactivityTimeoutMinutes () || isThanksMessage ( latest ) && minutesAgo > config . getRemoveThanksTimeoutMinutes () ) {
5152 post .sendMessage (config .getDormantChannelMessageTemplate ().formatted (config .getInactivityTimeoutMinutes ())).queue (s -> {
5253 post .getManager ().setLocked (true ).setArchived (true ).queue ();
5354 log .info ("Archived & locked forum thread '{}' (by {}) for inactivity (last message sent {} minutes ago)" ,
@@ -56,4 +57,13 @@ private void checkForumPost(@NotNull ThreadChannel post, HelpConfig config) {
5657 }
5758 }, e -> log .error ("Could not find message with id {}" , post .getLatestMessageId ()));
5859 }
60+
61+ private boolean isThanksMessage (@ NotNull Message m ) {
62+ if (m .getAuthor ().isBot () && !m .getButtons ().isEmpty () &&
63+ m .getButtons ().stream ().allMatch (b -> b .getId () != null && b .getId ().contains (HelpManager .HELP_THANKS_IDENTIFIER ))) {
64+ m .delete ().queue ();
65+ return true ;
66+ }
67+ return false ;
68+ }
5969}
0 commit comments