Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
fix: allow coroutines for prefixed commands (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstreaTSS authored Aug 2, 2022
1 parent fcdfdfb commit 30e6955
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions naff/models/naff/prefixed_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,17 @@ def _get_converter(anno: type, name: str) -> Callable[["PrefixedContext", str],
elif typing.get_origin(anno) is Literal:
literals = typing.get_args(anno)
return _LiteralConverter(literals).convert
elif inspect.isfunction(anno):
elif inspect.isroutine(anno):
num_params = len(inspect.signature(anno).parameters.values())
match num_params:
case 2:
return lambda ctx, arg: anno(ctx, arg)
return anno
case 1:
return lambda ctx, arg: anno(arg)

async def _one_function_cmd(ctx, arg) -> Any:
return await maybe_coroutine(anno, arg)

return _one_function_cmd
case 0:
ValueError(f"{get_object_name(anno)} for {name} has 0 arguments, which is unsupported.")
case _:
Expand Down

0 comments on commit 30e6955

Please sign in to comment.