diff options
| author | 2020-02-24 14:55:13 -0800 | |
|---|---|---|
| committer | 2020-03-22 15:54:35 -0700 | |
| commit | cef96afb64d0456e1b60b9be68fb0352bd0191a1 (patch) | |
| tree | 7948954be960e0185b75fb4ed5375ff99d031aaf | |
| parent | Constants: add a named tuple for scheduled task data (diff) | |
HelpChannels: implement move_idle_channels
Make all in-use channels dormant if idle or schedule the move if still
active. This is intended to clean up the in-use channels when the bot
restarts and has lost the tasks it had scheduled in another life.
| -rw-r--r-- | bot/cogs/help_channels.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index c440d166c..c8c437145 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -162,7 +162,16 @@ class HelpChannels(Scheduler, commands.Cog): self.ready.set() async def move_idle_channels(self) -> None: - """Make all idle in-use channels dormant.""" + """Make all in-use channels dormant if idle or schedule the move if still active.""" + idle_seconds = constants.HelpChannels.idle_minutes * 60 + + for channel in self.get_category_channels(self.in_use_category): + time_elapsed = await self.get_idle_time(channel) + if time_elapsed > idle_seconds: + await self.move_to_dormant(channel) + else: + data = ChannelTimeout(channel, idle_seconds - time_elapsed) + self.schedule_task(self.bot.loop, channel.id, data) async def move_to_available(self) -> None: """Make a channel available.""" |