aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-24 15:08:05 -0800
committerGravatar MarkKoz <[email protected]>2020-03-22 15:54:35 -0700
commit6c57fc1d6581da53394871c9967f7de2fc0ec25f (patch)
tree27e83006ee2681f8cacbf35b4cd328b99a3a2e30
parentHelpChannels: fix creation of queues in init_cog (diff)
HelpChannels: make move_idle_channels only handle a single channel
This function will get re-used in _scheduled_task, but it will only need to move a single channel. Therefore, to promote code re-use, this change was made. The init_cog will instead do a loop to call this on all channels in the in-use category.
-rw-r--r--bot/cogs/help_channels.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index 3757f0581..7fe81d407 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -157,21 +157,22 @@ class HelpChannels(Scheduler, commands.Cog):
self.name_queue = self.create_name_queue()
await self.init_available()
- await self.move_idle_channels()
+
+ for channel in self.get_category_channels(self.in_use_category):
+ await self.move_idle_channel(channel)
self.ready.set()
- async def move_idle_channels(self) -> None:
- """Make all in-use channels dormant if idle or schedule the move if still active."""
+ async def move_idle_channel(self, channel: discord.TextChannel) -> None:
+ """Make the `channel` dormant if idle or schedule the move if still active."""
idle_seconds = constants.HelpChannels.idle_minutes * 60
+ time_elapsed = await self.get_idle_time(channel)
- 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)
+ 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."""