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

29 lines
956 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
from zhenxun.services.cache import Cache
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
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-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:
2025-04-08 17:11:44 +08:00
raise SkipPluginException("Bot不存在或休眠中阻断权限检测...")
2025-01-08 15:23:10 +08:00
if CommonUtils.format(plugin.module) in bot.block_plugins:
2025-04-08 17:11:44 +08:00
raise SkipPluginException(
f"Bot插件 {plugin.name}({plugin.module}) 权限检查结果为关闭..."
2025-01-08 15:23:10 +08:00
)