diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpTitleCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpTitleCommand.java index a94471c103..14a6d0cb5b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpTitleCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpTitleCommand.java @@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; import net.dv8tion.jda.api.entities.ThreadChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.commands.SlashCommandAdapter; @@ -15,6 +16,9 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; +import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MAX; +import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MIN; + /** * Implements the {@code /change-help-title} command, which is able to change the title of a help * thread. @@ -54,7 +58,7 @@ public ChangeHelpTitleCommand(@NotNull HelpSystemHelper helper) { public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) { String title = event.getOption(TITLE_OPTION).getAsString(); - if (!helper.handleIsHelpThread(event)) { + if (!helper.handleIsHelpThread(event) || !handleIsValidTitle(title, event)) { return; } @@ -88,4 +92,18 @@ private boolean isHelpThreadOnCooldown(@NotNull ThreadChannel helpThread) { .filter(Instant.now()::isBefore) .isPresent(); } + + private boolean handleIsValidTitle(@NotNull CharSequence title, @NotNull IReplyCallback event) { + if (HelpSystemHelper.isTitleValid(title)) { + return true; + } + + event.reply( + "Sorry, but the title length (after removal of special characters) has to be between %d and %d." + .formatted(TITLE_COMPACT_LENGTH_MIN, TITLE_COMPACT_LENGTH_MAX)) + .setEphemeral(true) + .queue(); + + return false; + } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java index b7f5e77f1a..c6bbd74544 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpSystemHelper.java @@ -36,7 +36,7 @@ public final class HelpSystemHelper { private static final Pattern TITLE_COMPACT_REMOVAL_PATTERN = Pattern.compile("\\W"); static final int TITLE_COMPACT_LENGTH_MIN = 2; - static final int TITLE_COMPACT_LENGTH_MAX = 80; + static final int TITLE_COMPACT_LENGTH_MAX = 70; private final Predicate isOverviewChannelName; private final String overviewChannelPattern;