diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java b/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java index e3d7b5b29a..280f32599e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/basic/SuggestionsUpDownVoter.java @@ -22,6 +22,7 @@ */ public final class SuggestionsUpDownVoter extends MessageReceiverAdapter { private static final Logger logger = LoggerFactory.getLogger(SuggestionsUpDownVoter.class); + private static final int TITLE_MAX_LENGTH = 60; private static final String FALLBACK_UP_VOTE = "👍"; private static final String FALLBACK_DOWN_VOTE = "👎"; @@ -47,10 +48,27 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { Guild guild = event.getGuild(); 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(@NotNull Message message) { + String title = message.getContentRaw(); + + if (title.length() >= TITLE_MAX_LENGTH) { + int lastWordEnd = title.lastIndexOf(' ', TITLE_MAX_LENGTH); + + if (lastWordEnd == -1) { + lastWordEnd = TITLE_MAX_LENGTH; + } + + title = title.substring(0, lastWordEnd); + } + + message.createThreadChannel(title).queue(); + } + private static void reactWith(@NotNull String emoteName, @NotNull String fallbackUnicodeEmote, @NotNull Guild guild, @NotNull Message message) { getEmoteByName(emoteName, guild).map(message::addReaction).orElseGet(() -> {