Files
Mr.Xia 260651363a fix(sign_in): 修复签到命令 Rule 构造 NameError(MessageEvent 注解全局可见)
- rules.py 改为模块顶层导入 nonebot(NoneBot Rule 解析依赖参数注解在全局命名空间求值)
- 权限纯函数 is_allowed 拆至 permission.py(无 nonebot 依赖,保持可测性)
- 测试加载模块列表同步调整(config/api/service/permission)
2026-08-16 09:05:08 +08:00

32 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""独立签到插件 - 权限校验NoneBot Rule
签到命令仅在白名单群聊(或管理员)中可用;私聊非管理员不可用。
与 onmyoji_gacha 的规则不同:抽卡规则私聊放行,签到规则更严格(群聊白名单)。
注意:本模块必须顶层导入 nonebotNoneBot Rule 解析依赖参数注解,
注解名需要在模块全局命名空间可见),纯函数逻辑见 permission.py。
"""
from nonebot.rule import Rule
from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageEvent
from .config import Config
from .permission import is_allowed
def check_permission() -> Rule:
"""生成签到命令权限 Rule白名单群聊 + 管理员)。"""
config = Config()
async def _checker(event: MessageEvent) -> bool:
group_id = event.group_id if isinstance(event, GroupMessageEvent) else None
return is_allowed(
event.user_id,
group_id,
allowed_group_id=config.ALLOWED_GROUP_ID,
allowed_user_id=config.ALLOWED_USER_ID,
)
return Rule(_checker)