diff options
| author | 2020-02-24 12:18:00 -0800 | |
|---|---|---|
| committer | 2020-03-22 15:54:34 -0700 | |
| commit | 2cb8db6172a0c273f2b5768483ecfc42edc8ef9c (patch) | |
| tree | 1fd5a74f0849fd16e505a536af6599dd2455a028 | |
| parent | HelpChannels: add a function to get a channel or fetch it from API (diff) | |
HelpChannels: add a function to init the categories
As the categories are essential for the functionality of the cog, if
this function fails to get a category, it will remove/unload the cog.
| -rw-r--r-- | bot/cogs/help_channels.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 5f5129149..5ca16fd41 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -49,6 +49,10 @@ class HelpChannels(Scheduler, commands.Cog): self.bot = bot + self.available_category: discord.CategoryChannel = None + self.in_use_category: discord.CategoryChannel = None + self.dormant_category: discord.CategoryChannel = None + async def create_channel_queue(self) -> asyncio.Queue: """Return a queue of dormant channels to use for getting the next available channel.""" @@ -71,6 +75,18 @@ class HelpChannels(Scheduler, commands.Cog): async def init_available(self) -> None: """Initialise the Available category with channels.""" + async def init_categories(self) -> None: + """Get the help category objects. Remove the cog if retrieval fails.""" + try: + self.available_category = await self.try_get_channel( + constants.Categories.help_available + ) + self.in_use_category = await self.try_get_channel(constants.Categories.help_in_use) + self.dormant_category = await self.try_get_channel(constants.Categories.help_dormant) + except discord.HTTPException: + log.exception(f"Failed to get a category; cog will be removed") + self.bot.remove_cog(self.qualified_name) + async def move_idle_channels(self) -> None: """Make all idle in-use channels dormant.""" |