mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 18:59:09 +00:00
[commands] Fix discord.Invite special case handling in parameters.
This led to decorating a lot of things into @asyncio.coroutine. Unfortunately there's no way to lower the amount of decoration since coroutines spread like a virus.
This commit is contained in:
parent
d013032522
commit
8caadb5f03
@ -156,6 +156,7 @@ class Command:
|
|||||||
result = discord.utils.get(iterable, id=match.group(1))
|
result = discord.utils.get(iterable, id=match.group(1))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
def do_conversion(self, bot, message, converter, argument):
|
def do_conversion(self, bot, message, converter, argument):
|
||||||
if converter is bool:
|
if converter is bool:
|
||||||
return _convert_to_bool(argument)
|
return _convert_to_bool(argument)
|
||||||
@ -196,9 +197,10 @@ class Command:
|
|||||||
return discord.Game(name=argument)
|
return discord.Game(name=argument)
|
||||||
elif converter is discord.Invite:
|
elif converter is discord.Invite:
|
||||||
try:
|
try:
|
||||||
return bot.get_invite(argument)
|
invite = yield from bot.get_invite(argument)
|
||||||
|
return invite
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise BadArgument('Invite is invalid') from e
|
raise BadArgument('Invite is invalid or expired') from e
|
||||||
|
|
||||||
def _get_converter(self, param):
|
def _get_converter(self, param):
|
||||||
converter = param.annotation
|
converter = param.annotation
|
||||||
@ -212,6 +214,7 @@ class Command:
|
|||||||
|
|
||||||
return converter
|
return converter
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
def transform(self, ctx, param):
|
def transform(self, ctx, param):
|
||||||
required = param.default is param.empty
|
required = param.default is param.empty
|
||||||
converter = self._get_converter(param)
|
converter = self._get_converter(param)
|
||||||
@ -232,7 +235,7 @@ class Command:
|
|||||||
argument = quoted_word(view)
|
argument = quoted_word(view)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.do_conversion(ctx.bot, ctx.message, converter, argument)
|
return (yield from self.do_conversion(ctx.bot, ctx.message, converter, argument))
|
||||||
except CommandError as e:
|
except CommandError as e:
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -256,6 +259,7 @@ class Command:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
def _parse_arguments(self, ctx):
|
def _parse_arguments(self, ctx):
|
||||||
try:
|
try:
|
||||||
ctx.args = [] if self.instance is None else [self.instance]
|
ctx.args = [] if self.instance is None else [self.instance]
|
||||||
@ -283,20 +287,22 @@ class Command:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if param.kind == param.POSITIONAL_OR_KEYWORD:
|
if param.kind == param.POSITIONAL_OR_KEYWORD:
|
||||||
args.append(self.transform(ctx, param))
|
transformed = yield from self.transform(ctx, param)
|
||||||
|
args.append(transformed)
|
||||||
elif param.kind == param.KEYWORD_ONLY:
|
elif param.kind == param.KEYWORD_ONLY:
|
||||||
# kwarg only param denotes "consume rest" semantics
|
# kwarg only param denotes "consume rest" semantics
|
||||||
if self.rest_is_raw:
|
if self.rest_is_raw:
|
||||||
converter = self._get_converter(param)
|
converter = self._get_converter(param)
|
||||||
argument = view.read_rest()
|
argument = view.read_rest()
|
||||||
kwargs[name] = self.do_conversion(ctx.bot, ctx.message, converter, argument)
|
kwargs[name] = yield from self.do_conversion(ctx.bot, ctx.message, converter, argument)
|
||||||
else:
|
else:
|
||||||
kwargs[name] = self.transform(ctx, param)
|
kwargs[name] = yield from self.transform(ctx, param)
|
||||||
break
|
break
|
||||||
elif param.kind == param.VAR_POSITIONAL:
|
elif param.kind == param.VAR_POSITIONAL:
|
||||||
while not view.eof:
|
while not view.eof:
|
||||||
try:
|
try:
|
||||||
args.append(self.transform(ctx, param))
|
transformed = yield from self.transform(ctx, param)
|
||||||
|
args.append(transformed)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
except CommandError as e:
|
except CommandError as e:
|
||||||
@ -327,7 +333,7 @@ class Command:
|
|||||||
if not self._verify_checks(ctx):
|
if not self._verify_checks(ctx):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._parse_arguments(ctx):
|
if (yield from self._parse_arguments(ctx)):
|
||||||
injected = inject_context(ctx, self.callback)
|
injected = inject_context(ctx, self.callback)
|
||||||
yield from injected(*ctx.args, **ctx.kwargs)
|
yield from injected(*ctx.args, **ctx.kwargs)
|
||||||
|
|
||||||
@ -544,7 +550,7 @@ class Group(GroupMixin, Command):
|
|||||||
def invoke(self, ctx):
|
def invoke(self, ctx):
|
||||||
early_invoke = not self.invoke_without_command
|
early_invoke = not self.invoke_without_command
|
||||||
if early_invoke:
|
if early_invoke:
|
||||||
valid = self._verify_checks(ctx) and self._parse_arguments(ctx)
|
valid = self._verify_checks(ctx) and (yield from self._parse_arguments(ctx))
|
||||||
if not valid:
|
if not valid:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -569,7 +575,7 @@ class Group(GroupMixin, Command):
|
|||||||
# undo the trigger parsing
|
# undo the trigger parsing
|
||||||
view.index = previous
|
view.index = previous
|
||||||
view.previous = previous
|
view.previous = previous
|
||||||
valid = self._verify_checks(ctx) and self._parse_arguments(ctx)
|
valid = self._verify_checks(ctx) and (yield from self._parse_arguments(ctx))
|
||||||
if not valid:
|
if not valid:
|
||||||
return
|
return
|
||||||
injected = inject_context(ctx, self.callback)
|
injected = inject_context(ctx, self.callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user