Files
DanDingNoneBot/danding_bot/plugins/danding_sign_in/permission.py
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

25 lines
667 B
Python
Raw 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 依赖,便于单元测试)。"""
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