添加依赖注入支持,重构函数调用上下文,优化插件加载机制

This commit is contained in:
2024-12-17 13:25:30 +08:00
parent a0f657b239
commit a2c4fb220e
4 changed files with 132 additions and 42 deletions

View File

@ -0,0 +1,34 @@
from typing import TYPE_CHECKING, Any
from nonebot.adapters import Bot, Event
from nonebot.matcher import Matcher
from nonebot.typing import T_State
from pydantic import BaseModel
if TYPE_CHECKING:
from .caller import Caller
class SessionContext(BaseModel):
"""依赖注入会话上下文
Args:
BaseModel (_type_): _description_
"""
bot: Bot
event: Event
matcher: Matcher
state: T_State
caller: Any = None
class Config:
arbitrary_types_allowed = True
class SessionContextDepends(BaseModel):
bot: str | None = None
event: str | None = None
matcher: str | None = None
state: str | None = None
caller: str | None = None