zhenxun_bot/zhenxun/builtin_plugins/hooks/auth/auth_bot.py

33 lines
1.1 KiB
Python
Raw Normal View History

2025-01-07 18:29:35 +08:00
from nonebot.exception import IgnoredException
from zhenxun.models.bot_console import BotConsole
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.services.cache import Cache
from zhenxun.services.log import logger
2025-01-08 15:23:10 +08:00
from zhenxun.utils.common_utils import CommonUtils
2025-01-07 18:29:35 +08:00
from zhenxun.utils.enum import CacheType
async def auth_bot(plugin: PluginInfo, bot_id: str):
2025-01-08 15:23:10 +08:00
"""bot层面的权限检查
2025-01-07 18:29:35 +08:00
参数:
plugin: PluginInfo
2025-01-08 15:23:10 +08:00
bot_id: bot id
异常:
IgnoredException: 忽略插件
IgnoredException: 忽略插件
2025-01-07 18:29:35 +08:00
"""
2025-01-08 15:23:10 +08:00
if cache := Cache[BotConsole](CacheType.BOT):
bot = await cache.get(bot_id)
if not bot or not bot.status:
logger.debug("Bot不存在或休眠中阻断权限检测...", "AuthChecker")
raise IgnoredException("BotConsole休眠权限检测 ignore")
if CommonUtils.format(plugin.module) in bot.block_plugins:
logger.debug(
f"Bot插件 {plugin.name}({plugin.module}) 权限检查结果为关闭...",
"AuthChecker",
)
raise IgnoredException("BotConsole插件权限检测 ignore")