Skip to content

Commit a1cd65a

Browse files
committed
fix: Handle empty message content for thread titles
Ensures a fallback thread title is provided when the original message content is empty. The thread title will now default to the message author's name in such cases, preventing empty or uninformative thread titles.
1 parent 8b2d3c5 commit a1cd65a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,26 @@ public void onMessageReceived(MessageReceivedEvent event) {
5555
}
5656

5757
private static void createThread(Message message) {
58-
String title = message.getContentRaw();
5958

60-
if (title.length() >= TITLE_MAX_LENGTH) {
61-
int lastWordEnd = title.lastIndexOf(' ', TITLE_MAX_LENGTH);
59+
String threadTitle;
60+
String messageContent = message.getContentRaw();
61+
62+
if (messageContent.isEmpty()){
63+
threadTitle = message.getAuthor().getName();
64+
} else if (messageContent.length() >= TITLE_MAX_LENGTH) {
65+
int lastWordEnd = messageContent.lastIndexOf(' ', TITLE_MAX_LENGTH);
6266

6367
if (lastWordEnd == -1) {
6468
lastWordEnd = TITLE_MAX_LENGTH;
6569
}
6670

67-
title = title.substring(0, lastWordEnd);
71+
threadTitle = messageContent.substring(0, lastWordEnd);
72+
} else {
73+
74+
threadTitle = messageContent;
6875
}
6976

70-
message.createThreadChannel(title).queue();
77+
message.createThreadChannel(threadTitle).queue();
7178
}
7279

7380
private static void reactWith(String emojiName, Emoji fallbackEmoji, Guild guild,

0 commit comments

Comments
 (0)