diff options
-rw-r--r-- | bot/cogs/help_channels.py | 18 | ||||
-rw-r--r-- | config-default.yml | 4 |
2 files changed, 17 insertions, 5 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index d826463af..5ecf40e54 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -737,9 +737,21 @@ class HelpChannels(commands.Cog): self.scheduler.schedule_later(delay, msg.channel.id, self.move_idle_channel(msg.channel)) async def is_empty(self, channel: discord.TextChannel) -> bool: - """Return True if the most recent message in `channel` is the bot's `AVAILABLE_MSG`.""" - msg = await self.get_last_message(channel) - return self.match_bot_embed(msg, AVAILABLE_MSG) + """Return True if there's an AVAILABLE_MSG and the messages leading up are bot messages.""" + found = False + + # A limit of 100 results in a single API call. + # If AVAILABLE_MSG isn't found within 100 messages, then assume the channel is not empty. + # Not gonna do an extensive search for it cause it's too expensive. + async for msg in channel.history(limit=100): + if not msg.author.bot: + return False + + if self.match_bot_embed(msg, AVAILABLE_MSG): + found = True + break + + return found async def check_cooldowns(self) -> None: """Remove expired cooldowns and re-schedule active ones.""" diff --git a/config-default.yml b/config-default.yml index aacbe170f..4bd90511c 100644 --- a/config-default.yml +++ b/config-default.yml @@ -432,8 +432,8 @@ help_channels: # Allowed duration of inactivity before making a channel dormant idle_minutes: 30 - # Allowed duration of inactivity when question message deleted - # and no one other sent before message making channel dormant. + # Allowed duration of inactivity when channel is empty (due to deleted messages) + # before message making a channel dormant deleted_idle_minutes: 5 # Maximum number of channels to put in the available category |