diff options
author | 2020-04-18 00:38:23 +0700 | |
---|---|---|
committer | 2020-04-18 00:38:23 +0700 | |
commit | b7b48d0239afedbec31e8c05c90430a5b635cec0 (patch) | |
tree | afb03f1e773e5412b912bc609d3deaa11e17c4be | |
parent | Merge pull request #874 from ks129/syncer-timeout-fix (diff) | |
parent | Merge branch 'master' into bug/frontend/870/help-channel-dm-category (diff) |
Merge pull request #877 from python-discord/bug/frontend/870/help-channel-dm-category
HelpChannels: fix AttributeError getting a category for a DMChannel
-rw-r--r-- | bot/cogs/help_channels.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 692bb234c..e73bbdae5 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -420,6 +420,12 @@ class HelpChannels(Scheduler, commands.Cog): embed = message.embeds[0] return message.author == self.bot.user and 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 is not None 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. @@ -581,7 +587,7 @@ 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: + 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.") @@ -591,7 +597,7 @@ 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: + 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." |