fix: use AUTH_SNAPSHOT and PLUGIN_SNAPSHOT cache types instead of TEMP/PLUGINS

This commit is contained in:
HibiKier
2025-12-30 15:10:14 +08:00
parent ae4aa5c29c
commit 358c7f502c
14 changed files with 51 additions and 27 deletions
@@ -6,13 +6,13 @@ from nonebot_plugin_uninfo import Uninfo
from zhenxun.models.level_user import LevelUser
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.services.auth_snapshot.exception import SkipPluginException
from zhenxun.services.data_access import DataAccess
from zhenxun.services.db_context import DB_TIMEOUT_SECONDS
from zhenxun.services.log import logger
from zhenxun.utils.utils import get_entity_ids
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
from .exception import SkipPluginException
from .utils import send_message
@@ -9,13 +9,13 @@ from nonebot_plugin_uninfo import Uninfo
from zhenxun.configs.config import Config
from zhenxun.models.ban_console import BanConsole
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.services.auth_snapshot.exception import SkipPluginException
from zhenxun.services.db_context import DB_TIMEOUT_SECONDS
from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType
from zhenxun.utils.utils import EntityIDs, get_entity_ids
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
from .exception import SkipPluginException
from .utils import freq, send_message
Config.add_plugin_config(
@@ -3,13 +3,13 @@ import time
from zhenxun.models.bot_console import BotConsole
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.services.auth_snapshot.exception import SkipPluginException
from zhenxun.services.data_access import DataAccess
from zhenxun.services.db_context import DB_TIMEOUT_SECONDS
from zhenxun.services.log import logger
from zhenxun.utils.common_utils import CommonUtils
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
from .exception import SkipPluginException
async def auth_bot(plugin: PluginInfo, bot_id: str):
@@ -4,10 +4,10 @@ from nonebot_plugin_uninfo import Uninfo
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.models.user_console import UserConsole
from zhenxun.services.auth_snapshot.exception import SkipPluginException
from zhenxun.services.log import logger
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
from .exception import SkipPluginException
from .utils import send_message
@@ -4,10 +4,10 @@ from nonebot_plugin_alconna import UniMsg
from zhenxun.models.group_console import GroupConsole
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.services.auth_snapshot.exception import SkipPluginException
from zhenxun.services.log import logger
from .config import LOGGER_COMMAND, WARNING_THRESHOLD, SwitchEnum
from .exception import SkipPluginException
async def auth_group(
@@ -8,6 +8,7 @@ from pydantic import BaseModel
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.models.plugin_limit import PluginLimit
from zhenxun.services.auth_snapshot.exception import SkipPluginException
from zhenxun.services.db_context import DB_TIMEOUT_SECONDS
from zhenxun.services.log import logger
from zhenxun.utils.enum import LimitWatchType, PluginLimitType
@@ -18,7 +19,6 @@ from zhenxun.utils.time_utils import TimeUtils
from zhenxun.utils.utils import get_entity_ids
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
from .exception import SkipPluginException
driver = nonebot.get_driver()
@@ -6,13 +6,16 @@ from nonebot_plugin_uninfo import Uninfo
from zhenxun.models.group_console import GroupConsole
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.services.auth_snapshot.exception import (
IsSuperuserException,
SkipPluginException,
)
from zhenxun.services.db_context import DB_TIMEOUT_SECONDS
from zhenxun.services.log import logger
from zhenxun.utils.common_utils import CommonUtils
from zhenxun.utils.enum import BlockType
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
from .exception import IsSuperuserException, SkipPluginException
from .utils import freq, is_poke, send_message
@@ -2,8 +2,7 @@ import nonebot
from nonebot_plugin_uninfo import Uninfo
from zhenxun.configs.config import Config
from .exception import SkipPluginException
from zhenxun.services.auth_snapshot.exception import SkipPluginException
Config.add_plugin_config(
"hook",
@@ -1,26 +0,0 @@
class IsSuperuserException(Exception):
pass
class SkipPluginException(Exception):
def __init__(self, info: str, *args: object) -> None:
super().__init__(*args)
self.info = info
def __str__(self) -> str:
return self.info
def __repr__(self) -> str:
return self.info
class PermissionExemption(Exception):
def __init__(self, info: str, *args: object) -> None:
super().__init__(*args)
self.info = info
def __str__(self) -> str:
return self.info
def __repr__(self) -> str:
return self.info
+19 -2
View File
@@ -1,16 +1,21 @@
import time
from nonebot.adapters import Bot, Event
from nonebot.exception import IgnoredException
from nonebot.matcher import Matcher
from nonebot.message import run_postprocessor, run_preprocessor
from nonebot_plugin_alconna import UniMsg
from nonebot_plugin_uninfo import Uninfo
from zhenxun.services.auth_snapshot.checker import optimized_auth_checker
from zhenxun.services.auth_snapshot.exception import (
PermissionExemption,
SkipPluginException,
)
from zhenxun.services.log import logger
from .auth.auth_limit import LimitManager
from .auth.config import LOGGER_COMMAND
from .auth_checker import LimitManager
# # 权限检测
@@ -24,7 +29,19 @@ async def _(matcher: Matcher, event: Event, bot: Bot, session: Uninfo, message:
# session,
# message,
# )
await optimized_auth_checker.check(matcher, event, bot, session, message)
try:
await optimized_auth_checker.check(matcher, event, bot, session, message)
except SkipPluginException as e:
logger.info(str(e), LOGGER_COMMAND, session=session)
raise IgnoredException(str(e))
except PermissionExemption as e:
logger.info(
str(e) or "超级用户跳过权限检测...", LOGGER_COMMAND, session=session
)
raise IgnoredException(str(e))
except Exception as e:
logger.error(f"权限检测异常: {e}", LOGGER_COMMAND, session=session, e=e)
raise SkipPluginException("权限检测异常") from e
logger.debug(f"权限检测耗时:{time.time() - start_time}秒", LOGGER_COMMAND)