aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-29 14:09:39 -0800
committerGravatar MarkKoz <[email protected]>2020-03-22 15:54:44 -0700
commitb020e375a00ed2924ccd9be964326326a3737d4f (patch)
tree449cbd56cbefccd66662d19782998cc0dd833cf6
parentHelpChannels: include info about claim cooldowns in available message (diff)
HelpChannels: make category checks direct & efficient
Replace retrieval of all channels of a category with a direct comparison of the categories themselves. In the case of the `on_message` listener, the change enables the check to be done before the lock acquisition. This is because it doesn't rely on the channels in the category to be up to date. In fact, it doesn't even need the category object so it can exit early without needing to wait for the cog to be ready.
-rw-r--r--bot/cogs/help_channels.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index 8dd17e936..6ed66b80a 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -179,8 +179,7 @@ class HelpChannels(Scheduler, commands.Cog):
"""Make the current in-use help channel dormant."""
log.trace("dormant command invoked; checking if the channel is in-use.")
- in_use = self.get_category_channels(self.in_use_category)
- if ctx.channel in in_use:
+ if ctx.channel.category == self.in_use_category:
self.cancel_task(ctx.channel.id)
await self.move_to_dormant(ctx.channel)
else:
@@ -506,21 +505,28 @@ class HelpChannels(Scheduler, commands.Cog):
if message.author.bot:
return # Ignore messages sent by bots.
+ channel = message.channel
+ if channel.category and channel.category.id != constants.Categories.help_available:
+ return # Ignore messages outside the Available category.
+
log.trace("Waiting for the cog to be ready before processing messages.")
await self.ready.wait()
log.trace("Acquiring lock to prevent a channel from being processed twice...")
async with self.on_message_lock:
- log.trace("on_message lock acquired.")
- log.trace("Checking if the message was sent in an available channel.")
+ log.trace(f"on_message lock acquired for {message.id}.")
- available_channels = self.get_category_channels(self.available_category)
- if message.channel not in available_channels:
- return # Ignore messages outside the Available category.
+ if channel.category and channel.category.id != constants.Categories.help_available:
+ log.debug(
+ f"Message {message.id} will not make #{channel} ({channel.id}) in-use "
+ f"because another message in the channel already triggered that."
+ )
+ return
- await self.move_to_in_use(message.channel)
+ await self.move_to_in_use(channel)
await self.revoke_send_permissions(message.author)
- log.trace("Releasing on_message lock.")
+
+ log.trace(f"Releasing on_message lock for {message.id}.")
# Move a dormant channel to the Available category to fill in the gap.
# This is done last and outside the lock because it may wait indefinitely for a channel to