1
1
package org .togetherjava .tjbot .commands .free ;
2
2
3
3
import net .dv8tion .jda .api .JDA ;
4
+ import net .dv8tion .jda .api .entities .TextChannel ;
4
5
import net .dv8tion .jda .api .utils .TimeUtil ;
5
6
import org .jetbrains .annotations .NotNull ;
6
7
import org .togetherjava .tjbot .commands .Routine ;
@@ -36,8 +37,7 @@ public void runRoutine(@NotNull JDA jda) {
36
37
.stream ()
37
38
.filter (freeChannelMonitor ::isMonitoringChannel )
38
39
.filter (freeChannelMonitor ::isChannelBusy )
39
- .filter (channel -> TimeUtil .getTimeCreated (channel .getLatestMessageIdLong ())
40
- .isBefore (OffsetDateTime .now ().minusMinutes (INACTIVE_TIME_MINUTES )))
40
+ .filter (this ::isInactive )
41
41
.forEach (channel -> {
42
42
freeChannelMonitor .setChannelFree (channel );
43
43
freeChannelMonitor .displayStatus (channel .getGuild ());
@@ -48,6 +48,16 @@ public void runRoutine(@NotNull JDA jda) {
48
48
});
49
49
}
50
50
51
+ /**
52
+ * Checks if the channel was inactive for more than {@value INACTIVE_TIME_MINUTES} minutes.
53
+ *
54
+ * @param channel the channel to check
55
+ */
56
+ private boolean isInactive (@ NotNull TextChannel channel ) {
57
+ return TimeUtil .getTimeCreated (channel .getLatestMessageIdLong ())
58
+ .isBefore (OffsetDateTime .now ().minusMinutes (INACTIVE_TIME_MINUTES ));
59
+ }
60
+
51
61
@ Override
52
62
public @ NotNull Schedule createSchedule () {
53
63
return new Schedule (ScheduleMode .FIXED_DELAY , 0 , CHECK_INTERVAL_MINUTES , TimeUnit .MINUTES );
0 commit comments