aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/__init__.py6
-rw-r--r--bot/exts/evergreen/pfp_modify.py9
-rw-r--r--bot/group.py18
3 files changed, 30 insertions, 3 deletions
diff --git a/bot/__init__.py b/bot/__init__.py
index c8550537..d0992912 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -10,6 +10,7 @@ from discord.ext import commands
from bot.command import Command
from bot.constants import Client
+from bot.group import Group
# Configure the "TRACE" logging level (e.g. "log.trace(message)")
@@ -75,7 +76,10 @@ if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
-# Monkey-patch discord.py decorators to use the Command subclass which supports root aliases.
+# Monkey-patch discord.py decorators to use the both the Command and Group subclasses which supports root aliases.
# Must be patched before any cogs are added.
commands.command = partial(commands.command, cls=Command)
commands.GroupMixin.command = partialmethod(commands.GroupMixin.command, cls=Command)
+
+commands.group = partial(commands.group, cls=Group)
+commands.GroupMixin.group = partialmethod(commands.GroupMixin.group, cls=Group)
diff --git a/bot/exts/evergreen/pfp_modify.py b/bot/exts/evergreen/pfp_modify.py
index a3f7e3f8..8a3eb77c 100644
--- a/bot/exts/evergreen/pfp_modify.py
+++ b/bot/exts/evergreen/pfp_modify.py
@@ -173,7 +173,7 @@ class PfpModify(commands.Cog):
await ctx.send(file=file, embed=embed)
- @pfp_modify.command(pass_context=True, aliases=["easterify"])
+ @pfp_modify.command(pass_context=True, aliases=["easterify"], root_aliases=("easterify", "avatareasterify"))
async def avatareasterify(self, ctx: commands.Context, *colours: t.Union[discord.Colour, str]) -> None:
"""
This "Easterifies" the user's avatar.
@@ -249,7 +249,11 @@ class PfpModify(commands.Cog):
await ctx.send(file=file, embed=embed)
- @pfp_modify.group(aliases=["avatarpride", "pridepfp", "prideprofile"], invoke_without_command=True)
+ @pfp_modify.group(
+ aliases=["avatarpride", "pridepfp", "prideprofile"],
+ root_aliases=("prideavatar", "avatarpride", "pridepfp", "prideprofile"),
+ invoke_without_command=True
+ )
async def prideavatar(self, ctx: commands.Context, option: str = "lgbt", pixels: int = 64) -> None:
"""
This surrounds an avatar with a border of a specified LGBT flag.
@@ -310,6 +314,7 @@ class PfpModify(commands.Cog):
@pfp_modify.command(
name='savatar',
aliases=('spookyavatar', 'spookify'),
+ root_aliases=('spookyavatar', 'spookify'),
brief='Spookify an user\'s avatar.'
)
async def spooky_avatar(self, ctx: commands.Context, user: discord.Member = None) -> None:
diff --git a/bot/group.py b/bot/group.py
new file mode 100644
index 00000000..77092adf
--- /dev/null
+++ b/bot/group.py
@@ -0,0 +1,18 @@
+from discord.ext import commands
+
+
+class Group(commands.Group):
+ """
+ A `discord.ext.commands.Group` subclass which supports root aliases.
+
+ A `root_aliases` keyword argument is added, which is a sequence of alias names that will act as
+ top-level commands rather than being aliases of the command's group. It's stored as an attribute
+ also named `root_aliases`.
+ """
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.root_aliases = kwargs.get("root_aliases", [])
+
+ if not isinstance(self.root_aliases, (list, tuple)):
+ raise TypeError("Root aliases of a command must be a list or a tuple of strings.")