|
12 | 12 | from arclet.alconna import Alconna |
13 | 13 | from arclet.alconna import config as alconna_config |
14 | 14 | from arclet.letoderea import EVENT, Contexts, Param, Provider, ProviderFactory, global_providers |
| 15 | +from arclet.letoderea.context import shared_suppliers |
15 | 16 | from arclet.letoderea.scope import configure |
16 | 17 | from creart import it |
17 | 18 | from graia.amnesia.builtins.aiohttp import AiohttpClientService |
@@ -77,16 +78,6 @@ async def __call__(self, context: Contexts): |
77 | 78 | if self.target_type and not generic_isinstance(sess.event, self.target_type): |
78 | 79 | return |
79 | 80 | return sess |
80 | | - if ITEM_ORIGIN_EVENT in context and ITEM_ACCOUNT in context: |
81 | | - if self.target_type and not generic_isinstance(context[EVENT], self.target_type): |
82 | | - return |
83 | | - session = Session(context[ITEM_ACCOUNT], context[EVENT]) |
84 | | - if ITEM_MESSAGE_CONTENT in context: |
85 | | - session.elements = context[ITEM_MESSAGE_CONTENT] |
86 | | - if ITEM_MESSAGE_REPLY in context: |
87 | | - session.reply = context[ITEM_MESSAGE_REPLY] |
88 | | - context[ITEM_SESSION] = session |
89 | | - return session |
90 | 81 |
|
91 | 82 | def validate(self, param: Param): |
92 | 83 | if get_origin(param.annotation) is Session: |
@@ -222,6 +213,17 @@ async def __call__(self, context: Contexts): |
222 | 213 | ) |
223 | 214 |
|
224 | 215 |
|
| 216 | +@shared_suppliers.append |
| 217 | +async def session_supplier(context: Contexts): |
| 218 | + if ITEM_ORIGIN_EVENT in context and ITEM_ACCOUNT in context: |
| 219 | + session = Session(context[ITEM_ACCOUNT], context[EVENT]) |
| 220 | + if ITEM_MESSAGE_CONTENT in context: |
| 221 | + session.elements = context[ITEM_MESSAGE_CONTENT] |
| 222 | + if ITEM_MESSAGE_REPLY in context: |
| 223 | + session.reply = context[ITEM_MESSAGE_REPLY] |
| 224 | + context[ITEM_SESSION] = session |
| 225 | + |
| 226 | + |
225 | 227 | class RecordConfig(BasicConfModel): |
226 | 228 | to_me_only: bool = False |
227 | 229 | """是否仅记录提及 Bot 自己的消息""" |
|
0 commit comments