|
4 | 4 | import com.github.benmanes.caffeine.cache.Caffeine;
|
5 | 5 | import net.dv8tion.jda.api.entities.ThreadChannel;
|
6 | 6 | import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
| 7 | +import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; |
7 | 8 | import net.dv8tion.jda.api.interactions.commands.OptionType;
|
8 | 9 | import org.jetbrains.annotations.NotNull;
|
9 | 10 | import org.togetherjava.tjbot.commands.SlashCommandAdapter;
|
|
15 | 16 | import java.util.Optional;
|
16 | 17 | import java.util.concurrent.TimeUnit;
|
17 | 18 |
|
| 19 | +import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MAX; |
| 20 | +import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MIN; |
| 21 | + |
18 | 22 | /**
|
19 | 23 | * Implements the {@code /change-help-title} command, which is able to change the title of a help
|
20 | 24 | * thread.
|
@@ -54,7 +58,7 @@ public ChangeHelpTitleCommand(@NotNull HelpSystemHelper helper) {
|
54 | 58 | public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
|
55 | 59 | String title = event.getOption(TITLE_OPTION).getAsString();
|
56 | 60 |
|
57 |
| - if (!helper.handleIsHelpThread(event)) { |
| 61 | + if (!helper.handleIsHelpThread(event) || !handleIsValidTitle(title, event)) { |
58 | 62 | return;
|
59 | 63 | }
|
60 | 64 |
|
@@ -88,4 +92,18 @@ private boolean isHelpThreadOnCooldown(@NotNull ThreadChannel helpThread) {
|
88 | 92 | .filter(Instant.now()::isBefore)
|
89 | 93 | .isPresent();
|
90 | 94 | }
|
| 95 | + |
| 96 | + private boolean handleIsValidTitle(@NotNull CharSequence title, @NotNull IReplyCallback event) { |
| 97 | + if (HelpSystemHelper.isTitleValid(title)) { |
| 98 | + return true; |
| 99 | + } |
| 100 | + |
| 101 | + event.reply( |
| 102 | + "Sorry, but the title length (after removal of special characters) has to be between %d and %d." |
| 103 | + .formatted(TITLE_COMPACT_LENGTH_MIN, TITLE_COMPACT_LENGTH_MAX)) |
| 104 | + .setEphemeral(true) |
| 105 | + .queue(); |
| 106 | + |
| 107 | + return false; |
| 108 | + } |
91 | 109 | }
|
0 commit comments