From 0c41c4a8f2b39ce18917baba02ec67b1c86d2338 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Sun, 23 Oct 2022 21:01:15 +0530 Subject: [PATCH 01/20] added cooldown to ask command --- .../tjbot/commands/help/AskCommand.java | 53 ++++++++++++++++--- .../commands/help/HelpThreadCommand.java | 4 +- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 2b0c253e09..5125a39c42 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -1,9 +1,8 @@ package org.togetherjava.tjbot.commands.help; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.IMentionable; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Message; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -19,9 +18,13 @@ import org.togetherjava.tjbot.commands.CommandVisibility; import org.togetherjava.tjbot.commands.SlashCommandAdapter; +import org.togetherjava.tjbot.commands.utils.MessageUtils; import org.togetherjava.tjbot.config.Config; +import java.time.Instant; +import java.time.temporal.ChronoUnit; 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; @@ -47,10 +50,16 @@ * */ public final class AskCommand extends SlashCommandAdapter { + private static final int COOLDOWN_DURATION_VALUE = 5; + private static final ChronoUnit COOLDOWN_DURATION_UNIT = ChronoUnit.MINUTES; private static final Logger logger = LoggerFactory.getLogger(AskCommand.class); public static final String COMMAND_NAME = "ask"; private static final String TITLE_OPTION = "title"; private static final String CATEGORY_OPTION = "category"; + private final Cache userToLastAsk = Caffeine.newBuilder() + .maximumSize(1_000) + .expireAfterAccess(COOLDOWN_DURATION_VALUE, TimeUnit.of(COOLDOWN_DURATION_UNIT)) + .build(); private final HelpSystemHelper helper; /** @@ -77,6 +86,31 @@ public AskCommand(Config config, HelpSystemHelper helper) { @Override public void onSlashCommand(SlashCommandInteractionEvent event) { + if (isUserOnCooldown(event.getUser())) { + String message = + """ + You can only create 1 help thread per 5 minutes. While you are waiting changing the infos of your previous thread may help. + Use these commands in the help thread to change its details:- + %s + %s"""; + + RestAction changeTitle = MessageUtils.mentionGuildSlashCommand(event.getGuild(), + HelpThreadCommand.COMMAND_NAME, HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, + HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND); + RestAction changeCategory = MessageUtils.mentionGuildSlashCommand( + event.getGuild(), HelpThreadCommand.COMMAND_NAME, + HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, + HelpThreadCommand.CHANGE_CATEGORY_OPTION); + + RestAction.allOf(changeCategory, changeTitle) + .map(commandMentions -> message.formatted(commandMentions.get(0), + commandMentions.get(1))) + .flatMap(event::reply) + .queue(); + + return; + } + String title = event.getOption(TITLE_OPTION).getAsString(); String category = event.getOption(CATEGORY_OPTION).getAsString(); @@ -102,8 +136,15 @@ public void onSlashCommand(SlashCommandInteractionEvent event) { overviewChannel.createThreadChannel(name.toChannelName()) .flatMap(threadChannel -> handleEvent(eventHook, threadChannel, author, title, category, guild)) - .queue(any -> { - }, e -> handleFailure(e, eventHook)); + .queue(any -> userToLastAsk.put(event.getUser().getIdLong(), Instant.now()), + e -> handleFailure(e, eventHook)); + } + + private boolean isUserOnCooldown(User user) { + return Optional.ofNullable(userToLastAsk.getIfPresent(user.getIdLong())) + .map(lastAction -> lastAction.plus(COOLDOWN_DURATION_VALUE, COOLDOWN_DURATION_UNIT)) + .filter(Instant.now()::isBefore) + .isPresent(); } private boolean handleIsValidTitle(CharSequence title, IReplyCallback event) { 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 index b4e52339f6..4cad456f91 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java @@ -42,9 +42,9 @@ 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"; + public static final String CHANGE_CATEGORY_OPTION = "category"; private static final String CHANGE_TITLE_OPTION = "title"; - private static final String CHANGE_TITLE_SUBCOMMAND = "title"; + public static final String CHANGE_TITLE_SUBCOMMAND = "title"; public static final String CHANGE_SUBCOMMAND_GROUP = "change"; public static final String COMMAND_NAME = "help-thread"; From 275158943f11d4b0f0018f9d165a9d9e1ebc163b Mon Sep 17 00:00:00 2001 From: Taz03 Date: Sun, 23 Oct 2022 21:07:42 +0530 Subject: [PATCH 02/20] emphemeral --- .../java/org/togetherjava/tjbot/commands/help/AskCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 5125a39c42..20914ad6e2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -105,7 +105,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event) { RestAction.allOf(changeCategory, changeTitle) .map(commandMentions -> message.formatted(commandMentions.get(0), commandMentions.get(1))) - .flatMap(event::reply) + .flatMap(text -> event.reply(text).setEphemeral(true)) .queue(); return; From b8504e72d8fdf76f6f8158c90bd013e6ae4e289a Mon Sep 17 00:00:00 2001 From: Taz03 Date: Sun, 23 Oct 2022 21:13:01 +0530 Subject: [PATCH 03/20] changed name --- .../java/org/togetherjava/tjbot/commands/help/AskCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 20914ad6e2..35cd64cc3a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -103,8 +103,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event) { HelpThreadCommand.CHANGE_CATEGORY_OPTION); RestAction.allOf(changeCategory, changeTitle) - .map(commandMentions -> message.formatted(commandMentions.get(0), - commandMentions.get(1))) + .map(mentions -> message.formatted(mentions.get(0), mentions.get(1))) .flatMap(text -> event.reply(text).setEphemeral(true)) .queue(); From 1947452f18a09f18d60771e4d2594e16d6f7c52e Mon Sep 17 00:00:00 2001 From: Taz03 Date: Mon, 24 Oct 2022 21:19:39 +0530 Subject: [PATCH 04/20] CR --- .../togetherjava/tjbot/commands/Features.java | 2 +- .../tjbot/commands/help/AskCommand.java | 62 ++++++++++++------- .../tjbot/commands/utils/MessageUtils.java | 9 +++ 3 files changed, 51 insertions(+), 22 deletions(-) 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 28c4f1284f..2e1ef3eb26 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Features.java @@ -126,7 +126,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new UnquarantineCommand(actionsStore, config)); features.add(new WhoIsCommand()); features.add(new WolframAlphaCommand(config)); - features.add(new AskCommand(config, helpSystemHelper)); + features.add(new AskCommand(config, helpSystemHelper, database)); features.add(new ModMailCommand(jda, config)); features.add(new HelpThreadCommand(config, helpSystemHelper)); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 35cd64cc3a..b7afe3b9a6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -20,6 +20,7 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.utils.MessageUtils; import org.togetherjava.tjbot.config.Config; +import org.togetherjava.tjbot.db.Database; import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -28,6 +29,7 @@ import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MAX; import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MIN; +import static org.togetherjava.tjbot.db.generated.Tables.HELP_THREADS; /** * Implements the {@code /ask} command, which is the main way of asking questions. The command can @@ -61,14 +63,16 @@ public final class AskCommand extends SlashCommandAdapter { .expireAfterAccess(COOLDOWN_DURATION_VALUE, TimeUnit.of(COOLDOWN_DURATION_UNIT)) .build(); private final HelpSystemHelper helper; + private final Database database; /** * Creates a new instance. * * @param config the config to use * @param helper the helper to use + * @param database the database to get help threads from */ - public AskCommand(Config config, HelpSystemHelper helper) { + public AskCommand(Config config, HelpSystemHelper helper, Database database) { super("ask", "Ask a question - use this in the staging channel", CommandVisibility.GUILD); OptionData title = @@ -82,31 +86,13 @@ public AskCommand(Config config, HelpSystemHelper helper) { getData().addOptions(title, category); this.helper = helper; + this.database = database; } @Override public void onSlashCommand(SlashCommandInteractionEvent event) { if (isUserOnCooldown(event.getUser())) { - String message = - """ - You can only create 1 help thread per 5 minutes. While you are waiting changing the infos of your previous thread may help. - Use these commands in the help thread to change its details:- - %s - %s"""; - - RestAction changeTitle = MessageUtils.mentionGuildSlashCommand(event.getGuild(), - HelpThreadCommand.COMMAND_NAME, HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, - HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND); - RestAction changeCategory = MessageUtils.mentionGuildSlashCommand( - event.getGuild(), HelpThreadCommand.COMMAND_NAME, - HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, - HelpThreadCommand.CHANGE_CATEGORY_OPTION); - - RestAction.allOf(changeCategory, changeTitle) - .map(mentions -> message.formatted(mentions.get(0), mentions.get(1))) - .flatMap(text -> event.reply(text).setEphemeral(true)) - .queue(); - + sendCooldownResponse(event); return; } @@ -146,6 +132,40 @@ private boolean isUserOnCooldown(User user) { .isPresent(); } + private void sendCooldownResponse(SlashCommandInteractionEvent event) { + User user = event.getUser(); + + String message = + """ + Sorry, you can only create a single help thread every 5 minutes. Please use your existing thread %s instead. + If you made a typo or similar, you can adjust the title using the command %s and the category with %s :ok_hand:"""; + + RestAction changeTitle = MessageUtils.mentionGuildSlashCommand(event.getGuild(), + HelpThreadCommand.COMMAND_NAME, HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, + HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND); + RestAction changeCategory = MessageUtils.mentionGuildSlashCommand(event.getGuild(), + HelpThreadCommand.COMMAND_NAME, HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, + HelpThreadCommand.CHANGE_CATEGORY_OPTION); + long lastCreatedThreadId = database + .read(context -> context.selectFrom(HELP_THREADS) + .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) + .orderBy(HELP_THREADS.CREATED_AT.desc()) + .fetch()) + .get(0) + .getChannelId(); + + if (lastCreatedThreadId == 0) { + logger.warn("Can't find the last help thread created by the user with id ({})", + user.getId()); + } + + RestAction.allOf(changeCategory, changeTitle) + .map(mentions -> message.formatted(MessageUtils.mentionChannelById(lastCreatedThreadId), + mentions.get(0), mentions.get(1))) + .flatMap(text -> event.reply(text).setEphemeral(true)) + .queue(); + } + private boolean handleIsValidTitle(CharSequence title, IReplyCallback event) { if (HelpSystemHelper.isTitleValid(title)) { return true; diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index d92e7d4e00..e24586f6d5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -141,4 +141,13 @@ public static String abbreviate(String text, int maxLength) { return text.substring(0, maxLength - ABBREVIATION.length()) + ABBREVIATION; } + /** + * Mentions a guild channel by its id + * + * @param channelId the channel id to mention + * @return channel mention + */ + public static String mentionChannelById(long channelId) { + return "<#%s>".formatted(channelId); + } } From a1d1da33a34b598c3f2fe79bca2bf2b41b67180d Mon Sep 17 00:00:00 2001 From: Taz03 Date: Tue, 25 Oct 2022 12:14:06 +0530 Subject: [PATCH 05/20] improved docs --- .../togetherjava/tjbot/commands/utils/MessageUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index e24586f6d5..77a116ea27 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -142,10 +142,11 @@ public static String abbreviate(String text, int maxLength) { } /** - * Mentions a guild channel by its id + * Mentions a guild channel by its id Clone of JDAs Channel#getAsMention, but unfortunately + * channel instances can not be created out of just an ID, unlike User#fromId * - * @param channelId the channel id to mention - * @return channel mention + * @param channelId the ID of the channel to mention + * @return the channel as formatted string which Discord interprets as clickable mention */ public static String mentionChannelById(long channelId) { return "<#%s>".formatted(channelId); From 46e81d1aa951c41cd2c05036464a6eaa3898465c Mon Sep 17 00:00:00 2001 From: Taz03 Date: Tue, 25 Oct 2022 12:16:41 +0530 Subject: [PATCH 06/20] added emoji --- .../java/org/togetherjava/tjbot/commands/help/AskCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index b7afe3b9a6..a135a466b8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -138,7 +138,7 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { String message = """ Sorry, you can only create a single help thread every 5 minutes. Please use your existing thread %s instead. - If you made a typo or similar, you can adjust the title using the command %s and the category with %s :ok_hand:"""; + If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; RestAction changeTitle = MessageUtils.mentionGuildSlashCommand(event.getGuild(), HelpThreadCommand.COMMAND_NAME, HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, From 4ded10d2ef294e8c9d7a0f78b7de2a51995dc5cc Mon Sep 17 00:00:00 2001 From: Taz03 Date: Tue, 25 Oct 2022 12:19:11 +0530 Subject: [PATCH 07/20] no hardcode --- .../org/togetherjava/tjbot/commands/help/AskCommand.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index a135a466b8..54b563552c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -137,7 +137,7 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { String message = """ - Sorry, you can only create a single help thread every 5 minutes. Please use your existing thread %s instead. + Sorry, you can only create a single help thread every %s %s. Please use your existing thread %s instead. If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; RestAction changeTitle = MessageUtils.mentionGuildSlashCommand(event.getGuild(), @@ -160,8 +160,10 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { } RestAction.allOf(changeCategory, changeTitle) - .map(mentions -> message.formatted(MessageUtils.mentionChannelById(lastCreatedThreadId), - mentions.get(0), mentions.get(1))) + .map(mentions -> message.formatted(COOLDOWN_DURATION_VALUE, + COOLDOWN_DURATION_UNIT.name(), + MessageUtils.mentionChannelById(lastCreatedThreadId), mentions.get(0), + mentions.get(1))) .flatMap(text -> event.reply(text).setEphemeral(true)) .queue(); } From 3f04c0239f130523bf4aae425e71213e6aacb39b Mon Sep 17 00:00:00 2001 From: Taz03 Date: Tue, 25 Oct 2022 12:24:49 +0530 Subject: [PATCH 08/20] added helper menthod --- .../tjbot/commands/help/AskCommand.java | 16 ++++++++++------ .../tjbot/commands/help/HelpThreadCommand.java | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 54b563552c..48a4871a66 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -133,6 +133,7 @@ private boolean isUserOnCooldown(User user) { } private void sendCooldownResponse(SlashCommandInteractionEvent event) { + Guild guild = event.getGuild(); User user = event.getUser(); String message = @@ -140,12 +141,10 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { Sorry, you can only create a single help thread every %s %s. Please use your existing thread %s instead. If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; - RestAction changeTitle = MessageUtils.mentionGuildSlashCommand(event.getGuild(), - HelpThreadCommand.COMMAND_NAME, HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, - HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND); - RestAction changeCategory = MessageUtils.mentionGuildSlashCommand(event.getGuild(), - HelpThreadCommand.COMMAND_NAME, HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, - HelpThreadCommand.CHANGE_CATEGORY_OPTION); + RestAction changeTitle = + mentionHelpChangeCommand(guild, HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND); + RestAction changeCategory = + mentionHelpChangeCommand(guild, HelpThreadCommand.CHANGE_CATEGORY_SUBCOMMAND); long lastCreatedThreadId = database .read(context -> context.selectFrom(HELP_THREADS) .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) @@ -235,4 +234,9 @@ private static void handleFailure(Throwable exception, InteractionHook eventHook logger.error("Attempted to create a help thread, but failed", exception); } + + private static RestAction mentionHelpChangeCommand(Guild guild, String subcommand) { + return MessageUtils.mentionGuildSlashCommand(guild, HelpThreadCommand.COMMAND_NAME, + HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, subcommand); + } } 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 index 4cad456f91..9d708a90cc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadCommand.java @@ -41,10 +41,10 @@ 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"; - public static final String CHANGE_CATEGORY_OPTION = "category"; - private static final String CHANGE_TITLE_OPTION = "title"; + public static final String CHANGE_CATEGORY_SUBCOMMAND = "category"; + private static final String CHANGE_CATEGORY_OPTION = "category"; public static final String CHANGE_TITLE_SUBCOMMAND = "title"; + private static final String CHANGE_TITLE_OPTION = "title"; public static final String CHANGE_SUBCOMMAND_GROUP = "change"; public static final String COMMAND_NAME = "help-thread"; From 8b96a9cab14272d3a627e27a4a7156fa4d38a352 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Tue, 25 Oct 2022 13:00:38 +0530 Subject: [PATCH 09/20] improved variable naming --- .../togetherjava/tjbot/commands/help/AskCommand.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 48a4871a66..26ae77d9cb 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -145,7 +145,7 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { mentionHelpChangeCommand(guild, HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND); RestAction changeCategory = mentionHelpChangeCommand(guild, HelpThreadCommand.CHANGE_CATEGORY_SUBCOMMAND); - long lastCreatedThreadId = database + long lastThreadByAuthorId = database .read(context -> context.selectFrom(HELP_THREADS) .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) .orderBy(HELP_THREADS.CREATED_AT.desc()) @@ -153,16 +153,16 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { .get(0) .getChannelId(); - if (lastCreatedThreadId == 0) { + if (lastThreadByAuthorId == 0) { logger.warn("Can't find the last help thread created by the user with id ({})", user.getId()); } RestAction.allOf(changeCategory, changeTitle) - .map(mentions -> message.formatted(COOLDOWN_DURATION_VALUE, + .map(commandMentions -> message.formatted(COOLDOWN_DURATION_VALUE, COOLDOWN_DURATION_UNIT.name(), - MessageUtils.mentionChannelById(lastCreatedThreadId), mentions.get(0), - mentions.get(1))) + MessageUtils.mentionChannelById(lastThreadByAuthorId), commandMentions.get(0), + commandMentions.get(1))) .flatMap(text -> event.reply(text).setEphemeral(true)) .queue(); } From 92513519fb232ef3326cc9174d33990795c621dd Mon Sep 17 00:00:00 2001 From: Taz03 Date: Tue, 25 Oct 2022 13:07:50 +0530 Subject: [PATCH 10/20] CR --- .../java/org/togetherjava/tjbot/commands/help/AskCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 26ae77d9cb..781d0cc8e8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -149,13 +149,13 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { .read(context -> context.selectFrom(HELP_THREADS) .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) .orderBy(HELP_THREADS.CREATED_AT.desc()) - .fetch()) - .get(0) + .fetchOne()) .getChannelId(); if (lastThreadByAuthorId == 0) { logger.warn("Can't find the last help thread created by the user with id ({})", user.getId()); + return; } RestAction.allOf(changeCategory, changeTitle) From d7786a8c52994169b35e445487cbe0f2a83f8edb Mon Sep 17 00:00:00 2001 From: Taz03 Date: Tue, 25 Oct 2022 13:11:05 +0530 Subject: [PATCH 11/20] CR --- .../org/togetherjava/tjbot/commands/utils/MessageUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index 77a116ea27..54f64158b7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -149,6 +149,6 @@ public static String abbreviate(String text, int maxLength) { * @return the channel as formatted string which Discord interprets as clickable mention */ public static String mentionChannelById(long channelId) { - return "<#%s>".formatted(channelId); + return "<#%d>".formatted(channelId); } } From f914984e781834c0a3a5f0d7201bcf972e54bcb8 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Wed, 26 Oct 2022 09:35:58 +0530 Subject: [PATCH 12/20] CR --- .../tjbot/commands/help/AskCommand.java | 22 +++++++++---------- .../tjbot/commands/utils/MessageUtils.java | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 781d0cc8e8..77914e2bc4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -29,6 +29,7 @@ import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MAX; import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MIN; +import static org.togetherjava.tjbot.commands.help.HelpThreadCommand.*; import static org.togetherjava.tjbot.db.generated.Tables.HELP_THREADS; /** @@ -133,18 +134,12 @@ private boolean isUserOnCooldown(User user) { } private void sendCooldownResponse(SlashCommandInteractionEvent event) { - Guild guild = event.getGuild(); User user = event.getUser(); + Guild guild = event.getGuild(); - String message = - """ - Sorry, you can only create a single help thread every %s %s. Please use your existing thread %s instead. - If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; - - RestAction changeTitle = - mentionHelpChangeCommand(guild, HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND); + RestAction changeTitle = mentionHelpChangeCommand(guild, CHANGE_TITLE_SUBCOMMAND); RestAction changeCategory = - mentionHelpChangeCommand(guild, HelpThreadCommand.CHANGE_CATEGORY_SUBCOMMAND); + mentionHelpChangeCommand(guild, CHANGE_CATEGORY_SUBCOMMAND); long lastThreadByAuthorId = database .read(context -> context.selectFrom(HELP_THREADS) .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) @@ -158,6 +153,11 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { return; } + String message = + """ + Sorry, you can only create a single help thread every %s %s. Please use your existing thread %s instead. + If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; + RestAction.allOf(changeCategory, changeTitle) .map(commandMentions -> message.formatted(COOLDOWN_DURATION_VALUE, COOLDOWN_DURATION_UNIT.name(), @@ -236,7 +236,7 @@ private static void handleFailure(Throwable exception, InteractionHook eventHook } private static RestAction mentionHelpChangeCommand(Guild guild, String subcommand) { - return MessageUtils.mentionGuildSlashCommand(guild, HelpThreadCommand.COMMAND_NAME, - HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, subcommand); + return MessageUtils.mentionGuildSlashCommand(guild, COMMAND_NAME, CHANGE_SUBCOMMAND_GROUP, + subcommand); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index 54f64158b7..8e731520a9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -142,12 +142,13 @@ public static String abbreviate(String text, int maxLength) { } /** - * Mentions a guild channel by its id Clone of JDAs Channel#getAsMention, but unfortunately - * channel instances can not be created out of just an ID, unlike User#fromId + * Mentions a guild channel by its id. * * @param channelId the ID of the channel to mention * @return the channel as formatted string which Discord interprets as clickable mention */ + // Clone of JDAs Channel#getAsMention, but unfortunately channel instances can not be created + // out of just an ID, unlike User#fromId public static String mentionChannelById(long channelId) { return "<#%d>".formatted(channelId); } From cd2cb8a70fae7eca2491acf0597c37ef91a5b85d Mon Sep 17 00:00:00 2001 From: Taz03 Date: Wed, 26 Oct 2022 23:38:51 +0530 Subject: [PATCH 13/20] CR --- .../togetherjava/tjbot/commands/help/AskCommand.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 77914e2bc4..ea23ea4d6d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -144,15 +144,10 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { .read(context -> context.selectFrom(HELP_THREADS) .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) .orderBy(HELP_THREADS.CREATED_AT.desc()) - .fetchOne()) + .fetch()) + .get(0) .getChannelId(); - if (lastThreadByAuthorId == 0) { - logger.warn("Can't find the last help thread created by the user with id ({})", - user.getId()); - return; - } - String message = """ Sorry, you can only create a single help thread every %s %s. Please use your existing thread %s instead. @@ -160,7 +155,7 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { RestAction.allOf(changeCategory, changeTitle) .map(commandMentions -> message.formatted(COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT.name(), + COOLDOWN_DURATION_UNIT.name().toLowerCase(), MessageUtils.mentionChannelById(lastThreadByAuthorId), commandMentions.get(0), commandMentions.get(1))) .flatMap(text -> event.reply(text).setEphemeral(true)) From c393f5e048d0c644d59e7ad05e40a3ddf663eb68 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Thu, 27 Oct 2022 14:05:49 +0530 Subject: [PATCH 14/20] CR --- .../org/togetherjava/tjbot/commands/help/AskCommand.java | 4 ++-- .../togetherjava/tjbot/commands/utils/MessageUtils.java | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index ea23ea4d6d..df76bb95c3 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -144,8 +144,8 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { .read(context -> context.selectFrom(HELP_THREADS) .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) .orderBy(HELP_THREADS.CREATED_AT.desc()) - .fetch()) - .get(0) + .limit(1) + .fetchOne()) .getChannelId(); String message = diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index 8e731520a9..a5706d847e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -142,14 +142,15 @@ public static String abbreviate(String text, int maxLength) { } /** - * Mentions a guild channel by its id. + * Mentions a guild channel by its id. If the given channelId is unknown the formatted text will + * say `#deleted-channel` in discord. * * @param channelId the ID of the channel to mention * @return the channel as formatted string which Discord interprets as clickable mention */ - // Clone of JDAs Channel#getAsMention, but unfortunately channel instances can not be created - // out of just an ID, unlike User#fromId public static String mentionChannelById(long channelId) { + // Clone of JDAs Channel#getAsMention, but unfortunately channel instances can not be + // created out of just an ID, unlike User#fromId return "<#%d>".formatted(channelId); } } From 5dd33eac923624de7c575462c3ed2e89b4e480ea Mon Sep 17 00:00:00 2001 From: Taz03 Date: Sat, 29 Oct 2022 07:05:35 +0530 Subject: [PATCH 15/20] CR --- .../tjbot/commands/help/AskCommand.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index df76bb95c3..5363052557 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -21,6 +21,7 @@ import org.togetherjava.tjbot.commands.utils.MessageUtils; import org.togetherjava.tjbot.config.Config; import org.togetherjava.tjbot.db.Database; +import org.togetherjava.tjbot.db.generated.tables.records.HelpThreadsRecord; import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -140,24 +141,35 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { RestAction changeTitle = mentionHelpChangeCommand(guild, CHANGE_TITLE_SUBCOMMAND); RestAction changeCategory = mentionHelpChangeCommand(guild, CHANGE_CATEGORY_SUBCOMMAND); - long lastThreadByAuthorId = database - .read(context -> context.selectFrom(HELP_THREADS) - .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) - .orderBy(HELP_THREADS.CREATED_AT.desc()) - .limit(1) - .fetchOne()) - .getChannelId(); + + HelpThreadsRecord lastThreadByAuthor = + database.read(context -> context.selectFrom(HELP_THREADS) + .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) + .orderBy(HELP_THREADS.CREATED_AT.desc()) + .limit(1) + .fetchOne()); + + String cooldownDuration = + COOLDOWN_DURATION_VALUE + " " + COOLDOWN_DURATION_UNIT.name().toLowerCase(); + + if (lastThreadByAuthor == null) { + logger.warn("Can't find the last help thread created by the user with id ({})", + user.getId()); + event + .reply("Sorry, something went wrong try again after %s".formatted(cooldownDuration)) + .queue(); + return; + } String message = """ - Sorry, you can only create a single help thread every %s %s. Please use your existing thread %s instead. + Sorry, you can only create a single help thread every %s. Please use your existing thread %s instead. If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; RestAction.allOf(changeCategory, changeTitle) - .map(commandMentions -> message.formatted(COOLDOWN_DURATION_VALUE, - COOLDOWN_DURATION_UNIT.name().toLowerCase(), - MessageUtils.mentionChannelById(lastThreadByAuthorId), commandMentions.get(0), - commandMentions.get(1))) + .map(commandMentions -> message.formatted(cooldownDuration, + MessageUtils.mentionChannelById(lastThreadByAuthor.getChannelId()), + commandMentions.get(0), commandMentions.get(1))) .flatMap(text -> event.reply(text).setEphemeral(true)) .queue(); } From d0b4d51bdc586671a95c39ad4249da87e9c8bf06 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Thu, 3 Nov 2022 01:19:04 +0530 Subject: [PATCH 16/20] CR --- .../tjbot/commands/help/AskCommand.java | 29 ++++++++++++------- .../tjbot/commands/utils/MessageUtils.java | 4 +-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 5363052557..0269081b1f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -23,6 +23,8 @@ import org.togetherjava.tjbot.db.Database; import org.togetherjava.tjbot.db.generated.tables.records.HelpThreadsRecord; +import javax.annotation.Nullable; + import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Optional; @@ -138,16 +140,7 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { User user = event.getUser(); Guild guild = event.getGuild(); - RestAction changeTitle = mentionHelpChangeCommand(guild, CHANGE_TITLE_SUBCOMMAND); - RestAction changeCategory = - mentionHelpChangeCommand(guild, CHANGE_CATEGORY_SUBCOMMAND); - - HelpThreadsRecord lastThreadByAuthor = - database.read(context -> context.selectFrom(HELP_THREADS) - .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) - .orderBy(HELP_THREADS.CREATED_AT.desc()) - .limit(1) - .fetchOne()); + HelpThreadsRecord lastThreadByAuthor = getLatestHelpThread(user); String cooldownDuration = COOLDOWN_DURATION_VALUE + " " + COOLDOWN_DURATION_UNIT.name().toLowerCase(); @@ -156,7 +149,8 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { logger.warn("Can't find the last help thread created by the user with id ({})", user.getId()); event - .reply("Sorry, something went wrong try again after %s".formatted(cooldownDuration)) + .reply("Sorry, something went wrong. Please try again after %s" + .formatted(cooldownDuration)) .queue(); return; } @@ -166,6 +160,10 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { Sorry, you can only create a single help thread every %s. Please use your existing thread %s instead. If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; + RestAction changeTitle = mentionHelpChangeCommand(guild, CHANGE_TITLE_SUBCOMMAND); + RestAction changeCategory = + mentionHelpChangeCommand(guild, CHANGE_CATEGORY_SUBCOMMAND); + RestAction.allOf(changeCategory, changeTitle) .map(commandMentions -> message.formatted(cooldownDuration, MessageUtils.mentionChannelById(lastThreadByAuthor.getChannelId()), @@ -174,6 +172,15 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { .queue(); } + @Nullable + private HelpThreadsRecord getLatestHelpThread(User user) { + return database.read(context -> context.selectFrom(HELP_THREADS) + .where(HELP_THREADS.AUTHOR_ID.eq(user.getIdLong())) + .orderBy(HELP_THREADS.CREATED_AT.desc()) + .limit(1) + .fetchOne()); + } + private boolean handleIsValidTitle(CharSequence title, IReplyCallback event) { if (HelpSystemHelper.isTitleValid(title)) { return true; diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index a5706d847e..68c505e7b3 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -142,8 +142,8 @@ public static String abbreviate(String text, int maxLength) { } /** - * Mentions a guild channel by its id. If the given channelId is unknown the formatted text will - * say `#deleted-channel` in discord. + * Mentions a guild channel by its id. If the given channelId is unknown, the formatted text + * will say #deleted-channel in Discord. * * @param channelId the ID of the channel to mention * @return the channel as formatted string which Discord interprets as clickable mention From 56040cc03fc95798e297e5816dfd31edc41ea5f4 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Thu, 3 Nov 2022 13:45:01 +0530 Subject: [PATCH 17/20] CR --- .../java/org/togetherjava/tjbot/commands/help/AskCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index 0269081b1f..e1e7b00418 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -149,7 +149,7 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { logger.warn("Can't find the last help thread created by the user with id ({})", user.getId()); event - .reply("Sorry, something went wrong. Please try again after %s" + .reply("Sorry, something went wrong. Please try again after %s." .formatted(cooldownDuration)) .queue(); return; From 8204f5f44f5837711cfa0007f2339a0f79230528 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Sat, 5 Nov 2022 19:19:35 +0530 Subject: [PATCH 18/20] CR --- .../tjbot/commands/help/AskCommand.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index e1e7b00418..b06e970b02 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -27,8 +27,10 @@ import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.List; import java.util.Optional; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MAX; import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MIN; @@ -151,23 +153,30 @@ private void sendCooldownResponse(SlashCommandInteractionEvent event) { event .reply("Sorry, something went wrong. Please try again after %s." .formatted(cooldownDuration)) + .setEphemeral(true) .queue(); return; } - String message = - """ - Sorry, you can only create a single help thread every %s. Please use your existing thread %s instead. - If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; + Function, String> formatMessage = commandMentions -> { + String message = + """ + Sorry, you can only create a single help thread every %s. Please use your existing thread %s instead. + If you made a typo or similar, you can adjust the title using the command %s and the category with %s 👌"""; + + String lastThreadMention = + MessageUtils.mentionChannelById(lastThreadByAuthor.getChannelId()); + + return message.formatted(cooldownDuration, lastThreadMention, commandMentions.get(0), + commandMentions.get(1)); + }; RestAction changeTitle = mentionHelpChangeCommand(guild, CHANGE_TITLE_SUBCOMMAND); RestAction changeCategory = mentionHelpChangeCommand(guild, CHANGE_CATEGORY_SUBCOMMAND); RestAction.allOf(changeCategory, changeTitle) - .map(commandMentions -> message.formatted(cooldownDuration, - MessageUtils.mentionChannelById(lastThreadByAuthor.getChannelId()), - commandMentions.get(0), commandMentions.get(1))) + .map(formatMessage) .flatMap(text -> event.reply(text).setEphemeral(true)) .queue(); } From cb2c9618c2be2b1805492168f1cd7aaf12020fb4 Mon Sep 17 00:00:00 2001 From: Taz03 Date: Sat, 5 Nov 2022 19:20:55 +0530 Subject: [PATCH 19/20] CR --- .../java/org/togetherjava/tjbot/commands/help/AskCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index b06e970b02..b122843199 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -259,7 +259,7 @@ private static void handleFailure(Throwable exception, InteractionHook eventHook } private static RestAction mentionHelpChangeCommand(Guild guild, String subcommand) { - return MessageUtils.mentionGuildSlashCommand(guild, COMMAND_NAME, CHANGE_SUBCOMMAND_GROUP, - subcommand); + return MessageUtils.mentionGuildSlashCommand(guild, HelpThreadCommand.COMMAND_NAME, + CHANGE_SUBCOMMAND_GROUP, subcommand); } } From dbbacb861605838bd10027749a07dd649494b52c Mon Sep 17 00:00:00 2001 From: Taz03 Date: Sun, 6 Nov 2022 06:34:04 +0530 Subject: [PATCH 20/20] CR --- .../org/togetherjava/tjbot/commands/help/AskCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java index b122843199..ed4e0c518e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/AskCommand.java @@ -34,7 +34,8 @@ import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MAX; import static org.togetherjava.tjbot.commands.help.HelpSystemHelper.TITLE_COMPACT_LENGTH_MIN; -import static org.togetherjava.tjbot.commands.help.HelpThreadCommand.*; +import static org.togetherjava.tjbot.commands.help.HelpThreadCommand.CHANGE_CATEGORY_SUBCOMMAND; +import static org.togetherjava.tjbot.commands.help.HelpThreadCommand.CHANGE_TITLE_SUBCOMMAND; import static org.togetherjava.tjbot.db.generated.Tables.HELP_THREADS; /** @@ -260,6 +261,6 @@ private static void handleFailure(Throwable exception, InteractionHook eventHook private static RestAction mentionHelpChangeCommand(Guild guild, String subcommand) { return MessageUtils.mentionGuildSlashCommand(guild, HelpThreadCommand.COMMAND_NAME, - CHANGE_SUBCOMMAND_GROUP, subcommand); + HelpThreadCommand.CHANGE_SUBCOMMAND_GROUP, subcommand); } }