aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-29 07:51:24 -0800
committerGravatar MarkKoz <[email protected]>2020-03-22 15:54:39 -0700
commit37ec93d8eaf255ff9c118469d8a86231c9427680 (patch)
tree2eaa6762ba3c8664f3fc0aff08cd157a420588e2
parentConstants: add constant for max total help channels (diff)
HelpChannels: move reading of element names to a function
Makes it easier to test.
-rw-r--r--bot/cogs/help_channels.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index 67bd1ab35..0c6c48914 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -45,11 +45,6 @@ question to maximize your chance of getting a good answer. If you're not sure ho
through [our guide for asking a good question]({ASKING_GUIDE_URL}).
"""
-with Path("bot/resources/elements.json").open(encoding="utf-8") as elements_file:
- # Discord has a hard limit of 50 channels per category.
- # Easiest way to prevent more channels from being created is to limit the names available.
- ELEMENTS = json.load(elements_file)[:50]
-
class ChannelTimeout(t.NamedTuple):
"""Data for a task scheduled to make a channel dormant."""
@@ -102,6 +97,8 @@ class HelpChannels(Scheduler, commands.Cog):
self.channel_queue: asyncio.Queue[discord.TextChannel] = None
self.name_queue: t.Deque[str] = None
+ self.elements = self.get_names()
+
self.ready = asyncio.Event()
self.on_message_lock = asyncio.Lock()
self.init_task = self.bot.loop.create_task(self.init_cog())
@@ -160,7 +157,7 @@ class HelpChannels(Scheduler, commands.Cog):
used_names = self.get_used_names()
log.trace("Determining the available names.")
- available_names = (name for name in ELEMENTS if name not in used_names)
+ available_names = (name for name in self.elements if name not in used_names)
log.trace("Populating the name queue with names.")
return deque(available_names)
@@ -207,6 +204,14 @@ class HelpChannels(Scheduler, commands.Cog):
if channel.category_id == category.id and isinstance(channel, discord.TextChannel):
yield channel
+ @staticmethod
+ def get_names() -> t.List[str]:
+ """Return a list of element names."""
+ with Path("bot/resources/elements.json").open(encoding="utf-8") as elements_file:
+ # Discord has a hard limit of 50 channels per category.
+ # Easiest way to prevent more channels from being created is to limit available names.
+ return json.load(elements_file)[:50]
+
def get_used_names(self) -> t.Set[str]:
"""Return channels names which are already being used."""
log.trace("Getting channel names which are already being used.")