Browse Source

bugfix - parsed command arguments should be passed in kwargs

This fixes some weird edge cases with positional arguments when using
multiple command definitions for a single function.
pull/11/head
Andrei 8 years ago
parent
commit
7084531353
  1. 7
      disco/bot/command.py
  2. 4
      disco/bot/parser.py

7
disco/bot/command.py

@ -241,8 +241,11 @@ class Command(object):
))
try:
args = self.args.parse(event.args, ctx=event)
parsed_args = self.args.parse(event.args, ctx=event)
except ArgumentError as e:
raise CommandError(e.message)
return self.plugin.dispatch('command', self, event, *args, **self.context)
kwargs = {}
kwargs.update(self.context)
kwargs.update(parsed_args)
return self.plugin.dispatch('command', self, event, **kwargs)

4
disco/bot/parser.py

@ -145,7 +145,7 @@ class ArgumentSet(object):
"""
Parse a string of raw arguments into this argument specification.
"""
parsed = []
parsed = {}
for index, arg in enumerate(self.args):
if not arg.required and index + arg.true_count > len(rawargs):
@ -171,7 +171,7 @@ class ArgumentSet(object):
if (not arg.types or arg.types == ['str']) and isinstance(raw, list):
raw = ' '.join(raw)
parsed.append(raw)
parsed[arg.name] = raw
return parsed

Loading…
Cancel
Save