Hide empty cogs

pull/132/head
stijndcl 2022-09-19 17:50:33 +02:00
parent 7035f0773f
commit 5d2d7c49c2
1 changed files with 21 additions and 10 deletions

View File

@ -143,7 +143,7 @@ class CustomHelpCommand(commands.MinimalHelpCommand):
embed = discord.Embed(title=title.title(), colour=discord.Colour.blue()) embed = discord.Embed(title=title.title(), colour=discord.Colour.blue())
return embed return embed
def _clean_command_help(self, command: commands.Command) -> str: def _clean_command_doc(self, command: commands.Command) -> str:
"""Clean up a help docstring """Clean up a help docstring
This will strip out single newlines, because these are only there for readability and line length. This will strip out single newlines, because these are only there for readability and line length.
@ -170,7 +170,7 @@ class CustomHelpCommand(commands.MinimalHelpCommand):
This allows re-using this logic for Group commands that can be invoked by themselves. This allows re-using this logic for Group commands that can be invoked by themselves.
""" """
embed.description = self._clean_command_help(command) embed.description = self._clean_command_doc(command)
signature = self.get_command_signature(command) signature = self.get_command_signature(command)
embed.add_field(name="Signature", value=signature, inline=False) embed.add_field(name="Signature", value=signature, inline=False)
@ -188,16 +188,27 @@ class CustomHelpCommand(commands.MinimalHelpCommand):
async def _filter_cogs(self, cogs: list[commands.Cog]) -> list[commands.Cog]: async def _filter_cogs(self, cogs: list[commands.Cog]) -> list[commands.Cog]:
"""Filter the list of cogs down to all those that the user can see""" """Filter the list of cogs down to all those that the user can see"""
async def _predicate(cog: Optional[commands.Cog]) -> bool:
if cog is None:
return False
# Remove cogs that we never want to see in the help page because they # Remove cogs that we never want to see in the help page because they
# don't contain commands # don't contain commands, or shouldn't be visible at all
filtered_cogs = list( if not cog.get_commands():
filter(lambda cog: cog is not None and cog.qualified_name.lower() not in ("tasks", "debugcog"), cogs) return False
)
# Remove owner-only cogs for people that shouldn't see them if cog.qualified_name.lower() in ("tasks", "debugcog"):
return False
# Hide owner-only cogs if you're not the owner
if not await self.context.bot.is_owner(self.context.author): if not await self.context.bot.is_owner(self.context.author):
filtered_cogs = list(filter(lambda cog: cog.qualified_name.lower() not in ("owner",), filtered_cogs)) return cog.qualified_name.lower() not in ("owner",)
return True
# Filter list of cogs down
filtered_cogs = [cog for cog in cogs if await _predicate(cog)]
return list(sorted(filtered_cogs, key=lambda cog: cog.qualified_name)) return list(sorted(filtered_cogs, key=lambda cog: cog.qualified_name))