aboutsummaryrefslogtreecommitdiff
path: root/src/core_modules/command_spec.py
diff options
context:
space:
mode:
authorGravatar jesopo2020-01-26 02:41:24 +0000
committerGravatar jesopo2020-01-26 02:41:24 +0000
commit2ae47364c0a07bca25cedb04050d4f028cefc183 (patch)
tree9188f6d988de7ff6aed854ede81050f8ff3cb60f /src/core_modules/command_spec.py
parentfix typehinting issues (diff)
signature
support multiple specs per command
Diffstat (limited to 'src/core_modules/command_spec.py')
-rw-r--r--src/core_modules/command_spec.py66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/core_modules/command_spec.py b/src/core_modules/command_spec.py
index da3691c6..d1328628 100644
--- a/src/core_modules/command_spec.py
+++ b/src/core_modules/command_spec.py
@@ -90,44 +90,48 @@ class Module(ModuleManager.BaseModule):
@utils.hook("preprocess.command")
@utils.kwarg("priority", EventManager.PRIORITY_HIGH)
def preprocess(self, event):
- spec_arguments = event["hook"].get_kwarg("spec", None)
- if not spec_arguments == None:
+ specs = event["hook"].get_kwargs("spec")
+ if specs:
server = event["server"]
channel = event["target"] if event["is_channel"] else None
user = event["user"]
args = event["args_split"].copy()
- out = []
- kwargs = {"channel": channel}
+ first_error = None
+ for spec_arguments in specs:
+ out = []
+ kwargs = {"channel": channel}
+ failed = False
+ for spec_argument in spec_arguments:
+ argument_type_multi = len(set(
+ t.type for t in spec_argument.types)) > 1
+ options = self._spec_value(server, kwargs["channel"], user,
+ spec_argument.types, args)
- for spec_argument in spec_arguments:
- options = self._spec_value(server, kwargs["channel"], user,
- spec_argument.types, args)
+ found = None
+ for argument_type, value, n, error in options:
+ if not value == None:
+ if argument_type.exported:
+ kwargs[argument_type.exported] = value
- found = None
- first_error = None
- for argument_type, value, n, error in options:
- if not value == None:
- if argument_type.exported:
- kwargs[argument_type.exported] = value
+ args = args[n:]
+ if argument_type_multi:
+ value = [argument_type.type, value]
+ found = value
+ break
+ elif not error and n > len(args):
+ error = "Not enough arguments"
- found = True
- args = args[n:]
- if len(spec_argument.types) > 1:
- value = [argument_type.type, value]
- found = value
+ first_error = first_error or error
+ if not found == None:
+ out.append(found)
+ elif not spec_argument.optional:
+ failed = True
break
- elif not error and n > len(args):
- error = "Not enough arguments"
+ if not failed:
+ kwargs["spec"] = out
+ event["kwargs"].update(kwargs)
+ return
- if error and not first_error:
- first_error = error
-
- if not spec_argument.optional and not found:
- error = first_error or "Invalid arguments"
- return utils.consts.PERMISSION_HARD_FAIL, error
-
- out.append(found)
-
- kwargs["spec"] = out
- event["kwargs"].update(kwargs)
+ error = first_error or "Invalid arguments"
+ return utils.consts.PERMISSION_HARD_FAIL, error