mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-04 11:20:01 +08:00
性能优化 (#2126)
* 性能优化 * 代码改进 * 优化浏览器代际切换逻辑 * 统一缓存与生命周期 * 添加aiomysql依赖 * 优化插件路径处理逻辑,简化条件判断;在虚拟环境包管理器中添加编码和错误处理参数以增强稳定性 * 🚨 auto fix by pre-commit hooks * 优化Windows下的关闭逻辑 * 代码优化 * bugfix:修复配置重载问题 * bugfix:修复插件加载启动竞态问题 * 收敛事件入口和权限上下文 * 优化 Windows launcher 关闭重启兜底 --------- Co-authored-by: HibiKier <775757368@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
HibiKier
pre-commit-ci[bot]
parent
24c316cd2c
commit
5d92ccd3b0
@@ -7,9 +7,10 @@ from zhenxun.models.level_user import LevelUser
|
||||
from zhenxun.models.plugin_info import PluginInfo
|
||||
from zhenxun.services.cache.runtime_cache import LevelUserMemoryCache, LevelUserSnapshot
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.utils import get_entity_ids
|
||||
from zhenxun.utils.utils import EntityIDs, get_entity_ids
|
||||
|
||||
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
|
||||
from .context import PermissionContext
|
||||
from .exception import SkipPluginException
|
||||
|
||||
|
||||
@@ -20,6 +21,9 @@ async def auth_admin(
|
||||
LevelUser | LevelUserSnapshot | None, LevelUser | LevelUserSnapshot | None
|
||||
]
|
||||
| None = None,
|
||||
*,
|
||||
context: PermissionContext | None = None,
|
||||
entity: EntityIDs | None = None,
|
||||
):
|
||||
"""管理员命令 个人权限
|
||||
|
||||
@@ -33,7 +37,12 @@ async def auth_admin(
|
||||
return
|
||||
|
||||
try:
|
||||
entity = get_entity_ids(session)
|
||||
if context is not None:
|
||||
entity = context.entity
|
||||
if cached_levels is None:
|
||||
cached_levels = context.admin_levels
|
||||
if entity is None:
|
||||
entity = get_entity_ids(session)
|
||||
|
||||
global_user: LevelUser | LevelUserSnapshot | None = None
|
||||
group_users: LevelUser | LevelUserSnapshot | None = None
|
||||
@@ -42,7 +51,7 @@ async def auth_admin(
|
||||
global_user, group_users = cached_levels
|
||||
else:
|
||||
global_user, group_users = await LevelUserMemoryCache.get_levels(
|
||||
session.user.id, entity.group_id
|
||||
entity.user_id, entity.group_id
|
||||
)
|
||||
|
||||
user_level = global_user.user_level if global_user else 0
|
||||
@@ -53,7 +62,7 @@ async def auth_admin(
|
||||
raise SkipPluginException(
|
||||
f"{plugin.name}({plugin.module}) 管理员权限不足...",
|
||||
tip_message=[
|
||||
At(flag="user", target=session.user.id),
|
||||
At(flag="user", target=entity.user_id),
|
||||
f"你的权限不足喔,该功能需要的权限等级: {plugin.admin_level}",
|
||||
],
|
||||
tip_check_tag=entity.user_id,
|
||||
|
||||
Reference in New Issue
Block a user