Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server suggestion setup fails for a message without text #1198

Open
SquidXTV opened this issue Nov 11, 2024 · 0 comments
Open

Server suggestion setup fails for a message without text #1198

SquidXTV opened this issue Nov 11, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@SquidXTV
Copy link
Member

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

  1. Post a new message without text. (only an image for example)
  2. 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?

@SquidXTV SquidXTV added bug Something isn't working good first issue Good for newcomers labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant