From db482932088a3d648079cf1b04e0dc89f2602105 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Mon, 24 Feb 2020 13:11:56 -0800 Subject: HelpChannels: implement create_channel_queue It returns a queue of dormant channels in random order. The queue will be used to get the next available channel. Using a random order is simpler than trying to sort by the timestamp of the most recent message in each channel and this decision will only "negatively" impact the system when the bot restarts or the extension is reloaded. Ultimately, it just means in such events some dormant channels may chosen to become active again sooner than expected. --- bot/cogs/help_channels.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index f7af5d3be..3d7ece909 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -1,6 +1,7 @@ import asyncio import json import logging +import random import typing as t from collections import deque from pathlib import Path @@ -64,8 +65,20 @@ class HelpChannels(Scheduler, commands.Cog): """Cancel the init task if the cog unloads.""" self.init_task.cancel() - async def create_channel_queue(self) -> asyncio.Queue: - """Return a queue of dormant channels to use for getting the next available channel.""" + def create_channel_queue(self) -> asyncio.Queue: + """ + Return a queue of dormant channels to use for getting the next available channel. + + The channels are added to the queue in a random order. + """ + channels = list(self.get_category_channels(self.dormant_category)) + random.shuffle(channels) + + queue = asyncio.Queue() + for channel in channels: + queue.put_nowait(channel) + + return queue async def create_dormant(self) -> discord.TextChannel: """Create and return a new channel in the Dormant category.""" -- cgit v1.2.3