Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ public void onMessageReceived(MessageReceivedEvent event) {
Message message = event.getMessage();

createThread(message);

reactWith(config.getUpVoteEmoteName(), FALLBACK_UP_VOTE, guild, message);
reactWith(config.getDownVoteEmoteName(), FALLBACK_DOWN_VOTE, guild, message);
}

private static void createThread(Message message) {
String threadTitle = generateThreadTitle(message);
message.createThreadChannel(threadTitle).queue();
message.createThreadChannel(threadTitle).queue(_ -> {
}, exception -> {
if (exception instanceof ErrorResponseException responseException
&& responseException.getErrorResponse() == ErrorResponse.UNKNOWN_MESSAGE) {
logger.info("Failed to start suggestion thread: source message deleted");
return;

}
});
}

/**
Expand Down Expand Up @@ -91,19 +100,25 @@ private static void reactWith(String emojiName, Emoji fallbackEmoji, Guild guild
"Unable to vote on a suggestion with the configured emoji ('{}'), using fallback instead.",
emojiName);
return message.addReaction(fallbackEmoji);
}).queue(ignored -> {
}, exception -> {
if (exception instanceof ErrorResponseException responseException
&& responseException.getErrorResponse() == ErrorResponse.REACTION_BLOCKED) {
}).queue(_ -> {
}, SuggestionsUpDownVoter::handleReactionFailure);
}

private static void handleReactionFailure(Throwable exception) {
if (exception instanceof ErrorResponseException responseException) {
if (responseException.getErrorResponse() == ErrorResponse.REACTION_BLOCKED) {
// User blocked the bot, hence the bot can not add reactions to their messages.
// Nothing we can do here.
return;
}

logger.error("Attempted to react to a suggestion, but failed", exception);
});
if (responseException.getErrorResponse() == ErrorResponse.UNKNOWN_MESSAGE) {
logger.info("Failed to react to suggestion: source message deleted");
return;
}
}
logger.error("Attempted to react to a suggestion, but failed", exception);
}


private static Optional<RichCustomEmoji> getEmojiByName(String name, Guild guild) {
return guild.getEmojisByName(name, false).stream().findAny();
}
Expand Down
Loading