From 021fcbb20816f2031c9b190fb0c91d3e9b709b59 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Mon, 24 Feb 2020 15:29:21 -0800 Subject: HelpChannels: implement get_available_candidate Return a dormant channel to turn into an available channel, waiting indefinitely until one becomes available in the queue. --- bot/cogs/help_channels.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 4a34bd37d..99815d4e5 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -117,7 +117,21 @@ class HelpChannels(Scheduler, commands.Cog): """Make the current in-use help channel dormant.""" async def get_available_candidate(self) -> discord.TextChannel: - """Return a dormant channel to turn into an available channel.""" + """ + Return a dormant channel to turn into an available channel. + + If no channel is available, wait indefinitely until one becomes available. + """ + try: + channel = self.channel_queue.get_nowait() + except asyncio.QueueEmpty: + channel = await self.create_dormant() + + if not channel: + # Wait for a channel to become available. + channel = await self.channel_queue.get() + + return channel @staticmethod def get_category_channels(category: discord.CategoryChannel) -> t.Iterable[discord.TextChannel]: -- cgit v1.2.3