Skip to content

Commit 2738a98

Browse files
bug: do not archive pinned threads (resolves #1084) (#1088)
1 parent b097294 commit 2738a98

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadAutoArchiver.java

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import net.dv8tion.jda.api.entities.MessageEmbed;
99
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
1010
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
11-
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
1211
import net.dv8tion.jda.api.requests.RestAction;
1312
import net.dv8tion.jda.api.utils.TimeUtil;
1413
import org.slf4j.Logger;
@@ -70,58 +69,57 @@ private void autoArchiveForGuild(Guild guild) {
7069
logger.debug("Found {} active questions", activeThreads.size());
7170

7271
Instant archiveAfterMoment = computeArchiveAfterMoment();
73-
activeThreads
74-
.forEach(activeThread -> autoArchiveForThread(activeThread, archiveAfterMoment));
72+
activeThreads.stream()
73+
.filter(activeThread -> shouldBeArchived(activeThread, archiveAfterMoment))
74+
.forEach(this::autoArchiveForThread);
7575
}
7676

7777
private Instant computeArchiveAfterMoment() {
7878
return Instant.now().minus(ARCHIVE_AFTER_INACTIVITY_OF);
7979
}
8080

81-
private void autoArchiveForThread(ThreadChannel threadChannel, Instant archiveAfterMoment) {
82-
if (shouldBeArchived(threadChannel, archiveAfterMoment)) {
83-
logger.debug("Auto archiving help thread {}", threadChannel.getId());
81+
private void autoArchiveForThread(ThreadChannel threadChannel) {
82+
logger.debug("Auto archiving help thread {}", threadChannel.getId());
8483

85-
String linkHowToAsk = "https://stackoverflow.com/help/how-to-ask";
84+
String linkHowToAsk = "https://stackoverflow.com/help/how-to-ask";
8685

87-
MessageEmbed embed = new EmbedBuilder()
88-
.setDescription(
89-
"""
90-
Your question has been closed due to inactivity.
86+
MessageEmbed embed = new EmbedBuilder()
87+
.setDescription(
88+
"""
89+
Your question has been closed due to inactivity.
9190
92-
If it was not resolved yet, feel free to just post a message below
93-
to reopen it, or create a new thread.
91+
If it was not resolved yet, feel free to just post a message below
92+
to reopen it, or create a new thread.
9493
95-
Note that usually the reason for nobody calling back is that your
96-
question may have been not well asked and hence no one felt confident
97-
enough answering.
94+
Note that usually the reason for nobody calling back is that your
95+
question may have been not well asked and hence no one felt confident
96+
enough answering.
9897
99-
When you reopen the thread, try to use your time to **improve the quality**
100-
of the question by elaborating, providing **details**, context, all relevant code
101-
snippets, any **errors** you are getting, concrete **examples** and perhaps also some
102-
screenshots. Share your **attempt**, explain the **expected results** and compare
103-
them to the current results.
98+
When you reopen the thread, try to use your time to **improve the quality**
99+
of the question by elaborating, providing **details**, context, all relevant code
100+
snippets, any **errors** you are getting, concrete **examples** and perhaps also some
101+
screenshots. Share your **attempt**, explain the **expected results** and compare
102+
them to the current results.
104103
105-
Also try to make the information **easily accessible** by sharing code
106-
or assignment descriptions directly on Discord, not behind a link or
107-
PDF-file; provide some guidance for long code snippets and ensure
108-
the **code is well formatted** and has syntax highlighting. Kindly read through
109-
%s for more.
104+
Also try to make the information **easily accessible** by sharing code
105+
or assignment descriptions directly on Discord, not behind a link or
106+
PDF-file; provide some guidance for long code snippets and ensure
107+
the **code is well formatted** and has syntax highlighting. Kindly read through
108+
%s for more.
110109
111-
With enough info, someone knows the answer for sure 👍"""
112-
.formatted(linkHowToAsk))
113-
.setColor(HelpSystemHelper.AMBIENT_COLOR)
114-
.build();
110+
With enough info, someone knows the answer for sure 👍"""
111+
.formatted(linkHowToAsk))
112+
.setColor(HelpSystemHelper.AMBIENT_COLOR)
113+
.build();
115114

116-
handleArchiveFlow(threadChannel, embed);
117-
}
115+
handleArchiveFlow(threadChannel, embed);
118116
}
119117

120-
private static boolean shouldBeArchived(MessageChannel channel, Instant archiveAfterMoment) {
118+
private static boolean shouldBeArchived(ThreadChannel channel, Instant archiveAfterMoment) {
121119
Instant lastActivity =
122120
TimeUtil.getTimeCreated(channel.getLatestMessageIdLong()).toInstant();
123121

124-
return lastActivity.isBefore(archiveAfterMoment);
122+
return !channel.isPinned() && lastActivity.isBefore(archiveAfterMoment);
125123
}
126124

127125
private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed) {

0 commit comments

Comments
 (0)