Skip to content

Commit ed47eff

Browse files
committed
Added isInactive()
1 parent f5c25d0 commit ed47eff

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/free/FreeHelpChannelsRoutine.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.togetherjava.tjbot.commands.free;
22

33
import net.dv8tion.jda.api.JDA;
4+
import net.dv8tion.jda.api.entities.TextChannel;
45
import net.dv8tion.jda.api.utils.TimeUtil;
56
import org.jetbrains.annotations.NotNull;
67
import 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

Comments
 (0)