Browse Source

[commands] Remove support for pass_context=False in Command.

pull/662/head
Rapptz 8 years ago
parent
commit
bcaee518a1
  1. 1
      discord/ext/commands/bot.py
  2. 6
      discord/ext/commands/context.py
  3. 23
      discord/ext/commands/core.py

1
discord/ext/commands/bot.py

@ -168,7 +168,6 @@ class BotBase(GroupMixin):
self._skip_check = lambda x, y: x == y self._skip_check = lambda x, y: x == y
self.help_attrs = options.pop('help_attrs', {}) self.help_attrs = options.pop('help_attrs', {})
self.help_attrs['pass_context'] = True
if 'name' not in self.help_attrs: if 'name' not in self.help_attrs:
self.help_attrs['name'] = 'help' self.help_attrs['name'] = 'help'

6
discord/ext/commands/context.py

@ -32,7 +32,7 @@ class Context(discord.abc.Messageable):
This class contains a lot of meta data to help you understand more about This class contains a lot of meta data to help you understand more about
the invocation context. This class is not created manually and is instead the invocation context. This class is not created manually and is instead
passed around to commands by passing in :attr:`Command.pass_context`. passed around to commands as the first parameter.
This class implements the :class:`abc.Messageable` ABC. This class implements the :class:`abc.Messageable` ABC.
@ -122,9 +122,7 @@ class Context(discord.abc.Messageable):
if command.instance is not None: if command.instance is not None:
arguments.append(command.instance) arguments.append(command.instance)
if command.pass_context: arguments.append(self)
arguments.append(self)
arguments.extend(args[1:]) arguments.extend(args[1:])
ret = yield from command.callback(*arguments, **kwargs) ret = yield from command.callback(*arguments, **kwargs)

23
discord/ext/commands/core.py

@ -104,9 +104,6 @@ class Command:
A replacement for arguments in the default help text. A replacement for arguments in the default help text.
aliases: list aliases: list
The list of aliases the command can be invoked under. The list of aliases the command can be invoked under.
pass_context: bool
A boolean that indicates that the current :class:`.Context` should
be passed as the **first parameter**. Defaults to `True`.
enabled: bool enabled: bool
A boolean that indicates if the command is currently enabled. A boolean that indicates if the command is currently enabled.
If the command is invoked while it is disabled, then If the command is invoked while it is disabled, then
@ -152,7 +149,6 @@ class Command:
self.usage = kwargs.get('usage') self.usage = kwargs.get('usage')
self.rest_is_raw = kwargs.get('rest_is_raw', False) self.rest_is_raw = kwargs.get('rest_is_raw', False)
self.aliases = kwargs.get('aliases', []) self.aliases = kwargs.get('aliases', [])
self.pass_context = kwargs.get('pass_context', True)
self.description = inspect.cleandoc(kwargs.get('description', '')) self.description = inspect.cleandoc(kwargs.get('description', ''))
self.hidden = kwargs.get('hidden', False) self.hidden = kwargs.get('hidden', False)
signature = inspect.signature(callback) signature = inspect.signature(callback)
@ -272,9 +268,11 @@ class Command:
# first parameter is self # first parameter is self
result.popitem(last=False) result.popitem(last=False)
if self.pass_context: try:
# first/second parameter is context # first/second parameter is context
result.popitem(last=False) result.popitem(last=False)
except Exception as e:
raise ValueError('Missing context parameter') from None
return result return result
@ -331,12 +329,11 @@ class Command:
@asyncio.coroutine @asyncio.coroutine
def _parse_arguments(self, ctx): def _parse_arguments(self, ctx):
ctx.args = [] if self.instance is None else [self.instance] ctx.args = [ctx] if self.instance is None else [self.instance, ctx]
ctx.kwargs = {} ctx.kwargs = {}
args = ctx.args args = ctx.args
kwargs = ctx.kwargs kwargs = ctx.kwargs
first = True
view = ctx.view view = ctx.view
iterator = iter(self.params.items()) iterator = iter(self.params.items())
@ -349,12 +346,14 @@ class Command:
fmt = 'Callback for {0.name} command is missing "self" parameter.' fmt = 'Callback for {0.name} command is missing "self" parameter.'
raise discord.ClientException(fmt.format(self)) raise discord.ClientException(fmt.format(self))
for name, param in iterator: # next we have the 'ctx' as the next parameter
if first and self.pass_context: try:
args.append(ctx) next(iterator)
first = False except StopIteration:
continue fmt = 'Callback for {0.name} command is missing "ctx" parameter.'
raise discord.ClientException(fmt.format(self))
for name, param in iterator:
if param.kind == param.POSITIONAL_OR_KEYWORD: if param.kind == param.POSITIONAL_OR_KEYWORD:
transformed = yield from self.transform(ctx, param) transformed = yield from self.transform(ctx, param)
args.append(transformed) args.append(transformed)

Loading…
Cancel
Save