From 100a903d6604ac019adff0d4e197a092be2f273f Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Sat, 11 Apr 2020 10:28:47 -0700 Subject: HelpChannels: create a helper method for checking a chann --- bot/cogs/help_channels.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 797019f69..d91f3f91f 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -521,7 +521,8 @@ class HelpChannels(Scheduler, commands.Cog): return # Ignore messages sent by bots. channel = message.channel - if channel.category and channel.category.id != constants.Categories.help_available: + category = getattr(channel, "category", None) + if category and 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.") @@ -531,7 +532,8 @@ class HelpChannels(Scheduler, commands.Cog): async with self.on_message_lock: log.trace(f"on_message lock acquired for {message.id}.") - if channel.category and channel.category.id != constants.Categories.help_available: + category = getattr(channel, "category", None) + if category and 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." -- cgit v1.2.3 From 8249ea49144123a81f33163e266691e465c6fd77 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Sat, 11 Apr 2020 10:37:43 -0700 Subject: HelpChannels: create helper method for checking channel's category --- bot/cogs/help_channels.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index d91f3f91f..56caa60af 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -376,6 +376,12 @@ class HelpChannels(Scheduler, commands.Cog): embed = message.embeds[0] return embed.description.strip() == DORMANT_MSG.strip() + @staticmethod + def is_in_category(channel: discord.TextChannel, category_id: int) -> bool: + """Return True if `channel` is within a category with `category_id`.""" + actual_category = getattr(channel, "category", None) + return actual_category and actual_category.id == category_id + async def move_idle_channel(self, channel: discord.TextChannel, has_task: bool = True) -> None: """ Make the `channel` dormant if idle or schedule the move if still active. @@ -521,8 +527,7 @@ class HelpChannels(Scheduler, commands.Cog): return # Ignore messages sent by bots. channel = message.channel - category = getattr(channel, "category", None) - if category and category.id != constants.Categories.help_available: + if not self.is_in_category(channel, constants.Categories.help_available): return # Ignore messages outside the Available category. log.trace("Waiting for the cog to be ready before processing messages.") @@ -532,8 +537,7 @@ class HelpChannels(Scheduler, commands.Cog): async with self.on_message_lock: log.trace(f"on_message lock acquired for {message.id}.") - category = getattr(channel, "category", None) - if category and category.id != constants.Categories.help_available: + if not self.is_in_category(channel, 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." -- cgit v1.2.3 From 27ed536350640fd1ce3fee5c21cfa6b495b4793e Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Apr 2020 10:09:23 -0700 Subject: HelpChannels: ensure `is_in_category` returns a bool Co-Authored-By: kwzrd <44734341+kwzrd@users.noreply.github.com> --- bot/cogs/help_channels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 56caa60af..170812d1b 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -380,7 +380,7 @@ class HelpChannels(Scheduler, commands.Cog): def is_in_category(channel: discord.TextChannel, category_id: int) -> bool: """Return True if `channel` is within a category with `category_id`.""" actual_category = getattr(channel, "category", None) - return actual_category and actual_category.id == category_id + return actual_category is not None and actual_category.id == category_id async def move_idle_channel(self, channel: discord.TextChannel, has_task: bool = True) -> None: """ -- cgit v1.2.3