From dc1fd1a3fd45ef73c465bc770c0300e2b043aba6 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 30 Dec 2022 18:06:49 +0100 Subject: [PATCH 01/23] add HelpThreadHistoryCache class; add HelpThreadResetHelpActivityCommand class; --- .../commands/help/HelpThreadHistoryCache.java | 62 +++++++++++++++++++ .../HelpThreadResetHelpActivityCommand.java | 26 ++++++++ 2 files changed, 88 insertions(+) create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java new file mode 100644 index 0000000000..cc54ad3d74 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java @@ -0,0 +1,62 @@ +package org.togetherjava.tjbot.commands.help; + +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +/** + * The HelpThreadHistoryCache class is a singleton that stores a mapping of message channels to a + * linked list of message IDs. The cache allows for the retrieval of the most recent message ID for + * a given message channel. + * + * @author mDyingStar + */ +public class HelpThreadHistoryCache { + + private static HelpThreadHistoryCache instance = null; + private final Map> messageChannelMessageIdMap; + + /** + * Private constructor to prevent external instantiation of the cache. + */ + private HelpThreadHistoryCache() { + messageChannelMessageIdMap = new HashMap<>(); + } + + /** + * Returns the singleton instance of the cache. + * + * @return the instance of the cache. + */ + public static HelpThreadHistoryCache getInstance() { + if (instance == null) { + instance = new HelpThreadHistoryCache(); + } + return instance; + } + + /** + * Adds a message ID to the linked list of message IDs for the given message channel. + * + * @param channel the message channel + * @param messageId the message ID to add + */ + public void add(MessageChannel channel, Integer messageId) { + messageChannelMessageIdMap.computeIfAbsent(channel, ids -> new LinkedList<>()); + LinkedList messageIds = messageChannelMessageIdMap.get(channel); + messageIds.add(messageId); + } + + /** + * Returns the most recent message ID for the given message channel. + * + * @param channel the message channel + * @return the most recent message ID + */ + public Integer getMostRecentMessageId(MessageChannel channel) { + LinkedList messageIds = messageChannelMessageIdMap.get(channel); + return messageIds.get(messageIds.size() - 1); + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java new file mode 100644 index 0000000000..b1bfa5bb89 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java @@ -0,0 +1,26 @@ +package org.togetherjava.tjbot.commands.help; + +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; + +import org.togetherjava.tjbot.commands.CommandVisibility; +import org.togetherjava.tjbot.commands.SlashCommandAdapter; + +/** + * This command will reset the activity in a help thread. + */ +public class HelpThreadResetHelpActivityCommand extends SlashCommandAdapter { + + private static final String COMMAND_NAME = "reset-activity"; + + public HelpThreadResetHelpActivityCommand() { + super(COMMAND_NAME, "resets the activity in a help thread", CommandVisibility.GUILD); + } + + @Override + public void onSlashCommand(SlashCommandInteractionEvent event) { + var helpThreadHistoryCache = HelpThreadHistoryCache.getInstance(); + var threadChannel = event.getChannel().asThreadChannel(); + + + } +} From 70728215b82a98ede83c2523ce1a3db55c60c2b8 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 1 Jan 2023 12:06:33 +0100 Subject: [PATCH 02/23] Implement feature #567: Add command to reset activity for a help thread --- .../togetherjava/tjbot/commands/Features.java | 1 + .../code/CodeMessageAutoDetection.java | 4 +- .../help/HelpThreadActivityUpdater.java | 16 ++++- .../commands/help/HelpThreadHistoryCache.java | 62 ------------------- .../HelpThreadManuallyResetHistoryCache.java | 60 ++++++++++++++++++ .../help/HelpThreadResetActivityCommand.java | 54 ++++++++++++++++ .../HelpThreadResetHelpActivityCommand.java | 26 -------- 7 files changed, 132 insertions(+), 91 deletions(-) delete mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java delete mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java 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 04c6e966c2..0bcec0fc54 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Features.java @@ -142,6 +142,7 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new HelpThreadCommand(config, helpSystemHelper)); features.add(new ReportCommand(config)); features.add(new BookmarksCommand(bookmarksSystem)); + features.add(new HelpThreadResetActivityCommand()); return features; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java b/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java index 30d7aea1b5..884333795e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java @@ -18,7 +18,7 @@ * Automatically detects messages that contain code and registers them at {@link CodeMessageHandler} * for further processing. */ -public final class CodeMessageAutoDetection extends MessageReceiverAdapter { +public class CodeMessageAutoDetection extends MessageReceiverAdapter { private static final long MINIMUM_LINES_OF_CODE = 3; private final CodeMessageHandler codeMessageHandler; @@ -63,7 +63,7 @@ public void onMessageReceived(MessageReceivedEvent event) { codeMessageHandler.addAndHandleCodeMessage(originalMessage, true); } - private boolean isHelpThread(MessageReceivedEvent event) { + protected boolean isHelpThread(MessageReceivedEvent event) { if (event.getChannelType() != ChannelType.GUILD_PUBLIC_THREAD) { return false; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index 4b21fb37e8..6f4f281801 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -3,6 +3,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.MessageHistory; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; @@ -78,7 +79,20 @@ private void updateActivityForThread(ThreadChannel threadChannel) { private static RestAction determineActivity( MessageChannel channel) { - return channel.getHistory().retrievePast(ACTIVITY_DETERMINE_MESSAGE_LIMIT).map(messages -> { + String mostRecentMessageId = + HelpThreadManuallyResetHistoryCache.getInstance().getMostRecentMessageId(channel); + RestAction> restActionMessages; + + if (!mostRecentMessageId.isEmpty()) { + MessageHistory.MessageRetrieveAction historyAfter = + channel.getHistoryAfter(mostRecentMessageId, ACTIVITY_DETERMINE_MESSAGE_LIMIT); + restActionMessages = historyAfter.map(MessageHistory::getRetrievedHistory); + } else { + restActionMessages = + channel.getHistory().retrievePast(ACTIVITY_DETERMINE_MESSAGE_LIMIT); + } + + return restActionMessages.map(messages -> { if (messages.size() >= ACTIVITY_DETERMINE_MESSAGE_LIMIT) { // There are likely even more messages, but we hit the limit return HelpSystemHelper.ThreadActivity.HIGH; diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java deleted file mode 100644 index cc54ad3d74..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadHistoryCache.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.togetherjava.tjbot.commands.help; - -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; - -/** - * The HelpThreadHistoryCache class is a singleton that stores a mapping of message channels to a - * linked list of message IDs. The cache allows for the retrieval of the most recent message ID for - * a given message channel. - * - * @author mDyingStar - */ -public class HelpThreadHistoryCache { - - private static HelpThreadHistoryCache instance = null; - private final Map> messageChannelMessageIdMap; - - /** - * Private constructor to prevent external instantiation of the cache. - */ - private HelpThreadHistoryCache() { - messageChannelMessageIdMap = new HashMap<>(); - } - - /** - * Returns the singleton instance of the cache. - * - * @return the instance of the cache. - */ - public static HelpThreadHistoryCache getInstance() { - if (instance == null) { - instance = new HelpThreadHistoryCache(); - } - return instance; - } - - /** - * Adds a message ID to the linked list of message IDs for the given message channel. - * - * @param channel the message channel - * @param messageId the message ID to add - */ - public void add(MessageChannel channel, Integer messageId) { - messageChannelMessageIdMap.computeIfAbsent(channel, ids -> new LinkedList<>()); - LinkedList messageIds = messageChannelMessageIdMap.get(channel); - messageIds.add(messageId); - } - - /** - * Returns the most recent message ID for the given message channel. - * - * @param channel the message channel - * @return the most recent message ID - */ - public Integer getMostRecentMessageId(MessageChannel channel) { - LinkedList messageIds = messageChannelMessageIdMap.get(channel); - return messageIds.get(messageIds.size() - 1); - } -} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java new file mode 100644 index 0000000000..b83f9f3603 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java @@ -0,0 +1,60 @@ +package org.togetherjava.tjbot.commands.help; + +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; + +import java.util.*; + +/** + * stores a map of message channels to a list of message ids. + * + * @author mDyingStar + */ +public final class HelpThreadManuallyResetHistoryCache { + + private static HelpThreadManuallyResetHistoryCache instance = null; + private final Map> messageChannelMessageIdMap; + + /** + * Private constructor to prevent external instantiation of the cache. + */ + private HelpThreadManuallyResetHistoryCache() { + messageChannelMessageIdMap = new HashMap<>(); + } + + /** + * Returns the singleton instance of the cache. + * + * @return the instance of the cache. + */ + public static HelpThreadManuallyResetHistoryCache getInstance() { + if (instance == null) { + instance = new HelpThreadManuallyResetHistoryCache(); + } + return instance; + } + + /** + * Adds a message id to the list for a given channel in the cache. + * + * @param channel the message channel to add the message id to + * @param messageId the message id to add to the list for the channel + */ + public void add(MessageChannel channel, String messageId) { + messageChannelMessageIdMap.computeIfAbsent(channel, ids -> new LinkedList<>()); + List messageIds = messageChannelMessageIdMap.get(channel); + messageIds.add(messageId); + } + + /** + * Gets the most recent message id from the list for a given channel in the cache. + * + * @param channel the message channel to get the most recent message id from + * @return the most recent message id from the list for the channel, or an empty string if the + * list is empty + */ + public String getMostRecentMessageId(MessageChannel channel) { + messageChannelMessageIdMap.computeIfAbsent(channel, messageIds -> new ArrayList<>()); + List messageIds = messageChannelMessageIdMap.get(channel); + return messageIds.isEmpty() ? "" : messageIds.get(messageIds.size() - 1); + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java new file mode 100644 index 0000000000..7a89a752b5 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java @@ -0,0 +1,54 @@ +package org.togetherjava.tjbot.commands.help; + +import net.dv8tion.jda.api.entities.ISnowflake; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.requests.restaction.pagination.MessagePaginationAction; + +import org.togetherjava.tjbot.commands.CommandVisibility; +import org.togetherjava.tjbot.commands.SlashCommandAdapter; + +import java.util.Comparator; +import java.util.List; + +/** + * This command will reset the activity in a help thread. + * + * @author mDyingStar + */ +public final class HelpThreadResetActivityCommand extends SlashCommandAdapter { + + private static final String COMMAND_NAME = "reset-activity"; + + /** + * Constructs a new HelpThreadResetActivityCommand with the command name "reset-activity", a + * description of "resets the activity in a help thread", and command visibility of + * {@link CommandVisibility#GUILD}. + */ + public HelpThreadResetActivityCommand() { + super(COMMAND_NAME, "resets the activity in a help thread", CommandVisibility.GUILD); + } + + /** + * Called when the command is executed. Retrieves the most recent message in the thread, adds + * its id to the {@link HelpThreadManuallyResetHistoryCache}, and replies to the user to confirm + * that the activity has been reset. + * + * @param event the event representing the command interaction + */ + @Override + public void onSlashCommand(SlashCommandInteractionEvent event) { + var helpThreadHistoryCache = HelpThreadManuallyResetHistoryCache.getInstance(); + var threadChannel = event.getChannel().asThreadChannel(); + + MessagePaginationAction iterableHistory = threadChannel.getIterableHistory(); + + List messages = iterableHistory.stream() + .sorted(Comparator.comparing(ISnowflake::getTimeCreated).reversed()) + .toList(); + + helpThreadHistoryCache.add(threadChannel, messages.get(0).getId()); + + event.reply("Activities have been reset.").queue(); + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java deleted file mode 100644 index b1bfa5bb89..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetHelpActivityCommand.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.togetherjava.tjbot.commands.help; - -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; - -import org.togetherjava.tjbot.commands.CommandVisibility; -import org.togetherjava.tjbot.commands.SlashCommandAdapter; - -/** - * This command will reset the activity in a help thread. - */ -public class HelpThreadResetHelpActivityCommand extends SlashCommandAdapter { - - private static final String COMMAND_NAME = "reset-activity"; - - public HelpThreadResetHelpActivityCommand() { - super(COMMAND_NAME, "resets the activity in a help thread", CommandVisibility.GUILD); - } - - @Override - public void onSlashCommand(SlashCommandInteractionEvent event) { - var helpThreadHistoryCache = HelpThreadHistoryCache.getInstance(); - var threadChannel = event.getChannel().asThreadChannel(); - - - } -} From 3f2a7c2a6b2cd487b22a92218040f4a1edd70659 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 1 Jan 2023 12:10:11 +0100 Subject: [PATCH 03/23] change access modifier back to private and class back to final; --- .../tjbot/commands/code/CodeMessageAutoDetection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java b/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java index 884333795e..30d7aea1b5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/code/CodeMessageAutoDetection.java @@ -18,7 +18,7 @@ * Automatically detects messages that contain code and registers them at {@link CodeMessageHandler} * for further processing. */ -public class CodeMessageAutoDetection extends MessageReceiverAdapter { +public final class CodeMessageAutoDetection extends MessageReceiverAdapter { private static final long MINIMUM_LINES_OF_CODE = 3; private final CodeMessageHandler codeMessageHandler; @@ -63,7 +63,7 @@ public void onMessageReceived(MessageReceivedEvent event) { codeMessageHandler.addAndHandleCodeMessage(originalMessage, true); } - protected boolean isHelpThread(MessageReceivedEvent event) { + private boolean isHelpThread(MessageReceivedEvent event) { if (event.getChannelType() != ChannelType.GUILD_PUBLIC_THREAD) { return false; } From 07dfec7c0da7e4c8cd39d635cd8894bf827d0e95 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 1 Jan 2023 18:13:34 +0100 Subject: [PATCH 04/23] changed ResetActivityCommand from own command to Subcommand; --- .../togetherjava/tjbot/commands/Features.java | 1 - .../commands/help/HelpThreadCommand.java | 33 +++++++++--- .../help/HelpThreadResetActivityCommand.java | 54 ------------------- 3 files changed, 25 insertions(+), 63 deletions(-) delete mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java 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 0bcec0fc54..04c6e966c2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Features.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Features.java @@ -142,7 +142,6 @@ public static Collection createFeatures(JDA jda, Database database, Con features.add(new HelpThreadCommand(config, helpSystemHelper)); features.add(new ReportCommand(config)); features.add(new BookmarksCommand(bookmarksSystem)); - features.add(new HelpThreadResetActivityCommand()); return features; } 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 5ca8c3eab6..426f31daba 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 @@ -3,10 +3,7 @@ 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.Guild; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.InteractionHook; @@ -16,6 +13,7 @@ import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction; +import net.dv8tion.jda.api.requests.restaction.pagination.MessagePaginationAction; import org.togetherjava.tjbot.commands.CommandVisibility; import org.togetherjava.tjbot.commands.SlashCommandAdapter; @@ -42,6 +40,8 @@ public final class HelpThreadCommand extends SlashCommandAdapter { private static final String CHANGE_CATEGORY_OPTION = "category"; public static final String CHANGE_TITLE_SUBCOMMAND = "title"; private static final String CHANGE_TITLE_OPTION = "title"; + private static final String CLOSE_SUBCOMMAND = "close"; + private static final String RESET_ACTIVITY_SUBCOMMAND = "reset-activity"; public static final String CHANGE_SUBCOMMAND_GROUP = "change"; public static final String COMMAND_NAME = "help-thread"; @@ -80,6 +80,7 @@ public HelpThreadCommand(Config config, HelpSystemHelper helper) { getData().addSubcommandGroups(changeCommands); getData().addSubcommands(Subcommand.CLOSE.toSubcommandData()); + getData().addSubcommands(Subcommand.RESET_ACTIVITY.toSubcommandData()); this.helper = helper; @@ -92,9 +93,9 @@ public HelpThreadCommand(Config config, HelpSystemHelper helper) { 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)); + subcommandToEventHandler = new EnumMap<>(Map.of(Subcommand.CHANGE_CATEGORY, + this::changeCategory, Subcommand.CHANGE_TITLE, this::changeTitle, Subcommand.CLOSE, + this::closeThread, Subcommand.RESET_ACTIVITY, this::resetActivity)); } @Override @@ -198,6 +199,20 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); } + private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel helpThread) { + var helpThreadHistoryCache = HelpThreadManuallyResetHistoryCache.getInstance(); + + MessagePaginationAction iterableHistory = helpThread.getIterableHistory(); + + List messages = iterableHistory.stream() + .sorted(Comparator.comparing(ISnowflake::getTimeCreated).reversed()) + .toList(); + + helpThreadHistoryCache.add(helpThread, messages.get(0).getId()); + + event.reply("Activities have been reset.").queue(); + } + private static Stream streamSubcommands() { return Arrays.stream(Subcommand.values()); } @@ -206,7 +221,9 @@ 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); + CLOSE(CLOSE_SUBCOMMAND, "Close this help thread", Cooldown.YES), + RESET_ACTIVITY(RESET_ACTIVITY_SUBCOMMAND, "resets the activity in a help thread", + Cooldown.YES); private final String commandName; private final String description; diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java deleted file mode 100644 index 7a89a752b5..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadResetActivityCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.togetherjava.tjbot.commands.help; - -import net.dv8tion.jda.api.entities.ISnowflake; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.requests.restaction.pagination.MessagePaginationAction; - -import org.togetherjava.tjbot.commands.CommandVisibility; -import org.togetherjava.tjbot.commands.SlashCommandAdapter; - -import java.util.Comparator; -import java.util.List; - -/** - * This command will reset the activity in a help thread. - * - * @author mDyingStar - */ -public final class HelpThreadResetActivityCommand extends SlashCommandAdapter { - - private static final String COMMAND_NAME = "reset-activity"; - - /** - * Constructs a new HelpThreadResetActivityCommand with the command name "reset-activity", a - * description of "resets the activity in a help thread", and command visibility of - * {@link CommandVisibility#GUILD}. - */ - public HelpThreadResetActivityCommand() { - super(COMMAND_NAME, "resets the activity in a help thread", CommandVisibility.GUILD); - } - - /** - * Called when the command is executed. Retrieves the most recent message in the thread, adds - * its id to the {@link HelpThreadManuallyResetHistoryCache}, and replies to the user to confirm - * that the activity has been reset. - * - * @param event the event representing the command interaction - */ - @Override - public void onSlashCommand(SlashCommandInteractionEvent event) { - var helpThreadHistoryCache = HelpThreadManuallyResetHistoryCache.getInstance(); - var threadChannel = event.getChannel().asThreadChannel(); - - MessagePaginationAction iterableHistory = threadChannel.getIterableHistory(); - - List messages = iterableHistory.stream() - .sorted(Comparator.comparing(ISnowflake::getTimeCreated).reversed()) - .toList(); - - helpThreadHistoryCache.add(threadChannel, messages.get(0).getId()); - - event.reply("Activities have been reset.").queue(); - } -} From 9ae5835e17befddf7df8ec7ba99f5e11fb17456b Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 2 Jan 2023 22:10:49 +0100 Subject: [PATCH 05/23] add removeChannel method to cache; adjust methods; --- .../tjbot/commands/help/HelpThreadCommand.java | 3 +++ .../help/HelpThreadManuallyResetHistoryCache.java | 9 +++++++++ 2 files changed, 12 insertions(+) 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 426f31daba..aec0fcc24b 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 @@ -196,10 +196,13 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT .setColor(HelpSystemHelper.AMBIENT_COLOR) .build(); + HelpThreadManuallyResetHistoryCache.getInstance().removeChannel(helpThread); event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); } private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel helpThread) { + refreshCooldownFor(Subcommand.RESET_ACTIVITY, helpThread); + var helpThreadHistoryCache = HelpThreadManuallyResetHistoryCache.getInstance(); MessagePaginationAction iterableHistory = helpThread.getIterableHistory(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java index b83f9f3603..5ce5470eda 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java @@ -57,4 +57,13 @@ public String getMostRecentMessageId(MessageChannel channel) { List messageIds = messageChannelMessageIdMap.get(channel); return messageIds.isEmpty() ? "" : messageIds.get(messageIds.size() - 1); } + + /** + * Removes a message channel from the cache. + * + * @param channel the message channel to remove + */ + public void removeChannel(MessageChannel channel) { + messageChannelMessageIdMap.remove(channel); + } } From 3aefdbe3d53f6e52ac3e9ad81f06f2ed0b5880a7 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 2 Jan 2023 22:23:56 +0100 Subject: [PATCH 06/23] replaced HelpThreadManuallyResetHistoryCache.java with Caffeine Object. --- .../help/HelpThreadActivityUpdater.java | 16 +++-- .../commands/help/HelpThreadCommand.java | 14 ++-- .../HelpThreadManuallyResetHistoryCache.java | 69 ------------------- 3 files changed, 18 insertions(+), 81 deletions(-) delete mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index 6f4f281801..6e4a48fcd5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -1,5 +1,7 @@ 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.JDA; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; @@ -14,6 +16,7 @@ import org.togetherjava.tjbot.commands.Routine; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; import java.util.Optional; @@ -31,8 +34,14 @@ public final class HelpThreadActivityUpdater implements Routine { private static final Logger logger = LoggerFactory.getLogger(HelpThreadActivityUpdater.class); private static final int SCHEDULE_MINUTES = 30; private static final int ACTIVITY_DETERMINE_MESSAGE_LIMIT = 11; - + private static final int PERSIST_DURATION_VALUE = 12; + private static final ChronoUnit PERSIST_DURATION_UNIT = ChronoUnit.HOURS; private final HelpSystemHelper helper; + public static final Cache resetChannelHistoryCache = + Caffeine.newBuilder() + .maximumSize(1_000) + .expireAfterAccess(PERSIST_DURATION_VALUE, TimeUnit.of(PERSIST_DURATION_UNIT)) + .build(); /** * Creates a new instance. @@ -79,11 +88,10 @@ private void updateActivityForThread(ThreadChannel threadChannel) { private static RestAction determineActivity( MessageChannel channel) { - String mostRecentMessageId = - HelpThreadManuallyResetHistoryCache.getInstance().getMostRecentMessageId(channel); + String mostRecentMessageId = resetChannelHistoryCache.getIfPresent(channel); RestAction> restActionMessages; - if (!mostRecentMessageId.isEmpty()) { + if (mostRecentMessageId != null) { MessageHistory.MessageRetrieveAction historyAfter = channel.getHistoryAfter(mostRecentMessageId, ACTIVITY_DETERMINE_MESSAGE_LIMIT); restActionMessages = historyAfter.map(MessageHistory::getRetrievedHistory); 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 aec0fcc24b..211ff7903e 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 @@ -13,7 +13,6 @@ import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction; -import net.dv8tion.jda.api.requests.restaction.pagination.MessagePaginationAction; import org.togetherjava.tjbot.commands.CommandVisibility; import org.togetherjava.tjbot.commands.SlashCommandAdapter; @@ -29,6 +28,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.togetherjava.tjbot.commands.help.HelpThreadActivityUpdater.resetChannelHistoryCache; + /** * Implements the {@code /help-thread} command, used to maintain certain aspects of help threads, * such as renaming or closing them. @@ -196,22 +197,19 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT .setColor(HelpSystemHelper.AMBIENT_COLOR) .build(); - HelpThreadManuallyResetHistoryCache.getInstance().removeChannel(helpThread); + resetChannelHistoryCache.invalidate(helpThread); event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); } private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel helpThread) { refreshCooldownFor(Subcommand.RESET_ACTIVITY, helpThread); - var helpThreadHistoryCache = HelpThreadManuallyResetHistoryCache.getInstance(); - - MessagePaginationAction iterableHistory = helpThread.getIterableHistory(); - - List messages = iterableHistory.stream() + List messages = helpThread.getIterableHistory() + .stream() .sorted(Comparator.comparing(ISnowflake::getTimeCreated).reversed()) .toList(); - helpThreadHistoryCache.add(helpThread, messages.get(0).getId()); + resetChannelHistoryCache.put(helpThread, messages.get(0).getId()); event.reply("Activities have been reset.").queue(); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java deleted file mode 100644 index 5ce5470eda..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadManuallyResetHistoryCache.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.togetherjava.tjbot.commands.help; - -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; - -import java.util.*; - -/** - * stores a map of message channels to a list of message ids. - * - * @author mDyingStar - */ -public final class HelpThreadManuallyResetHistoryCache { - - private static HelpThreadManuallyResetHistoryCache instance = null; - private final Map> messageChannelMessageIdMap; - - /** - * Private constructor to prevent external instantiation of the cache. - */ - private HelpThreadManuallyResetHistoryCache() { - messageChannelMessageIdMap = new HashMap<>(); - } - - /** - * Returns the singleton instance of the cache. - * - * @return the instance of the cache. - */ - public static HelpThreadManuallyResetHistoryCache getInstance() { - if (instance == null) { - instance = new HelpThreadManuallyResetHistoryCache(); - } - return instance; - } - - /** - * Adds a message id to the list for a given channel in the cache. - * - * @param channel the message channel to add the message id to - * @param messageId the message id to add to the list for the channel - */ - public void add(MessageChannel channel, String messageId) { - messageChannelMessageIdMap.computeIfAbsent(channel, ids -> new LinkedList<>()); - List messageIds = messageChannelMessageIdMap.get(channel); - messageIds.add(messageId); - } - - /** - * Gets the most recent message id from the list for a given channel in the cache. - * - * @param channel the message channel to get the most recent message id from - * @return the most recent message id from the list for the channel, or an empty string if the - * list is empty - */ - public String getMostRecentMessageId(MessageChannel channel) { - messageChannelMessageIdMap.computeIfAbsent(channel, messageIds -> new ArrayList<>()); - List messageIds = messageChannelMessageIdMap.get(channel); - return messageIds.isEmpty() ? "" : messageIds.get(messageIds.size() - 1); - } - - /** - * Removes a message channel from the cache. - * - * @param channel the message channel to remove - */ - public void removeChannel(MessageChannel channel) { - messageChannelMessageIdMap.remove(channel); - } -} From e2464bf5ceff2dfc2c6087702d69babbf811907e Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 3 Jan 2023 10:52:31 +0100 Subject: [PATCH 07/23] adjust cache setting and variable name; --- .../tjbot/commands/help/HelpThreadActivityUpdater.java | 6 +++--- .../togetherjava/tjbot/commands/help/HelpThreadCommand.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index 6e4a48fcd5..5c9c5652f4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -37,10 +37,10 @@ public final class HelpThreadActivityUpdater implements Routine { private static final int PERSIST_DURATION_VALUE = 12; private static final ChronoUnit PERSIST_DURATION_UNIT = ChronoUnit.HOURS; private final HelpSystemHelper helper; - public static final Cache resetChannelHistoryCache = + public static final Cache manuallyResetChannelActivityCache = Caffeine.newBuilder() .maximumSize(1_000) - .expireAfterAccess(PERSIST_DURATION_VALUE, TimeUnit.of(PERSIST_DURATION_UNIT)) + .expireAfterWrite(PERSIST_DURATION_VALUE, TimeUnit.of(PERSIST_DURATION_UNIT)) .build(); /** @@ -88,7 +88,7 @@ private void updateActivityForThread(ThreadChannel threadChannel) { private static RestAction determineActivity( MessageChannel channel) { - String mostRecentMessageId = resetChannelHistoryCache.getIfPresent(channel); + String mostRecentMessageId = manuallyResetChannelActivityCache.getIfPresent(channel); RestAction> restActionMessages; if (mostRecentMessageId != null) { 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 211ff7903e..4009eef5f5 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 @@ -28,7 +28,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.togetherjava.tjbot.commands.help.HelpThreadActivityUpdater.resetChannelHistoryCache; +import static org.togetherjava.tjbot.commands.help.HelpThreadActivityUpdater.manuallyResetChannelActivityCache; /** * Implements the {@code /help-thread} command, used to maintain certain aspects of help threads, @@ -197,7 +197,7 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT .setColor(HelpSystemHelper.AMBIENT_COLOR) .build(); - resetChannelHistoryCache.invalidate(helpThread); + manuallyResetChannelActivityCache.invalidate(helpThread); event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); } @@ -209,7 +209,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel .sorted(Comparator.comparing(ISnowflake::getTimeCreated).reversed()) .toList(); - resetChannelHistoryCache.put(helpThread, messages.get(0).getId()); + manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); event.reply("Activities have been reset.").queue(); } From 49d15a43764865e3af261ecab121ab5b58d66685 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 3 Jan 2023 11:27:19 +0100 Subject: [PATCH 08/23] changes command response message; --- .../togetherjava/tjbot/commands/help/HelpThreadCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 4009eef5f5..995b0fc2ed 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 @@ -211,7 +211,8 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); - event.reply("Activities have been reset.").queue(); + event.reply("Activities have been reset. Updated status will be displayed in one minute.") + .queue(); } private static Stream streamSubcommands() { From 0ef8cb3969717e338e3a508665dfba9ca9660405 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 3 Jan 2023 11:38:58 +0100 Subject: [PATCH 09/23] changed access modifier to package-private; adjust resetActivity; --- .../tjbot/commands/help/HelpThreadActivityUpdater.java | 2 +- .../togetherjava/tjbot/commands/help/HelpThreadCommand.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index 5c9c5652f4..a3f8cd438e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -80,7 +80,7 @@ private void updateActivityForGuild(Guild guild) { activeThreads.forEach(this::updateActivityForThread); } - private void updateActivityForThread(ThreadChannel threadChannel) { + void updateActivityForThread(ThreadChannel threadChannel) { determineActivity(threadChannel) .flatMap(threadActivity -> helper.changeChannelActivity(threadChannel, threadActivity)) .queue(); 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 995b0fc2ed..c0c833c62a 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 @@ -211,8 +211,10 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); - event.reply("Activities have been reset. Updated status will be displayed in one minute.") - .queue(); + HelpThreadActivityUpdater helpThreadActivityUpdater = new HelpThreadActivityUpdater(helper); + helpThreadActivityUpdater.updateActivityForThread(helpThread); + + event.reply("Activities have been reset.").queue(); } private static Stream streamSubcommands() { From 8e61a4f313e242937cd0f75334a76998923585c2 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 3 Jan 2023 15:23:04 +0100 Subject: [PATCH 10/23] changed suggestions from code findings; --- .../tjbot/commands/help/HelpThreadActivityUpdater.java | 4 +++- .../togetherjava/tjbot/commands/help/HelpThreadCommand.java | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index a3f8cd438e..a1b29eafc7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -36,7 +36,9 @@ public final class HelpThreadActivityUpdater implements Routine { private static final int ACTIVITY_DETERMINE_MESSAGE_LIMIT = 11; private static final int PERSIST_DURATION_VALUE = 12; private static final ChronoUnit PERSIST_DURATION_UNIT = ChronoUnit.HOURS; + private final HelpSystemHelper helper; + public static final Cache manuallyResetChannelActivityCache = Caffeine.newBuilder() .maximumSize(1_000) @@ -80,7 +82,7 @@ private void updateActivityForGuild(Guild guild) { activeThreads.forEach(this::updateActivityForThread); } - void updateActivityForThread(ThreadChannel threadChannel) { + private void updateActivityForThread(ThreadChannel threadChannel) { determineActivity(threadChannel) .flatMap(threadActivity -> helper.changeChannelActivity(threadChannel, threadActivity)) .queue(); 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 c0c833c62a..ad7c1ab161 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 @@ -211,8 +211,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); - HelpThreadActivityUpdater helpThreadActivityUpdater = new HelpThreadActivityUpdater(helper); - helpThreadActivityUpdater.updateActivityForThread(helpThread); + helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); event.reply("Activities have been reset.").queue(); } From ca4f6369c14404b3653e9b76b98fd14bef474b90 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 5 Jan 2023 18:37:09 +0100 Subject: [PATCH 11/23] removed not needed sorting; --- .../togetherjava/tjbot/commands/help/HelpThreadCommand.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 ad7c1ab161..75cdba4105 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 @@ -204,10 +204,7 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel helpThread) { refreshCooldownFor(Subcommand.RESET_ACTIVITY, helpThread); - List messages = helpThread.getIterableHistory() - .stream() - .sorted(Comparator.comparing(ISnowflake::getTimeCreated).reversed()) - .toList(); + List messages = helpThread.getIterableHistory().stream().toList(); manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); From ba631e66d5a87d10790f424ee9fee54140eca0be Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 5 Jan 2023 18:38:19 +0100 Subject: [PATCH 12/23] adjust line formatting; --- .../org/togetherjava/tjbot/commands/help/HelpThreadCommand.java | 2 -- 1 file changed, 2 deletions(-) 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 75cdba4105..c5cfc6d6eb 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 @@ -207,9 +207,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel List messages = helpThread.getIterableHistory().stream().toList(); manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); - helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); - event.reply("Activities have been reset.").queue(); } From 3625a003d10dc34037c41e705459c86fd3772b53 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 5 Jan 2023 19:39:21 +0100 Subject: [PATCH 13/23] added if case that only thread author can reset activity; --- .../tjbot/commands/help/HelpThreadCommand.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 c5cfc6d6eb..0ef049ff53 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 @@ -204,9 +204,13 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel helpThread) { refreshCooldownFor(Subcommand.RESET_ACTIVITY, helpThread); - List messages = helpThread.getIterableHistory().stream().toList(); + if (!event.getMember().equals(helpThread.getOwner())) { + event.reply("Only the thread creator can reset activities.").queue(); + } + + RestAction> messages = helpThread.getHistory().retrievePast(1); - manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); + manuallyResetChannelActivityCache.put(helpThread, messages.complete().get(0).getId()); helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); event.reply("Activities have been reset.").queue(); } From 485e277ec79edcd3b63727aeb1acdba5baaefc60 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 5 Jan 2023 19:42:14 +0100 Subject: [PATCH 14/23] added if case that only thread author can reset activity; --- .../org/togetherjava/tjbot/commands/help/HelpThreadCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0ef049ff53..f03c0380fd 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 @@ -224,7 +224,7 @@ enum Subcommand { Cooldown.YES), CHANGE_TITLE(CHANGE_TITLE_SUBCOMMAND, "Change the title of this help thread", Cooldown.YES), CLOSE(CLOSE_SUBCOMMAND, "Close this help thread", Cooldown.YES), - RESET_ACTIVITY(RESET_ACTIVITY_SUBCOMMAND, "resets the activity in a help thread", + RESET_ACTIVITY(RESET_ACTIVITY_SUBCOMMAND, "Resets the activity in a help thread", Cooldown.YES); private final String commandName; From d5aaff74aa7982c828ee2425d870939edeb37fa5 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 5 Jan 2023 22:36:10 +0100 Subject: [PATCH 15/23] changed blocking to async method; --- .../tjbot/commands/help/HelpThreadCommand.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 f03c0380fd..1fab2170cc 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 @@ -208,11 +208,11 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel event.reply("Only the thread creator can reset activities.").queue(); } - RestAction> messages = helpThread.getHistory().retrievePast(1); - - manuallyResetChannelActivityCache.put(helpThread, messages.complete().get(0).getId()); - helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); - event.reply("Activities have been reset.").queue(); + helpThread.getHistory().retrievePast(1).queue(messages -> { + manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); + helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); + event.reply("Activities have been reset.").queue(); + }); } private static Stream streamSubcommands() { From d03a114309e9ad49cc55eb76453f7efb150e9499 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 5 Jan 2023 22:37:32 +0100 Subject: [PATCH 16/23] add return; --- .../org/togetherjava/tjbot/commands/help/HelpThreadCommand.java | 1 + 1 file changed, 1 insertion(+) 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 1fab2170cc..d34aaee6a6 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 @@ -206,6 +206,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel if (!event.getMember().equals(helpThread.getOwner())) { event.reply("Only the thread creator can reset activities.").queue(); + return; } helpThread.getHistory().retrievePast(1).queue(messages -> { From b2d6ae725a6307b47ed4faa8ca291a1b147baa03 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 6 Jan 2023 05:22:58 +0100 Subject: [PATCH 17/23] removed lines from lambda; --- .../tjbot/commands/help/HelpThreadCommand.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 d34aaee6a6..b65e3033e9 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 @@ -209,11 +209,13 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel return; } - helpThread.getHistory().retrievePast(1).queue(messages -> { - manuallyResetChannelActivityCache.put(helpThread, messages.get(0).getId()); - helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); - event.reply("Activities have been reset.").queue(); - }); + helpThread.getHistory() + .retrievePast(1) + .queue(messages -> manuallyResetChannelActivityCache.put(helpThread, + messages.get(0).getId())); + + helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); + event.reply("Activities have been reset.").queue(); } private static Stream streamSubcommands() { From 142e20dc2f1aced0fe6f79910657e8913ddeeaa4 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 6 Jan 2023 10:15:53 +0100 Subject: [PATCH 18/23] changed cache type --- .../tjbot/commands/help/HelpThreadActivityUpdater.java | 5 +++-- .../togetherjava/tjbot/commands/help/HelpThreadCommand.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index a1b29eafc7..94cfafee72 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -39,7 +39,7 @@ public final class HelpThreadActivityUpdater implements Routine { private final HelpSystemHelper helper; - public static final Cache manuallyResetChannelActivityCache = + public static final Cache manuallyResetChannelActivityCache = Caffeine.newBuilder() .maximumSize(1_000) .expireAfterWrite(PERSIST_DURATION_VALUE, TimeUnit.of(PERSIST_DURATION_UNIT)) @@ -90,7 +90,8 @@ private void updateActivityForThread(ThreadChannel threadChannel) { private static RestAction determineActivity( MessageChannel channel) { - String mostRecentMessageId = manuallyResetChannelActivityCache.getIfPresent(channel); + String mostRecentMessageId = + manuallyResetChannelActivityCache.getIfPresent(channel.getIdLong()); RestAction> restActionMessages; if (mostRecentMessageId != null) { 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 b65e3033e9..bba200c472 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 @@ -197,7 +197,7 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT .setColor(HelpSystemHelper.AMBIENT_COLOR) .build(); - manuallyResetChannelActivityCache.invalidate(helpThread); + manuallyResetChannelActivityCache.invalidate(helpThread.getIdLong()); event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); } @@ -211,7 +211,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel helpThread.getHistory() .retrievePast(1) - .queue(messages -> manuallyResetChannelActivityCache.put(helpThread, + .queue(messages -> manuallyResetChannelActivityCache.put(helpThread.getIdLong(), messages.get(0).getId())); helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); From d96edac94da1f25b4d8b8cdfd740d89608e032dc Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 6 Jan 2023 12:57:38 +0100 Subject: [PATCH 19/23] changed getId to getIdLong and removed line; --- .../commands/help/HelpThreadActivityUpdater.java | 11 +++++------ .../tjbot/commands/help/HelpThreadCommand.java | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index 94cfafee72..f92f858afc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -39,11 +39,10 @@ public final class HelpThreadActivityUpdater implements Routine { private final HelpSystemHelper helper; - public static final Cache manuallyResetChannelActivityCache = - Caffeine.newBuilder() - .maximumSize(1_000) - .expireAfterWrite(PERSIST_DURATION_VALUE, TimeUnit.of(PERSIST_DURATION_UNIT)) - .build(); + public static final Cache manuallyResetChannelActivityCache = Caffeine.newBuilder() + .maximumSize(1_000) + .expireAfterWrite(PERSIST_DURATION_VALUE, TimeUnit.of(PERSIST_DURATION_UNIT)) + .build(); /** * Creates a new instance. @@ -90,7 +89,7 @@ private void updateActivityForThread(ThreadChannel threadChannel) { private static RestAction determineActivity( MessageChannel channel) { - String mostRecentMessageId = + Long mostRecentMessageId = manuallyResetChannelActivityCache.getIfPresent(channel.getIdLong()); RestAction> restActionMessages; 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 bba200c472..06c3432710 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 @@ -197,7 +197,6 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT .setColor(HelpSystemHelper.AMBIENT_COLOR) .build(); - manuallyResetChannelActivityCache.invalidate(helpThread.getIdLong()); event.replyEmbeds(embed).flatMap(any -> helpThread.getManager().setArchived(true)).queue(); } @@ -212,7 +211,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel helpThread.getHistory() .retrievePast(1) .queue(messages -> manuallyResetChannelActivityCache.put(helpThread.getIdLong(), - messages.get(0).getId())); + messages.get(0).getIdLong())); helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); event.reply("Activities have been reset.").queue(); From e2d7d3a2a4c4ab65eda7057abb4c60ca34970f4d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 9 Jan 2023 19:52:15 +0100 Subject: [PATCH 20/23] resolved code findings; PR #739 --- .../help/HelpThreadActivityUpdater.java | 37 ++++++++++--------- .../commands/help/HelpThreadCommand.java | 10 ++--- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index f92f858afc..72da69be0c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -34,14 +34,12 @@ public final class HelpThreadActivityUpdater implements Routine { private static final Logger logger = LoggerFactory.getLogger(HelpThreadActivityUpdater.class); private static final int SCHEDULE_MINUTES = 30; private static final int ACTIVITY_DETERMINE_MESSAGE_LIMIT = 11; - private static final int PERSIST_DURATION_VALUE = 12; - private static final ChronoUnit PERSIST_DURATION_UNIT = ChronoUnit.HOURS; - + private static final int CACHE_LIFETIME = 12; + private static final ChronoUnit CACHE_LIFETIME_UNIT = ChronoUnit.HOURS; private final HelpSystemHelper helper; - public static final Cache manuallyResetChannelActivityCache = Caffeine.newBuilder() .maximumSize(1_000) - .expireAfterWrite(PERSIST_DURATION_VALUE, TimeUnit.of(PERSIST_DURATION_UNIT)) + .expireAfterWrite(CACHE_LIFETIME, TimeUnit.of(CACHE_LIFETIME_UNIT)) .build(); /** @@ -89,18 +87,7 @@ private void updateActivityForThread(ThreadChannel threadChannel) { private static RestAction determineActivity( MessageChannel channel) { - Long mostRecentMessageId = - manuallyResetChannelActivityCache.getIfPresent(channel.getIdLong()); - RestAction> restActionMessages; - - if (mostRecentMessageId != null) { - MessageHistory.MessageRetrieveAction historyAfter = - channel.getHistoryAfter(mostRecentMessageId, ACTIVITY_DETERMINE_MESSAGE_LIMIT); - restActionMessages = historyAfter.map(MessageHistory::getRetrievedHistory); - } else { - restActionMessages = - channel.getHistory().retrievePast(ACTIVITY_DETERMINE_MESSAGE_LIMIT); - } + RestAction> restActionMessages = getRelevantHistory(channel); return restActionMessages.map(messages -> { if (messages.size() >= ACTIVITY_DETERMINE_MESSAGE_LIMIT) { @@ -121,6 +108,22 @@ private static RestAction determineActivity( }); } + private static RestAction> getRelevantHistory(MessageChannel channel) { + Long mostRecentMessageId = + manuallyResetChannelActivityCache.getIfPresent(channel.getIdLong()); + RestAction> restActionMessages; + + if (mostRecentMessageId != null) { + MessageHistory.MessageRetrieveAction historyAfter = + channel.getHistoryAfter(mostRecentMessageId, ACTIVITY_DETERMINE_MESSAGE_LIMIT); + restActionMessages = historyAfter.map(MessageHistory::getRetrievedHistory); + } else { + restActionMessages = + channel.getHistory().retrievePast(ACTIVITY_DETERMINE_MESSAGE_LIMIT); + } + return restActionMessages; + } + private static boolean isBotMessage(Message message) { return message.getAuthor().equals(message.getJDA().getSelfUser()); } 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 06c3432710..518789c75b 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 @@ -203,15 +203,11 @@ private void closeThread(SlashCommandInteractionEvent event, ThreadChannel helpT private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel helpThread) { refreshCooldownFor(Subcommand.RESET_ACTIVITY, helpThread); - if (!event.getMember().equals(helpThread.getOwner())) { - event.reply("Only the thread creator can reset activities.").queue(); - return; - } - helpThread.getHistory() .retrievePast(1) - .queue(messages -> manuallyResetChannelActivityCache.put(helpThread.getIdLong(), - messages.get(0).getIdLong())); + .map(messages -> messages.get(0)) + .queue(lastMessage -> manuallyResetChannelActivityCache.put(helpThread.getIdLong(), + lastMessage.getIdLong())); helper.changeChannelActivity(helpThread, HelpSystemHelper.ThreadActivity.LOW); event.reply("Activities have been reset.").queue(); From dd339a8149573e1463699ff5040d2f042962a614 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 10 Jan 2023 08:21:20 +0100 Subject: [PATCH 21/23] resolved code findings #2; PR #739 --- .../tjbot/commands/help/HelpThreadActivityUpdater.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index 72da69be0c..a0bf8f184b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -87,9 +87,8 @@ private void updateActivityForThread(ThreadChannel threadChannel) { private static RestAction determineActivity( MessageChannel channel) { - RestAction> restActionMessages = getRelevantHistory(channel); - return restActionMessages.map(messages -> { + return getRelevantHistory(channel).map(messages -> { if (messages.size() >= ACTIVITY_DETERMINE_MESSAGE_LIMIT) { // There are likely even more messages, but we hit the limit return HelpSystemHelper.ThreadActivity.HIGH; From ae2d56223d125cebf0180d6d2908525e51108300 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 13 Jan 2023 14:54:26 +0100 Subject: [PATCH 22/23] resolved code findings #3; PR #739 --- .../help/HelpThreadActivityUpdater.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java index a0bf8f184b..5cf11b83b8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/help/HelpThreadActivityUpdater.java @@ -34,12 +34,13 @@ public final class HelpThreadActivityUpdater implements Routine { private static final Logger logger = LoggerFactory.getLogger(HelpThreadActivityUpdater.class); private static final int SCHEDULE_MINUTES = 30; private static final int ACTIVITY_DETERMINE_MESSAGE_LIMIT = 11; - private static final int CACHE_LIFETIME = 12; - private static final ChronoUnit CACHE_LIFETIME_UNIT = ChronoUnit.HOURS; + private static final int CHANNEL_ACTIVITY_CACHE_LIFETIME = 12; + private static final ChronoUnit CHANNEL_ACTIVITY_CACHE_LIFETIME_UNIT = ChronoUnit.HOURS; private final HelpSystemHelper helper; public static final Cache manuallyResetChannelActivityCache = Caffeine.newBuilder() .maximumSize(1_000) - .expireAfterWrite(CACHE_LIFETIME, TimeUnit.of(CACHE_LIFETIME_UNIT)) + .expireAfterWrite(CHANNEL_ACTIVITY_CACHE_LIFETIME, + TimeUnit.of(CHANNEL_ACTIVITY_CACHE_LIFETIME_UNIT)) .build(); /** @@ -110,17 +111,11 @@ private static RestAction determineActivity( private static RestAction> getRelevantHistory(MessageChannel channel) { Long mostRecentMessageId = manuallyResetChannelActivityCache.getIfPresent(channel.getIdLong()); - RestAction> restActionMessages; - - if (mostRecentMessageId != null) { - MessageHistory.MessageRetrieveAction historyAfter = - channel.getHistoryAfter(mostRecentMessageId, ACTIVITY_DETERMINE_MESSAGE_LIMIT); - restActionMessages = historyAfter.map(MessageHistory::getRetrievedHistory); - } else { - restActionMessages = - channel.getHistory().retrievePast(ACTIVITY_DETERMINE_MESSAGE_LIMIT); - } - return restActionMessages; + + return mostRecentMessageId != null + ? channel.getHistoryAfter(mostRecentMessageId, ACTIVITY_DETERMINE_MESSAGE_LIMIT) + .map(MessageHistory::getRetrievedHistory) + : channel.getHistory().retrievePast(ACTIVITY_DETERMINE_MESSAGE_LIMIT); } private static boolean isBotMessage(Message message) { From 895d487bd03d7df6a8fbb38490b6015397394cb8 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Jan 2023 19:11:18 +0100 Subject: [PATCH 23/23] resolved code findings #4; changed description text for reset activity command PR #739 --- .../togetherjava/tjbot/commands/help/HelpThreadCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 518789c75b..675c03c092 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 @@ -222,7 +222,8 @@ enum Subcommand { Cooldown.YES), CHANGE_TITLE(CHANGE_TITLE_SUBCOMMAND, "Change the title of this help thread", Cooldown.YES), CLOSE(CLOSE_SUBCOMMAND, "Close this help thread", Cooldown.YES), - RESET_ACTIVITY(RESET_ACTIVITY_SUBCOMMAND, "Resets the activity in a help thread", + RESET_ACTIVITY(RESET_ACTIVITY_SUBCOMMAND, + "Resets the activity indicator, use if help is still needed, but the indicator shows otherwise", Cooldown.YES); private final String commandName;