Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> isOverviewChannelName;
private final String overviewChannelPattern;
Expand Down