fix(sign_in): 修复签到命令 Rule 构造 NameError(MessageEvent 注解全局可见)
- rules.py 改为模块顶层导入 nonebot(NoneBot Rule 解析依赖参数注解在全局命名空间求值) - 权限纯函数 is_allowed 拆至 permission.py(无 nonebot 依赖,保持可测性) - 测试加载模块列表同步调整(config/api/service/permission)
This commit is contained in:
24
danding_bot/plugins/danding_sign_in/permission.py
Normal file
24
danding_bot/plugins/danding_sign_in/permission.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""独立签到插件 - 权限纯函数(无 nonebot 依赖,便于单元测试)。"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def is_allowed(
|
||||
user_id: int,
|
||||
group_id: Optional[int],
|
||||
*,
|
||||
allowed_group_id: int,
|
||||
allowed_user_id: int,
|
||||
) -> bool:
|
||||
"""签到权限纯函数:管理员任意场景可用;其他用户仅白名单群聊可用。
|
||||
|
||||
Args:
|
||||
user_id: 消息发送者 QQ
|
||||
group_id: 群聊 ID,非群聊场景为 None
|
||||
allowed_group_id: 白名单群聊
|
||||
allowed_user_id: 管理员 QQ
|
||||
"""
|
||||
|
||||
if user_id == allowed_user_id:
|
||||
return True
|
||||
return group_id is not None and group_id == allowed_group_id
|
||||
Reference in New Issue
Block a user