aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-10-19 13:08:05 -0700
committerGravatar MarkKoz <[email protected]>2020-11-20 15:57:09 -0800
commit2eb56e4f863475307eafa070d22e71d061641f6a (patch)
tree947594bc182d27a1bf94c6731e8a917f4516615e
parentHelp channels: remove obsolete function (diff)
Help channels: replace ready event with awaiting the init task
The event is redundant since awaiting the task accomplishes the same thing. If the task is already done, the await will finish immediately. If the task gets cancelled, the error is raised but discord.py suppress it in both commands and event listeners.
-rw-r--r--bot/exts/help_channels/_cog.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index 5c4a0d972..bea1f65e6 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -83,7 +83,6 @@ class HelpChannels(commands.Cog):
# Asyncio stuff
self.queue_tasks: t.List[asyncio.Task] = []
- self.ready = asyncio.Event()
self.on_message_lock = asyncio.Lock()
self.init_task = self.bot.loop.create_task(self.init_cog())
@@ -264,11 +263,9 @@ class HelpChannels(commands.Cog):
self.close_command.enabled = True
await self.init_available()
+ self.report_stats()
log.info("Cog is ready!")
- self.ready.set()
-
- self.report_stats()
def report_stats(self) -> None:
"""Report the channel count stats."""
@@ -439,8 +436,9 @@ class HelpChannels(commands.Cog):
if not is_available or _channel.is_excluded_channel(channel):
return # Ignore messages outside the Available category or in excluded channels.
- log.trace("Waiting for the cog to be ready before processing messages.")
- await self.ready.wait()
+ if not self.init_task.done():
+ log.trace("Waiting for the cog to be ready before processing messages.")
+ await self.init_task
log.trace("Acquiring lock to prevent a channel from being processed twice...")
async with self.on_message_lock: