Skip to content

Commit 5c79afb

Browse files
authored
Merge pull request #435 from danthe1st/fix-duplicate-close-suggestions
fix duplicate close suggestions when multiple detectors match
2 parents 4360c28 + 165d216 commit 5c79afb

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/main/java/net/javadiscord/javabot/systems/help/HelpListener.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,29 +155,36 @@ private void replyCloseSuggestionIfPatternMatches(Message msg) {
155155
return;
156156
}
157157
if (msg.getChannel().asThreadChannel().getOwnerIdLong() == msg.getAuthor().getIdLong()) {
158-
for (String[] detector : closeSuggestionDetectors) {
159-
if (doesMatchDetector(content, detector)) {
160-
msg.reply("""
158+
if(matchesAnyDetector(content)) {
159+
msg.reply("""
161160
If you are finished with your post, please close it.
162161
If you are not, please ignore this message.
163162
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
164163
""")
165-
.addActionRow(
166-
createCloseSuggestionButton(msg.getChannel()
167-
.asThreadChannel()),
168-
Button.secondary(
169-
InteractionUtils.DELETE_ORIGINAL_TEMPLATE,
170-
"\uD83D\uDDD1️"
171-
)
172-
)
173-
.queue();
174-
recentlyCloseSuggestedPosts.put(
175-
postId,
176-
System.currentTimeMillis() + SUGGEST_CLOSE_TIMEOUT
177-
);
178-
}
164+
.addActionRow(
165+
createCloseSuggestionButton(msg.getChannel()
166+
.asThreadChannel()),
167+
Button.secondary(
168+
InteractionUtils.DELETE_ORIGINAL_TEMPLATE,
169+
"\uD83D\uDDD1️"
170+
)
171+
)
172+
.queue();
173+
recentlyCloseSuggestedPosts.put(
174+
postId,
175+
System.currentTimeMillis() + SUGGEST_CLOSE_TIMEOUT
176+
);
177+
}
178+
}
179+
}
180+
181+
private boolean matchesAnyDetector(String content) {
182+
for (String[] detector : closeSuggestionDetectors) {
183+
if (doesMatchDetector(content, detector)) {
184+
return true;
179185
}
180186
}
187+
return false;
181188
}
182189

183190
private boolean doesMatchDetector(String content, String[] detector) {

0 commit comments

Comments
 (0)