mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-08-01 19:49:59 +00:00
修复依赖注入问题? (#17)
* 实现缓存装饰器,优化数据获取和存储逻辑
* 重构代码,准备将聊天请求逻辑移入MarshoHandler
* 记录点(
* unfinished
* 🎨 重写基本完毕
* 移除未使用import,添加漏掉的换行
* 修复依赖注入问题?
This commit is contained in:
@ -72,7 +72,9 @@ class Caller:
|
||||
|
||||
# if self.ctx.state is None:
|
||||
# return False, "State is None"
|
||||
if self._rule and not await self._rule(self.ctx.bot, self.ctx.event):
|
||||
if self._rule and not await self._rule(
|
||||
self.ctx.bot, self.ctx.event, self.ctx.state
|
||||
):
|
||||
return False, "告诉用户 Rule Denied 规则不匹配"
|
||||
|
||||
return True, ""
|
||||
@ -113,9 +115,9 @@ class Caller:
|
||||
# 检查函数签名,确定依赖注入参数
|
||||
sig = inspect.signature(func)
|
||||
for name, param in sig.parameters.items():
|
||||
if param.annotation == T_State:
|
||||
self.di.state = name
|
||||
continue # 防止后续判断T_State子类时报错
|
||||
# if param.annotation == T_State:
|
||||
# self.di.state = name
|
||||
# continue # 防止后续判断T_State子类时报错
|
||||
|
||||
if issubclass(param.annotation, Event) or isinstance(
|
||||
param.annotation, Event
|
||||
|
@ -19,7 +19,7 @@ class SessionContext(BaseModel):
|
||||
bot: Bot
|
||||
event: Event
|
||||
matcher: Matcher
|
||||
# state: T_State
|
||||
state: T_State | None
|
||||
caller: Any = None
|
||||
|
||||
class Config:
|
||||
|
Reference in New Issue
Block a user