diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Features.java b/application/src/main/java/org/togetherjava/tjbot/commands/Features.java index 02603d25ba..f05b626572 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Features.java @@ -125,9 +125,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new WhoIsCommand()); features.add(new WolframAlphaCommand(config)); features.add(new AskCommand(config, helpSystemHelper)); - features.add(new CloseCommand()); - features.add(new ChangeHelpCategoryCommand(config, helpSystemHelper)); - features.add(new ChangeHelpTitleCommand(helpSystemHelper)); + features.add(new HelpThreadCommand(config, helpSystemHelper)); // Mixtures features.add(new HelpThreadOverviewUpdater(config, helpSystemHelper)); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpCategoryCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpCategoryCommand.java deleted file mode 100644 index 9235ba053d..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpCategoryCommand.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.togetherjava.tjbot.commands.help; - -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.ThreadChannel; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.interactions.InteractionHook; -import net.dv8tion.jda.api.interactions.commands.OptionType; -import net.dv8tion.jda.api.interactions.commands.build.OptionData; -import net.dv8tion.jda.api.requests.RestAction; -import org.togetherjava.tjbot.commands.CommandVisibility; -import org.togetherjava.tjbot.commands.SlashCommandAdapter; -import org.togetherjava.tjbot.config.Config; - -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Locale; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -/** - * Implements the {@code /change-help-category} command, which is able to change the category of a - * help thread. - *

- * This is either used for threads that do not have categories yet (as created by - * {@link ImplicitAskListener}), or simply to adjust the category afterwards. - *

- * Changing the category will invite all helpers interested into the corresponding category to the - * question thread. - */ -public final class ChangeHelpCategoryCommand extends SlashCommandAdapter { - private static final String CATEGORY_OPTION = "category"; - - private static final int COOLDOWN_DURATION_VALUE = 30; - private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.MINUTES; - - private final HelpSystemHelper helper; - private final Cache helpThreadIdToLastCategoryChange; - - /** - * Creates a new instance. - * - * @param config the config to use - * @param helper the helper to use - */ - public ChangeHelpCategoryCommand(Config config, HelpSystemHelper helper) { - super("change-help-category", "changes the category of a help thread", - CommandVisibility.GUILD); - - OptionData category = new OptionData(OptionType.STRING, CATEGORY_OPTION, - "select what describes the question the best", true); - config.getHelpSystem() - .getCategories() - .forEach(categoryText -> category.addChoice(categoryText, categoryText)); - - getData().addOptions(category); - - helpThreadIdToLastCategoryChange = Caffeine.newBuilder() - .maximumSize(1_000) - .expireAfterAccess(COOLDOWN_DURATION_VALUE, TimeUnit.of(COOLDOWN_DURATION_UNIT)) - .build(); - - this.helper = helper; - } - - @Override - public void onSlashCommand(SlashCommandInteractionEvent event) { - String category = event.getOption(CATEGORY_OPTION).getAsString(); - - ThreadChannel helpThread = event.getThreadChannel(); - if (helpThread.isArchived()) { - event.reply("This thread is already closed.").setEphemeral(true).queue(); - return; - } - - if (isHelpThreadOnCooldown(helpThread)) { - event - .reply("Please wait a bit, this command can only be used once per %d %s.".formatted( - COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT.toString().toLowerCase(Locale.US))) - .setEphemeral(true) - .queue(); - return; - } - helpThreadIdToLastCategoryChange.put(helpThread.getIdLong(), Instant.now()); - - event.deferReply().queue(); - - helper.renameChannelToCategory(helpThread, category) - .flatMap(any -> sendCategoryChangedMessage(helpThread.getGuild(), event.getHook(), - helpThread, category)) - .queue(); - } - - private RestAction sendCategoryChangedMessage(Guild guild, InteractionHook hook, - ThreadChannel helpThread, String category) { - String changedContent = "Changed the category to **%s**.".formatted(category); - var action = hook.editOriginal(changedContent); - - Optional helperRole = helper.handleFindRoleForCategory(category, guild); - if (helperRole.isEmpty()) { - return action; - } - - // We want to invite all members of a role, but without hard-pinging them. However, - // manually inviting them is cumbersome and can hit rate limits. - // Instead, we abuse the fact that a role-ping through an edit will not hard-ping users, - // but still invite them to a thread. - String headsUpPattern = "%splease have a look, thanks."; - String headsUpWithoutRole = headsUpPattern.formatted(""); - String headsUpWithRole = - headsUpPattern.formatted(helperRole.orElseThrow().getAsMention() + " "); - return action.flatMap(any -> helpThread.sendMessage(headsUpWithoutRole) - .flatMap(message -> message.editMessage(headsUpWithRole))); - } - - private boolean isHelpThreadOnCooldown(ThreadChannel helpThread) { - return Optional - .ofNullable(helpThreadIdToLastCategoryChange.getIfPresent(helpThread.getIdLong())) - .map(lastCategoryChange -> lastCategoryChange.plus(COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT)) - .filter(Instant.now()::isBefore) - .isPresent(); - } -} 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 deleted file mode 100644 index 1510d54f2b..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/ChangeHelpTitleCommand.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.togetherjava.tjbot.commands.help; - -import com.github.benmanes.caffeine.cache.Cache; -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.togetherjava.tjbot.commands.CommandVisibility; -import org.togetherjava.tjbot.commands.SlashCommandAdapter; - -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Locale; -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. - *

- * This is to adjust a bad title in hindsight, for example if it was automatically created by - * {@link ImplicitAskListener}. - */ -public final class ChangeHelpTitleCommand extends SlashCommandAdapter { - private static final String TITLE_OPTION = "title"; - - private static final int COOLDOWN_DURATION_VALUE = 30; - private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.MINUTES; - - private final HelpSystemHelper helper; - private final Cache helpThreadIdToLastTitleChange; - - /** - * Creates a new instance. - * - * @param helper the helper to use - */ - public ChangeHelpTitleCommand(HelpSystemHelper helper) { - super("change-help-title", "changes the title of a help thread", CommandVisibility.GUILD); - - getData().addOption(OptionType.STRING, TITLE_OPTION, "short and to the point", true); - - helpThreadIdToLastTitleChange = Caffeine.newBuilder() - .maximumSize(1_000) - .expireAfterAccess(COOLDOWN_DURATION_VALUE, TimeUnit.of(COOLDOWN_DURATION_UNIT)) - .build(); - - this.helper = helper; - } - - @Override - public void onSlashCommand(SlashCommandInteractionEvent event) { - String title = event.getOption(TITLE_OPTION).getAsString(); - - if (!handleIsValidTitle(title, event)) { - return; - } - - ThreadChannel helpThread = event.getThreadChannel(); - if (helpThread.isArchived()) { - event.reply("This thread is already closed.").setEphemeral(true).queue(); - return; - } - - if (isHelpThreadOnCooldown(helpThread)) { - event - .reply("Please wait a bit, this command can only be used once per %d %s.".formatted( - COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT.toString().toLowerCase(Locale.US))) - .setEphemeral(true) - .queue(); - return; - } - helpThreadIdToLastTitleChange.put(helpThread.getIdLong(), Instant.now()); - - helper.renameChannelToTitle(helpThread, title) - .flatMap(any -> event.reply("Changed the title to **%s**.".formatted(title))) - .queue(); - } - - private boolean isHelpThreadOnCooldown(ThreadChannel helpThread) { - return Optional - .ofNullable(helpThreadIdToLastTitleChange.getIfPresent(helpThread.getIdLong())) - .map(lastCategoryChange -> lastCategoryChange.plus(COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT)) - .filter(Instant.now()::isBefore) - .isPresent(); - } - - private boolean handleIsValidTitle(CharSequence title, 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/CloseCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/CloseCommand.java deleted file mode 100644 index c50b14d1a7..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/CloseCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.togetherjava.tjbot.commands.help; - -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.entities.ThreadChannel; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import org.togetherjava.tjbot.commands.CommandVisibility; -import org.togetherjava.tjbot.commands.SlashCommandAdapter; - -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Locale; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -/** - * Implements the {@code /close} command to close question threads. - *

- * Can be used in active (non-archived) question threads. Will close, i.e. archive, the thread upon - * use. Meant to be used once a question has been resolved. - */ -public final class CloseCommand extends SlashCommandAdapter { - private static final int COOLDOWN_DURATION_VALUE = 30; - private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.MINUTES; - - private final Cache helpThreadIdToLastClose; - - /** - * Creates a new instance. - */ - public CloseCommand() { - super("close", "Close this question thread", CommandVisibility.GUILD); - - helpThreadIdToLastClose = Caffeine.newBuilder() - .maximumSize(1_000) - .expireAfterAccess(COOLDOWN_DURATION_VALUE, TimeUnit.of(COOLDOWN_DURATION_UNIT)) - .build(); - } - - @Override - public void onSlashCommand(SlashCommandInteractionEvent event) { - ThreadChannel helpThread = event.getThreadChannel(); - if (helpThread.isArchived()) { - event.reply("This thread is already closed.").setEphemeral(true).queue(); - return; - } - - if (isHelpThreadOnCooldown(helpThread)) { - event - .reply("Please wait a bit, this command can only be used once per %d %s.".formatted( - COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT.toString().toLowerCase(Locale.US))) - .setEphemeral(true) - .queue(); - return; - } - helpThreadIdToLastClose.put(helpThread.getIdLong(), Instant.now()); - - MessageEmbed embed = new EmbedBuilder().setDescription("Closed the thread.") - .setColor(HelpSystemHelper.AMBIENT_COLOR) - .build(); - - event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); - } - - private boolean isHelpThreadOnCooldown(ThreadChannel helpThread) { - return Optional.ofNullable(helpThreadIdToLastClose.getIfPresent(helpThread.getIdLong())) - .map(lastCategoryChange -> lastCategoryChange.plus(COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT)) - .filter(Instant.now()::isBefore) - .isPresent(); - } -} 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 81261f921b..59f4a54a25 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 @@ -108,7 +108,7 @@ RestAction sendExplanationMessage(MessageChannel threadChannel) { **provide details**, context, more code, examples and maybe some screenshots. \ With enough info, someone knows the answer for sure."""), HelpSystemHelper.embedWith( - "Don't forget to close your thread using the command **/close** when your question has been answered, thanks.")); + "Don't forget to close your thread using the command **/help-thread close** when your question has been answered, thanks.")); MessageAction action = threadChannel.sendMessage(message); if (useCodeSyntaxExampleImage) { @@ -293,7 +293,7 @@ private void executeUncategorizedAdviceCheck(long threadChannelId, long authorId MessageEmbed embed = HelpSystemHelper.embedWith( """ Hey there 👋 You have to select a category for your help thread, otherwise nobody can see your question. - Please use the `/change-help-category` slash-command and pick what fits best, thanks 🙂 + Please use the `/help-thread change category` slash-command and pick what fits best, thanks 🙂 """); Message message = new MessageBuilder(author.getAsMention()).setEmbeds(embed).build(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java new file mode 100644 index 0000000000..04c9b78cb5 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java @@ -0,0 +1,244 @@ +package org.togetherjava.tjbot.commands.help; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.InteractionHook; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; +import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.WebhookMessageUpdateAction; +import org.togetherjava.tjbot.commands.CommandVisibility; +import org.togetherjava.tjbot.commands.SlashCommandAdapter; +import org.togetherjava.tjbot.config.Config; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +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 /help-thread} command, which are contains special command for help threads + * only + */ +public final class HelpThreadCommand extends SlashCommandAdapter { + private static final int COOLDOWN_DURATION_VALUE = 30; + private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.MINUTES; + private static final String CHANGE_CATEGORY_SUBCOMMAND = "category"; + private static final String CHANGE_CATEGORY_OPTION = "category"; + private static final String CHANGE_TITLE_OPTION = "title"; + private static final String CHANGE_TITLE_SUBCOMMAND = "title"; + + private final HelpSystemHelper helper; + private final Map nameToSubcommand; + private final Map> subcommandToCooldownCache; + private final Map> subcommandToEventHandler; + + /** + * Creates a new instance. + * + * @param config the config to use + * @param helper the helper to use + */ + public HelpThreadCommand(Config config, HelpSystemHelper helper) { + super("help-thread", "Help thread specific commands", CommandVisibility.GUILD); + + OptionData categoryChoices = + new OptionData(OptionType.STRING, CHANGE_CATEGORY_OPTION, "new category", true); + config.getHelpSystem() + .getCategories() + .forEach(categoryText -> categoryChoices.addChoice(categoryText, categoryText)); + + SubcommandData changeCategory = + Subcommand.CHANGE_CATEGORY.toSubcommandData().addOptions(categoryChoices); + + SubcommandData changeTitle = Subcommand.CHANGE_TITLE.toSubcommandData() + .addOption(OptionType.STRING, CHANGE_TITLE_OPTION, "new title", true); + + SubcommandGroupData changeCommands = + new SubcommandGroupData("change", "Change the details of this help thread") + .addSubcommands(changeCategory, changeTitle); + getData().addSubcommandGroups(changeCommands); + + getData().addSubcommands(Subcommand.CLOSE.toSubcommandData()); + + this.helper = helper; + + Supplier> createCooldownCache = () -> Caffeine.newBuilder() + .maximumSize(1_000) + .expireAfterAccess(COOLDOWN_DURATION_VALUE, TimeUnit.of(COOLDOWN_DURATION_UNIT)) + .build(); + nameToSubcommand = streamSubcommands() + .collect(Collectors.toMap(Subcommand::getCommandName, Function.identity())); + subcommandToCooldownCache = new EnumMap<>(streamSubcommands() + .filter(Subcommand::hasCooldown) + .collect(Collectors.toMap(Function.identity(), any -> createCooldownCache.get()))); + subcommandToEventHandler = new EnumMap<>( + Map.of(Subcommand.CHANGE_CATEGORY, this::changeCategory, Subcommand.CHANGE_TITLE, + this::changeTitle, Subcommand.CLOSE, this::closeThread)); + } + + @Override + public void onSlashCommand(SlashCommandInteractionEvent event) { + ThreadChannel helpThread = event.getThreadChannel(); + + Subcommand invokedSubcommand = + Objects.requireNonNull(nameToSubcommand.get(event.getSubcommandName())); + + if (invokedSubcommand.hasCooldown() + && isHelpThreadOnCooldown(invokedSubcommand, helpThread)) { + sendCooldownMessage(event); + return; + } + + subcommandToEventHandler.get(invokedSubcommand).accept(event, helpThread); + } + + private boolean isHelpThreadOnCooldown(Subcommand subcommand, ThreadChannel helpThread) { + Cache helpThreadIdToLastAction = requireCooldownCache(subcommand); + return Optional.ofNullable(helpThreadIdToLastAction.getIfPresent(helpThread.getIdLong())) + .map(lastAction -> lastAction.plus(COOLDOWN_DURATION_VALUE, COOLDOWN_DURATION_UNIT)) + .filter(Instant.now()::isBefore) + .isPresent(); + } + + private Cache requireCooldownCache(Subcommand subcommand) { + if (!subcommand.hasCooldown()) { + throw new IllegalArgumentException( + "Must only be used with subcommands that do have cooldown, but " + subcommand + + " was given."); + } + + return subcommandToCooldownCache.get(subcommand); + } + + private void sendCooldownMessage(SlashCommandInteractionEvent event) { + event + .reply("Please wait a bit, this command can only be used once per %d %s.".formatted( + COOLDOWN_DURATION_VALUE, + COOLDOWN_DURATION_UNIT.toString().toLowerCase(Locale.US))) + .setEphemeral(true) + .queue(); + } + + private void changeCategory(SlashCommandInteractionEvent event, ThreadChannel helpThread) { + String category = event.getOption(CHANGE_CATEGORY_OPTION).getAsString(); + + event.deferReply().queue(); + refreshCooldownFor(Subcommand.CHANGE_CATEGORY, helpThread); + + helper.renameChannelToCategory(helpThread, category) + .flatMap(any -> sendCategoryChangedMessage(helpThread.getGuild(), event.getHook(), + helpThread, category)) + .queue(); + } + + private void refreshCooldownFor(Subcommand subcommand, ThreadChannel helpThread) { + Cache helpThreadIdToLastAction = requireCooldownCache(subcommand); + helpThreadIdToLastAction.put(helpThread.getIdLong(), Instant.now()); + } + + private RestAction sendCategoryChangedMessage(Guild guild, InteractionHook hook, + ThreadChannel helpThread, String category) { + String changedContent = "Changed the category to **%s**.".formatted(category); + WebhookMessageUpdateAction action = hook.editOriginal(changedContent); + + Optional helperRole = helper.handleFindRoleForCategory(category, guild); + if (helperRole.isEmpty()) { + return action; + } + + // We want to invite all members of a role, but without hard-pinging them. However, + // manually inviting them is cumbersome and can hit rate limits. + // Instead, we abuse the fact that a role-ping through an edit will not hard-ping users, + // but still invite them to a thread. + String headsUpPattern = "%s please have a look, thanks."; + String headsUpWithoutRole = headsUpPattern.formatted(""); + String headsUpWithRole = headsUpPattern.formatted(helperRole.orElseThrow().getAsMention()); + return action.flatMap(any -> helpThread.sendMessage(headsUpWithoutRole) + .flatMap(message -> message.editMessage(headsUpWithRole))); + } + + private void changeTitle(SlashCommandInteractionEvent event, ThreadChannel helpThread) { + String title = event.getOption(CHANGE_TITLE_OPTION).getAsString(); + + if (!HelpSystemHelper.isTitleValid(title)) { + 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; + } + + refreshCooldownFor(Subcommand.CHANGE_TITLE, helpThread); + + helper.renameChannelToTitle(helpThread, title) + .flatMap(any -> event.reply("Changed the title to **%s**.".formatted(title))) + .queue(); + } + + private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpThread) { + refreshCooldownFor(Subcommand.CLOSE, helpThread); + + MessageEmbed embed = new EmbedBuilder().setDescription("Closed the thread.") + .setColor(HelpSystemHelper.AMBIENT_COLOR) + .build(); + + event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); + } + + private static Stream streamSubcommands() { + return Arrays.stream(Subcommand.values()); + } + + enum Subcommand { + CHANGE_CATEGORY(CHANGE_CATEGORY_SUBCOMMAND, "Change the category of this help thread", + Cooldown.YES), + CHANGE_TITLE(CHANGE_TITLE_SUBCOMMAND, "Change the title of this help thread", Cooldown.YES), + CLOSE("close", "Close this help thread", Cooldown.YES); + + private final String commandName; + private final String description; + private final Cooldown cooldown; + + Subcommand(String commandName, String description, Cooldown cooldown) { + this.commandName = commandName; + this.description = description; + this.cooldown = cooldown; + } + + String getCommandName() { + return commandName; + } + + String getDescription() { + return description; + } + + boolean hasCooldown() { + return cooldown == Cooldown.YES; + } + + SubcommandData toSubcommandData() { + return new SubcommandData(commandName, description); + } + } + + enum Cooldown { + YES, + NO + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java index 46086246cb..629d022128 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/ImplicitAskListener.java @@ -185,7 +185,7 @@ private static MessageAction sendInitialMessage(ThreadChannel threadChannel, """ %s has a question about '**%s**' and will send the details now. - Please use `/change-help-category` to greatly increase the visibility of the question.""" + Please use `/help-thread change category` to greatly increase the visibility of the question.""" .formatted(author, title)).setEmbeds(embed).build(); return threadChannel.sendMessage(threadMessage);