diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadAutoArchiver.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadAutoArchiver.java index 1dd6053562..4b0b6a317a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadAutoArchiver.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadAutoArchiver.java @@ -8,7 +8,6 @@ import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.utils.TimeUtil; import org.slf4j.Logger; @@ -70,58 +69,57 @@ private void autoArchiveForGuild(Guild guild) { logger.debug("Found {} active questions", activeThreads.size()); Instant archiveAfterMoment = computeArchiveAfterMoment(); - activeThreads - .forEach(activeThread -> autoArchiveForThread(activeThread, archiveAfterMoment)); + activeThreads.stream() + .filter(activeThread -> shouldBeArchived(activeThread, archiveAfterMoment)) + .forEach(this::autoArchiveForThread); } private Instant computeArchiveAfterMoment() { return Instant.now().minus(ARCHIVE_AFTER_INACTIVITY_OF); } - private void autoArchiveForThread(ThreadChannel threadChannel, Instant archiveAfterMoment) { - if (shouldBeArchived(threadChannel, archiveAfterMoment)) { - logger.debug("Auto archiving help thread {}", threadChannel.getId()); + private void autoArchiveForThread(ThreadChannel threadChannel) { + logger.debug("Auto archiving help thread {}", threadChannel.getId()); - String linkHowToAsk = "https://stackoverflow.com/help/how-to-ask"; + String linkHowToAsk = "https://stackoverflow.com/help/how-to-ask"; - MessageEmbed embed = new EmbedBuilder() - .setDescription( - """ - Your question has been closed due to inactivity. + MessageEmbed embed = new EmbedBuilder() + .setDescription( + """ + Your question has been closed due to inactivity. - If it was not resolved yet, feel free to just post a message below - to reopen it, or create a new thread. + If it was not resolved yet, feel free to just post a message below + to reopen it, or create a new thread. - Note that usually the reason for nobody calling back is that your - question may have been not well asked and hence no one felt confident - enough answering. + Note that usually the reason for nobody calling back is that your + question may have been not well asked and hence no one felt confident + enough answering. - When you reopen the thread, try to use your time to **improve the quality** - of the question by elaborating, providing **details**, context, all relevant code - snippets, any **errors** you are getting, concrete **examples** and perhaps also some - screenshots. Share your **attempt**, explain the **expected results** and compare - them to the current results. + When you reopen the thread, try to use your time to **improve the quality** + of the question by elaborating, providing **details**, context, all relevant code + snippets, any **errors** you are getting, concrete **examples** and perhaps also some + screenshots. Share your **attempt**, explain the **expected results** and compare + them to the current results. - Also try to make the information **easily accessible** by sharing code - or assignment descriptions directly on Discord, not behind a link or - PDF-file; provide some guidance for long code snippets and ensure - the **code is well formatted** and has syntax highlighting. Kindly read through - %s for more. + Also try to make the information **easily accessible** by sharing code + or assignment descriptions directly on Discord, not behind a link or + PDF-file; provide some guidance for long code snippets and ensure + the **code is well formatted** and has syntax highlighting. Kindly read through + %s for more. - With enough info, someone knows the answer for sure 👍""" - .formatted(linkHowToAsk)) - .setColor(HelpSystemHelper.AMBIENT_COLOR) - .build(); + With enough info, someone knows the answer for sure 👍""" + .formatted(linkHowToAsk)) + .setColor(HelpSystemHelper.AMBIENT_COLOR) + .build(); - handleArchiveFlow(threadChannel, embed); - } + handleArchiveFlow(threadChannel, embed); } - private static boolean shouldBeArchived(MessageChannel channel, Instant archiveAfterMoment) { + private static boolean shouldBeArchived(ThreadChannel channel, Instant archiveAfterMoment) { Instant lastActivity = TimeUtil.getTimeCreated(channel.getLatestMessageIdLong()).toInstant(); - return lastActivity.isBefore(archiveAfterMoment); + return !channel.isPinned() && lastActivity.isBefore(archiveAfterMoment); } private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed) {