|
@@ -6,10 +6,11 @@ import inspect
|
|
from ..types import (
|
|
from ..types import (
|
|
Message,
|
|
Message,
|
|
Context,
|
|
Context,
|
|
|
|
+ Command,
|
|
CommandType,
|
|
CommandType,
|
|
Response,
|
|
Response,
|
|
)
|
|
)
|
|
-from ..injection import Injector, inject_all, MessageInjector, ContextInjector
|
|
|
|
|
|
+from ..injection import Injector, inject_all, MessageInjector, ContextInjector, CommandInjector
|
|
from .error_handling import with_failure_handling
|
|
from .error_handling import with_failure_handling
|
|
|
|
|
|
decorated_commands: dict[str, CommandType] = {}
|
|
decorated_commands: dict[str, CommandType] = {}
|
|
@@ -51,6 +52,8 @@ def _get_injectors(fn: Callable[..., Any]) -> list[Injector]:
|
|
injectors.append(MessageInjector)
|
|
injectors.append(MessageInjector)
|
|
elif annot == Context:
|
|
elif annot == Context:
|
|
injectors.append(ContextInjector)
|
|
injectors.append(ContextInjector)
|
|
|
|
+ elif annot == Command:
|
|
|
|
+ injectors.append(CommandInjector)
|
|
elif isinstance(annot, Injector):
|
|
elif isinstance(annot, Injector):
|
|
injectors.append(annot)
|
|
injectors.append(annot)
|
|
else:
|
|
else:
|
|
@@ -61,11 +64,10 @@ def _get_injectors(fn: Callable[..., Any]) -> list[Injector]:
|
|
def _make_response(message: Message, result: Any) -> Response:
|
|
def _make_response(message: Message, result: Any) -> Response:
|
|
if result is None or isinstance(result, Response):
|
|
if result is None or isinstance(result, Response):
|
|
return result
|
|
return result
|
|
- elif isinstance(result, str):
|
|
|
|
|
|
+ if isinstance(result, str):
|
|
return Response.from_message(message, text=result)
|
|
return Response.from_message(message, text=result)
|
|
# TODO handle attachments, other special returns
|
|
# TODO handle attachments, other special returns
|
|
- else:
|
|
|
|
- return Response.from_message(message, text=str(result))
|
|
|
|
|
|
+ return Response.from_message(message, text=str(result))
|
|
|
|
|
|
|
|
|
|
def _on_command_impl(name: str, fn: Callable[..., Any]) -> Callable[..., Any]:
|
|
def _on_command_impl(name: str, fn: Callable[..., Any]) -> Callable[..., Any]:
|