|
8 | 8 | import net.dv8tion.jda.api.entities.MessageEmbed; |
9 | 9 | import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; |
10 | 10 | import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; |
11 | | -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; |
12 | 11 | import net.dv8tion.jda.api.requests.RestAction; |
13 | 12 | import net.dv8tion.jda.api.utils.TimeUtil; |
14 | 13 | import org.slf4j.Logger; |
@@ -70,58 +69,57 @@ private void autoArchiveForGuild(Guild guild) { |
70 | 69 | logger.debug("Found {} active questions", activeThreads.size()); |
71 | 70 |
|
72 | 71 | Instant archiveAfterMoment = computeArchiveAfterMoment(); |
73 | | - activeThreads |
74 | | - .forEach(activeThread -> autoArchiveForThread(activeThread, archiveAfterMoment)); |
| 72 | + activeThreads.stream() |
| 73 | + .filter(activeThread -> shouldBeArchived(activeThread, archiveAfterMoment)) |
| 74 | + .forEach(this::autoArchiveForThread); |
75 | 75 | } |
76 | 76 |
|
77 | 77 | private Instant computeArchiveAfterMoment() { |
78 | 78 | return Instant.now().minus(ARCHIVE_AFTER_INACTIVITY_OF); |
79 | 79 | } |
80 | 80 |
|
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()); |
84 | 83 |
|
85 | | - String linkHowToAsk = "https://stackoverflow.com/help/how-to-ask"; |
| 84 | + String linkHowToAsk = "https://stackoverflow.com/help/how-to-ask"; |
86 | 85 |
|
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. |
91 | 90 |
|
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. |
94 | 93 |
|
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. |
98 | 97 |
|
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. |
104 | 103 |
|
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. |
110 | 109 |
|
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(); |
115 | 114 |
|
116 | | - handleArchiveFlow(threadChannel, embed); |
117 | | - } |
| 115 | + handleArchiveFlow(threadChannel, embed); |
118 | 116 | } |
119 | 117 |
|
120 | | - private static boolean shouldBeArchived(MessageChannel channel, Instant archiveAfterMoment) { |
| 118 | + private static boolean shouldBeArchived(ThreadChannel channel, Instant archiveAfterMoment) { |
121 | 119 | Instant lastActivity = |
122 | 120 | TimeUtil.getTimeCreated(channel.getLatestMessageIdLong()).toInstant(); |
123 | 121 |
|
124 | | - return lastActivity.isBefore(archiveAfterMoment); |
| 122 | + return !channel.isPinned() && lastActivity.isBefore(archiveAfterMoment); |
125 | 123 | } |
126 | 124 |
|
127 | 125 | private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed) { |
|
0 commit comments