refactor: onmyoji gacha plugin overhaul (gacha-refactor)

This commit is contained in:
2026-05-03 09:55:15 +08:00
parent 9a8cb3ad6d
commit 0312c79c9d
20 changed files with 2699 additions and 2450 deletions

View File

@@ -0,0 +1,45 @@
"""
权限校验与规则解析模块
提供NoneBot命令的权限检查规则函数包括
- 群组权限检查(通用)
所有规则函数返回Rule对象用于NoneBot的matcher定义。
"""
from typing import Callable
from nonebot.rule import Rule
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, MessageEvent
def _check_group_allowed(config) -> Callable:
"""生成群组权限检查函数(内部复用,消除重复逻辑)。
Args:
config: Config实例需包含ALLOWED_GROUPS属性
Returns:
异步检查函数,私聊放行、群聊检查白名单
"""
async def _check(bot: Bot, event: MessageEvent) -> bool:
if not isinstance(event, GroupMessageEvent):
return True
return str(event.group_id) in config.ALLOWED_GROUPS
return _check
def check_permission() -> Rule:
"""检查群组是否有权限使用抽卡功能。"""
from .config import Config
config = Config()
return Rule(_check_group_allowed(config))
def check_rank_permission() -> Rule:
"""检查用户是否有权限查看排行榜。
当前与check_permission逻辑相同保留为独立入口便于未来扩展。
"""
from .config import Config
config = Config()
return Rule(_check_group_allowed(config))