aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-10-01 18:40:29 -0700
committerGravatar MarkKoz <[email protected]>2019-10-01 19:29:11 -0700
commit2efcc97c107bebe5c5bdc2cc5876743619e35600 (patch)
treee0893a3c17b80d6fc148825214438de72a062b82
parentUse has_active_infraction util function in superstarify (diff)
Add help category for Infractions and ModManagement cogs
The two cogs will be listed under the same category in the help output.
Diffstat (limited to '')
-rw-r--r--bot/cogs/help.py37
-rw-r--r--bot/cogs/moderation/infractions.py1
-rw-r--r--bot/cogs/moderation/management.py1
3 files changed, 31 insertions, 8 deletions
diff --git a/bot/cogs/help.py b/bot/cogs/help.py
index 37d12b2d5..0847e5e17 100644
--- a/bot/cogs/help.py
+++ b/bot/cogs/help.py
@@ -1,5 +1,4 @@
import asyncio
-import inspect
import itertools
from collections import namedtuple
from contextlib import suppress
@@ -107,12 +106,26 @@ class HelpSession:
if command:
return command
- cog = self._bot.cogs.get(query)
- if cog:
+ # Find all cog categories that match.
+ cogs = self._bot.cogs.values()
+ cog_matches = [cog for cog in cogs if hasattr(cog, "category") and cog.category == query]
+
+ # Try to search by cog name if no categories match.
+ if not cog_matches:
+ cog = self._bot.cogs.get(query)
+
+ # Don't consider it a match if the cog has a category.
+ if cog and not hasattr(cog, "category"):
+ cog_matches = [cog]
+
+ if cog_matches:
+ cog = cog_matches[0]
+ cmds = (cog.get_commands() for cog in cog_matches) # Commands of all cogs
+
return Cog(
- name=cog.qualified_name,
- description=inspect.getdoc(cog),
- commands=[c for c in self._bot.commands if c.cog is cog]
+ name=cog.category if hasattr(cog, "category") else cog.qualified_name,
+ description=cog.description,
+ commands=tuple(itertools.chain.from_iterable(cmds)) # Flatten the list
)
self._handle_not_found(query)
@@ -207,8 +220,16 @@ class HelpSession:
A zero width space is used as a prefix for results with no cogs to force them last in ordering.
"""
- cog = cmd.cog_name
- return f'**{cog}**' if cog else f'**\u200bNo Category:**'
+ if cmd.cog:
+ try:
+ if cmd.cog.category:
+ return f'**{cmd.cog.category}**'
+ except AttributeError:
+ pass
+
+ return f'**{cmd.cog_name}**'
+ else:
+ return "**\u200bNo Category:**"
def _get_command_params(self, cmd: Command) -> str:
"""
diff --git a/bot/cogs/moderation/infractions.py b/bot/cogs/moderation/infractions.py
index 5a93745ba..b2b03e46c 100644
--- a/bot/cogs/moderation/infractions.py
+++ b/bot/cogs/moderation/infractions.py
@@ -30,6 +30,7 @@ class Infractions(Scheduler, commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
+ self.category = "Moderation"
self._muted_role = discord.Object(constants.Roles.muted)
super().__init__()
diff --git a/bot/cogs/moderation/management.py b/bot/cogs/moderation/management.py
index 567c4e2df..c4fd3894e 100644
--- a/bot/cogs/moderation/management.py
+++ b/bot/cogs/moderation/management.py
@@ -35,6 +35,7 @@ class ModManagement(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
+ self.category = "Moderation"
@property
def mod_log(self) -> ModLog: