|
@@ -5,7 +5,7 @@ from datetime import datetime
|
|
|
from aiohttp import ClientSession
|
|
|
|
|
|
from ..types import Message, Context, Attachment, Command
|
|
|
-from .base import Injector, InjectorWithCleanup
|
|
|
+from .base import Injector, InjectorWithCleanup, Simple
|
|
|
|
|
|
__all__ = [
|
|
|
"Lazy",
|
|
@@ -25,18 +25,6 @@ __all__ = [
|
|
|
"Config",
|
|
|
]
|
|
|
|
|
|
-
|
|
|
-Dep = TypeVar("Dep")
|
|
|
-
|
|
|
-
|
|
|
-class Simple(Injector[Dep]):
|
|
|
- def __init__(self, extract: Callable[[Message, Context], Dep]):
|
|
|
- self.extract = extract
|
|
|
-
|
|
|
- async def inject(self, message: Message, context: Context) -> Dep:
|
|
|
- return self.extract(message, context)
|
|
|
-
|
|
|
-
|
|
|
MessageInjector = Simple[Message](lambda m, c: m)
|
|
|
ContextInjector = Simple[Context](lambda m, c: c)
|
|
|
Origin = Simple[str](lambda m, c: m.origin_id)
|
|
@@ -60,6 +48,9 @@ class Config(Injector[Any]):
|
|
|
return context.config(self.key)
|
|
|
|
|
|
|
|
|
+Dep = TypeVar("Dep")
|
|
|
+
|
|
|
+
|
|
|
class Lazy(InjectorWithCleanup[Callable[[], Coroutine[None, None, Dep]]]):
|
|
|
def __init__(self, deferred: Injector[Dep]):
|
|
|
self.deferred = deferred
|