|
@@ -8,25 +8,40 @@ __all__ = [
|
|
|
"Lazy",
|
|
|
"MessageInjector",
|
|
|
"ContextInjector",
|
|
|
+ "Origin",
|
|
|
+ "Channel",
|
|
|
+ "Sender",
|
|
|
+ "Timestamp",
|
|
|
+ "OriginAdmin",
|
|
|
+ "ChannelAdmin",
|
|
|
+ "Text",
|
|
|
+ "Attachments",
|
|
|
+ "CommandInjector",
|
|
|
]
|
|
|
|
|
|
|
|
|
-class MessageInjector(Injector[Message]):
|
|
|
- async def inject(self, message: Message, context: Context) -> Message:
|
|
|
- return message
|
|
|
-
|
|
|
-
|
|
|
-MessageInjector = MessageInjector()
|
|
|
+Dep = TypeVar("Dep")
|
|
|
|
|
|
|
|
|
-class ContextInjector(Injector[Context]):
|
|
|
- async def inject(self, message: Message, context: Context) -> Context:
|
|
|
- return context
|
|
|
+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)
|
|
|
|
|
|
-ContextInjector = ContextInjector()
|
|
|
|
|
|
-Dep = TypeVar("Dep")
|
|
|
+MessageInjector = Simple(lambda m, c: m)
|
|
|
+ContextInjector = Simple(lambda m, c: c)
|
|
|
+Origin = Simple(lambda m, c: m.origin_id)
|
|
|
+Channel = Simple(lambda m, c: m.channel_id)
|
|
|
+Sender = Simple(lambda m, c: m.sender_id)
|
|
|
+Timestamp = Simple(lambda m, c: m.timestamp)
|
|
|
+OriginAdmin = Simple(lambda m, c: m.origin_admin)
|
|
|
+ChannelAdmin = Simple(lambda m, c: m.channel_admin)
|
|
|
+Text = Simple(lambda m, c: m.text)
|
|
|
+Attachments = Simple(lambda m, c: m.attachments)
|
|
|
+CommandInjector = Simple(lambda m, c: m.command)
|
|
|
|
|
|
|
|
|
class Lazy(InjectorWithCleanup[Callable[[], Coroutine[None, None, Dep]]]):
|