From 1fcb01dcea273ce9e08b23519d11f739fd55ca31 Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 3 May 2019 11:04:38 -0700 Subject: [PATCH] ref: strict argument matching for `Plugin.command` deco Previously any keyword arguments passed into the `Plugin.command` decorator that didn't match a keyword argument inside of `Comman.update` would be collected into the `metdata` for a command. This can cause fairly severe bugs in your code if you make typos when passing keyword arguments into the decorator since they will be blindly accepted. For example consider a situation where a user (lets say me) creates the following command: ``` @Plugin.command(..., permissions=CommandLevels.TRUSTED) ``` While this looks perfectly valid and the code will run without issue, this command actually has a permissions level of '0' since the correct keyword argument is `level`. This commit changes the behavior to require all metadata passed in to be within a `metadata` kwarg. Any unknown keyword arguments passed will throw a traditional Python error. --- disco/bot/command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/disco/bot/command.py b/disco/bot/command.py index de8eaa5..c302584 100644 --- a/disco/bot/command.py +++ b/disco/bot/command.py @@ -171,7 +171,7 @@ class Command(object): oob=False, context=None, parser=False, - **kwargs): + metadata=None): self.triggers += aliases or [] def resolve_role(ctx, rid): @@ -209,7 +209,7 @@ class Command(object): self.is_regex = is_regex self.oob = oob self.context = context or {} - self.metadata = kwargs + self.metadata = metadata or {} if parser: self.parser = PluginArgumentParser(prog=self.name, add_help=False)