Skip to content

Commit 7ca4496

Browse files
committed
SuggestionsUpDownVoter should have UNKNOWN_MESSAGE exception gracefully with an INFO log instead #1414
1 parent 7f63240 commit 7ca4496

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

application/src/main/java/org/togetherjava/tjbot/features/basic/SuggestionsUpDownVoter.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,23 @@ public void onMessageReceived(MessageReceivedEvent event) {
5050
Message message = event.getMessage();
5151

5252
createThread(message);
53+
5354
reactWith(config.getUpVoteEmoteName(), FALLBACK_UP_VOTE, guild, message);
5455
reactWith(config.getDownVoteEmoteName(), FALLBACK_DOWN_VOTE, guild, message);
5556
}
5657

5758
private static void createThread(Message message) {
5859
String threadTitle = generateThreadTitle(message);
59-
message.createThreadChannel(threadTitle).queue();
60+
message.createThreadChannel(threadTitle).queue(null, exception -> {
61+
if (exception instanceof ErrorResponseException responseException
62+
&& responseException.getErrorResponse() == ErrorResponse.UNKNOWN_MESSAGE) {
63+
logger.info(
64+
"Create Thread skipped: message was already deleted (likely by scamblocker) - ID: {}",
65+
message.getIdLong());
66+
return;
67+
68+
}
69+
});
6070
}
6171

6272
/**
@@ -93,13 +103,19 @@ private static void reactWith(String emojiName, Emoji fallbackEmoji, Guild guild
93103
return message.addReaction(fallbackEmoji);
94104
}).queue(ignored -> {
95105
}, exception -> {
96-
if (exception instanceof ErrorResponseException responseException
97-
&& responseException.getErrorResponse() == ErrorResponse.REACTION_BLOCKED) {
98-
// User blocked the bot, hence the bot can not add reactions to their messages.
99-
// Nothing we can do here.
100-
return;
106+
if (exception instanceof ErrorResponseException responseException) {
107+
if (responseException.getErrorResponse() == ErrorResponse.REACTION_BLOCKED) {
108+
// User blocked the bot, hence the bot can not add reactions to their messages.
109+
// Nothing we can do here.
110+
return;
111+
}
112+
if (responseException.getErrorResponse() == ErrorResponse.UNKNOWN_MESSAGE) {
113+
logger.info(
114+
"Reaction skipped: message was already deleted (likely by scamblocker) - ID: {}",
115+
message.getIdLong());
116+
return;
117+
}
101118
}
102-
103119
logger.error("Attempted to react to a suggestion, but failed", exception);
104120
});
105121
}

0 commit comments

Comments
 (0)