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

28 lines
907 B
Python
Raw Normal View History

2025-01-07 18:29:35 +08:00
from zhenxun.models.bot_console import BotConsole
from zhenxun.models.plugin_info import PluginInfo
2025-07-10 17:10:07 +08:00
from zhenxun.services.data_access import DataAccess
2025-01-08 15:23:10 +08:00
from zhenxun.utils.common_utils import CommonUtils
2025-01-07 18:29:35 +08:00
2025-04-08 17:11:44 +08:00
from .exception import SkipPluginException
2025-01-07 18:29:35 +08:00
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
异常:
2025-04-08 17:11:44 +08:00
SkipPluginException: 忽略插件
SkipPluginException: 忽略插件
2025-01-07 18:29:35 +08:00
"""
2025-07-10 17:10:07 +08:00
bot_dao = DataAccess(BotConsole)
bot = await bot_dao.safe_get_or_none(bot_id=bot_id)
if not bot or not bot.status:
raise SkipPluginException("Bot不存在或休眠中阻断权限检测...")
if CommonUtils.format(plugin.module) in bot.block_plugins:
raise SkipPluginException(
f"Bot插件 {plugin.name}({plugin.module}) 权限检查结果为关闭..."
)