Open
Description
Describe the bug
The bot automatically sets up the up/down votes and a thread to discuss a suggestion.
It fails to do so if someone creates a new post in #server-suggestions
without text.
For example: https://discord.com/channels/272761734820003841/480829495486447627/1305554470364643442
Expected behavior
It shouldn't fail, even for posts without text.
To Reproduce
- Post a new message without text. (only an image for example)
- See the error
Additional context
One of the EventListeners had an uncaught exception java.lang.IllegalArgumentException: Name may not be empty
at net.dv8tion.jda.internal.utils.Checks.notEmpty(Checks.java:94)
at net.dv8tion.jda.internal.entities.channel.mixin.attribute.IThreadContainerMixin.createThreadChannel(IThreadContainerMixin.java:69)
at net.dv8tion.jda.internal.entities.ReceivedMessage.createThreadChannel(ReceivedMessage.java:946)
at org.togetherjava.tjbot.features.basic.SuggestionsUpDownVoter.createThread(SuggestionsUpDownVoter.java:70)
at org.togetherjava.tjbot.features.basic.SuggestionsUpDownVoter.onMessageReceived(SuggestionsUpDownVoter.java:52)
at org.togetherjava.tjbot.features.system.BotCore.lambda$onMessageReceived$9(BotCore.java:221)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.jav...
The bot tries to create a new thread and set the title of that thread using the text of the post:
private static void createThread(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();
}
It is missing checks if the text is empty.
What kind of default title would make sense?