11package org .togetherjava .tjbot .commands .free ;
22
33import net .dv8tion .jda .api .JDA ;
4+ import net .dv8tion .jda .api .entities .TextChannel ;
45import net .dv8tion .jda .api .utils .TimeUtil ;
56import org .jetbrains .annotations .NotNull ;
67import org .togetherjava .tjbot .commands .Routine ;
@@ -36,8 +37,7 @@ public void runRoutine(@NotNull JDA jda) {
3637 .stream ()
3738 .filter (freeChannelMonitor ::isMonitoringChannel )
3839 .filter (freeChannelMonitor ::isChannelBusy )
39- .filter (channel -> TimeUtil .getTimeCreated (channel .getLatestMessageIdLong ())
40- .isBefore (OffsetDateTime .now ().minusMinutes (INACTIVE_TIME_MINUTES )))
40+ .filter (this ::isInactive )
4141 .forEach (channel -> {
4242 freeChannelMonitor .setChannelFree (channel );
4343 freeChannelMonitor .displayStatus (channel .getGuild ());
@@ -48,6 +48,16 @@ public void runRoutine(@NotNull JDA jda) {
4848 });
4949 }
5050
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+
5161 @ Override
5262 public @ NotNull Schedule createSchedule () {
5363 return new Schedule (ScheduleMode .FIXED_DELAY , 0 , CHECK_INTERVAL_MINUTES , TimeUnit .MINUTES );
0 commit comments