aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-24 13:11:56 -0800
committerGravatar MarkKoz <[email protected]>2020-03-22 15:54:35 -0700
commitdb482932088a3d648079cf1b04e0dc89f2602105 (patch)
treeaf1e0d14c40a93a91e80fca73147ff1e17d1bd33
parentHelpChannels: only yield text channels from a category (diff)
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.
-rw-r--r--bot/cogs/help_channels.py17
1 files 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."""