Skip to content

bug: do not archive pinned threads (resolves #1084) #1088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Loading