aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-22 13:05:49 -0700
committerGravatar MarkKoz <[email protected]>2020-08-22 20:07:02 -0700
commitee4efbb91300890424d1f8ecb1273166e9f0f53a (patch)
tree7b8c7bbc92e3590ac8f680904a5d5d5812705985
parentDisable raw commands (diff)
Define a Command subclass with root alias support
A subclass is used because cogs make copies of Command objects. They do this to allow multiple instances of a cog to be used. If the Command class doesn't inherently support the `root_aliases` kwarg, it won't end up being copied when a command gets copied. `Command.__original_kwargs__` could be updated to include the new kwarg. However, updating it and adding the attribute to the command wouldn't be as elegant as passing a `Command` subclass as a `cls` attribute to the `commands.command` decorator. This is because the former requires copying the entire code of the decorator to add the two lines into the nested function (it's a decorator with args, hence the nested function).
-rw-r--r--bot/command.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/bot/command.py b/bot/command.py
new file mode 100644
index 000000000..92e61d97e
--- /dev/null
+++ b/bot/command.py
@@ -0,0 +1,15 @@
+from discord.ext import commands
+
+
+class Command(commands.Command):
+ """
+ A `discord.ext.commands.Command` 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", [])