3333import java .util .ArrayList ;
3434import java .util .HashMap ;
3535import java .util .HashSet ;
36+ import java .util .LinkedHashMap ;
3637import java .util .List ;
3738import java .util .Map ;
3839import java .util .Set ;
@@ -66,6 +67,13 @@ public class HelpListener extends ListenerAdapter implements ButtonHandler {
6667 {"issue" ,"solv" },
6768 {"thank" }
6869 };
70+ private final long SUGGEST_CLOSE_TIMEOUT = 5 * 60_000L ;//5 minutes
71+ private final Map <Long , Long > recentlyCloseSuggestedPosts = new LinkedHashMap <>(8 , 0.75f , true ) {
72+ @ Override
73+ protected boolean removeEldestEntry (Map .Entry <Long , Long > eldest ) {
74+ return System .currentTimeMillis () > eldest .getValue () || size () >= 32 ;
75+ }
76+ };
6977
7078 @ Override
7179 public void onMessageReceived (@ NotNull MessageReceivedEvent event ) {
@@ -109,6 +117,10 @@ private void replyCloseSuggestionIfPatternMatches(Message msg) {
109117 if (content .contains ("```" )) {
110118 return ;
111119 }
120+ long postId = msg .getChannel ().getIdLong ();
121+ if (recentlyCloseSuggestedPosts .containsKey (postId ) && recentlyCloseSuggestedPosts .get (postId ) > System .currentTimeMillis ()) {
122+ return ;
123+ }
112124 if (msg .getChannel ().asThreadChannel ().getOwnerIdLong () == msg .getAuthor ().getIdLong ()) {
113125 for (String [] detector : closeSuggestionDetectors ) {
114126 if (doesMatchDetector (content , detector )) {
@@ -120,6 +132,7 @@ private void replyCloseSuggestionIfPatternMatches(Message msg) {
120132 .addActionRow (createCloseSuggestionButton (msg .getChannel ().asThreadChannel ()),
121133 Button .secondary (InteractionUtils .DELETE_ORIGINAL_TEMPLATE , "\uD83D \uDDD1 ️" ))
122134 .queue ();
135+ recentlyCloseSuggestedPosts .put (postId , System .currentTimeMillis () + SUGGEST_CLOSE_TIMEOUT );
123136 }
124137 }
125138 }
0 commit comments