24
24
import java .util .Optional ;
25
25
import java .util .concurrent .TimeUnit ;
26
26
import java .util .function .Function ;
27
- import java .util .function .Supplier ;
28
27
29
28
/**
30
29
* Routine, which periodically checks all help threads and archives them if there has not been any
31
30
* recent activity.
32
31
*/
33
32
public final class HelpThreadAutoArchiver implements Routine {
34
33
private static final Logger logger = LoggerFactory .getLogger (HelpThreadAutoArchiver .class );
35
- private static final int SCHEDULE_MINUTES = 60 ;
36
- private static final Duration ARCHIVE_AFTER_INACTIVITY_OF = Duration .ofHours ( 12 );
34
+ private static final int SCHEDULE_MINUTES = 6 ;
35
+ private static final Duration ARCHIVE_AFTER_INACTIVITY_OF = Duration .ofSeconds ( 60 );
37
36
38
37
private final HelpSystemHelper helper ;
39
38
@@ -48,7 +47,7 @@ public HelpThreadAutoArchiver(HelpSystemHelper helper) {
48
47
49
48
@ Override
50
49
public Schedule createSchedule () {
51
- return new Schedule (ScheduleMode .FIXED_RATE , 0 , SCHEDULE_MINUTES , TimeUnit .MINUTES );
50
+ return new Schedule (ScheduleMode .FIXED_RATE , 0 , SCHEDULE_MINUTES , TimeUnit .SECONDS );
52
51
}
53
52
54
53
@ Override
@@ -128,18 +127,6 @@ private static boolean shouldBeArchived(MessageChannel channel, Instant archiveA
128
127
129
128
private void handleArchiveFlow (ThreadChannel threadChannel , MessageEmbed embed ) {
130
129
131
- Supplier <RestAction <Void >> archiveThread =
132
- () -> threadChannel .getManager ().setArchived (true );
133
-
134
- Function <Throwable , RestAction <Void >> handleFailure = error -> {
135
- if (error instanceof ErrorResponseException ) {
136
- logger .warn (
137
- "Unknown error occurred during help thread auto archive routine, archiving thread" ,
138
- error );
139
- }
140
- return archiveThread .get ();
141
- };
142
-
143
130
Function <Result <Member >, RestAction <Message >> sendEmbedWithMention =
144
131
member -> threadChannel .sendMessage (member .get ().getAsMention ()).addEmbeds (embed );
145
132
@@ -159,11 +146,12 @@ private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed)
159
146
})
160
147
.mapToResult ()
161
148
.flatMap (sentEmbed -> {
162
- if (sentEmbed .isSuccess ()) {
163
- return archiveThread .get ();
149
+ if (sentEmbed .getFailure () instanceof ErrorResponseException ) {
150
+ logger .warn (
151
+ "Unknown error occurred during help thread auto archive routine, archiving thread" ,
152
+ sentEmbed .getFailure ());
164
153
}
165
-
166
- return handleFailure .apply (sentEmbed .getFailure ());
154
+ return threadChannel .getManager ().setArchived (true );
167
155
})
168
156
.queue ();
169
157
}
0 commit comments