mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-18 02:30:08 +08:00
bugfix:修复sqlite部分场景下锁竞争问题;新增插件恶意触发配置文件 (#2144)
* bugfix:修复sqlite部分场景下锁竞争问题;新增插件恶意触发配置文件 * 文件没同步完
This commit is contained in:
@@ -12,7 +12,7 @@ from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from ....base_model import Result
|
||||
from ....config import AVA_URL, GROUP_AVA_URL
|
||||
from ....utils import authentication
|
||||
from ....utils import DB_BUSY_MESSAGE, authentication
|
||||
from .data_source import ApiDataSource
|
||||
from .model import (
|
||||
ClearRequest,
|
||||
@@ -294,6 +294,8 @@ async def _(bot_id: str, user_id: str) -> Result[UserDetail]:
|
||||
if result
|
||||
else Result.warning_("未找到该好友...")
|
||||
)
|
||||
except TimeoutError:
|
||||
return Result.fail(DB_BUSY_MESSAGE)
|
||||
except (ValueError, KeyError):
|
||||
return Result.warning_("指定Bot未连接...")
|
||||
except Exception as e:
|
||||
@@ -311,6 +313,8 @@ async def _(bot_id: str, user_id: str) -> Result[UserDetail]:
|
||||
async def _(group_id: str) -> Result[GroupDetail]:
|
||||
try:
|
||||
return Result.ok(await ApiDataSource.get_group_detail(group_id), "拿到信息啦!")
|
||||
except TimeoutError:
|
||||
return Result.fail(DB_BUSY_MESSAGE)
|
||||
except Exception as e:
|
||||
logger.error(f"{router.prefix}/get_group_detail 调用错误", "WebUi", e=e)
|
||||
return Result.fail(f"发生了一点错误捏 {type(e)}: {e}")
|
||||
|
||||
@@ -13,6 +13,7 @@ from zhenxun.utils.enum import RequestType
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from ....config import AVA_URL, GROUP_AVA_URL
|
||||
from ....utils import webui_db_call
|
||||
from .model import (
|
||||
FriendRequestResult,
|
||||
GroupDetail,
|
||||
@@ -110,20 +111,24 @@ class ApiDataSource:
|
||||
fd = [x for x in friend_list if x.user_id == user_id]
|
||||
if not fd:
|
||||
return None
|
||||
like_plugin_list = (
|
||||
await Statistics.filter(user_id=user_id)
|
||||
like_plugin_list = await webui_db_call(
|
||||
Statistics.filter(user_id=user_id)
|
||||
.annotate(count=Count("id"))
|
||||
.group_by("plugin_name")
|
||||
.order_by("-count")
|
||||
.limit(5)
|
||||
.values_list("plugin_name", "count")
|
||||
.values_list("plugin_name", "count"),
|
||||
"Manage.friend_like_plugin",
|
||||
)
|
||||
like_plugin = {}
|
||||
module_list = [x[0] for x in like_plugin_list]
|
||||
plugins = await PluginInfo.get_plugins(
|
||||
load_status=None,
|
||||
filter_parent=False,
|
||||
module__in=module_list,
|
||||
plugins = await webui_db_call(
|
||||
PluginInfo.get_plugins(
|
||||
load_status=None,
|
||||
filter_parent=False,
|
||||
module__in=module_list,
|
||||
),
|
||||
"Manage.friend_like_plugin_names",
|
||||
)
|
||||
module2name = {p.module: p.name for p in plugins}
|
||||
for data in like_plugin_list:
|
||||
@@ -136,8 +141,14 @@ class ApiDataSource:
|
||||
nickname=user.user_name,
|
||||
remark="",
|
||||
is_ban=await BanConsole.is_ban(user_id),
|
||||
chat_count=await ChatHistory.filter(user_id=user_id).count(),
|
||||
call_count=await Statistics.filter(user_id=user_id).count(),
|
||||
chat_count=await webui_db_call(
|
||||
ChatHistory.filter(user_id=user_id).count(),
|
||||
"Manage.friend_chat_count",
|
||||
),
|
||||
call_count=await webui_db_call(
|
||||
Statistics.filter(user_id=user_id).count(),
|
||||
"Manage.friend_call_count",
|
||||
),
|
||||
like_plugin=like_plugin,
|
||||
)
|
||||
|
||||
@@ -151,16 +162,20 @@ class ApiDataSource:
|
||||
返回:
|
||||
dict[str, int]: 插件与调用次数
|
||||
"""
|
||||
like_plugin_list = (
|
||||
await Statistics.filter(group_id=group_id)
|
||||
like_plugin_list = await webui_db_call(
|
||||
Statistics.filter(group_id=group_id)
|
||||
.annotate(count=Count("id"))
|
||||
.group_by("plugin_name")
|
||||
.order_by("-count")
|
||||
.limit(5)
|
||||
.values_list("plugin_name", "count")
|
||||
.values_list("plugin_name", "count"),
|
||||
"Manage.group_like_plugin",
|
||||
)
|
||||
like_plugin = {}
|
||||
plugins = await PluginInfo.get_plugins()
|
||||
plugins = await webui_db_call(
|
||||
PluginInfo.get_plugins(),
|
||||
"Manage.group_like_plugin_names",
|
||||
)
|
||||
module2name = {p.module: p.name for p in plugins}
|
||||
for data in like_plugin_list:
|
||||
name = module2name.get(data[0]) or data[0]
|
||||
@@ -268,8 +283,14 @@ class ApiDataSource:
|
||||
name=group.group_name,
|
||||
member_count=group.member_count,
|
||||
max_member_count=group.max_member_count,
|
||||
chat_count=await ChatHistory.filter(group_id=group_id).count(),
|
||||
call_count=await Statistics.filter(group_id=group_id).count(),
|
||||
chat_count=await webui_db_call(
|
||||
ChatHistory.filter(group_id=group_id).count(),
|
||||
"Manage.group_chat_count",
|
||||
),
|
||||
call_count=await webui_db_call(
|
||||
Statistics.filter(group_id=group_id).count(),
|
||||
"Manage.group_call_count",
|
||||
),
|
||||
like_plugin=like_plugin,
|
||||
level=group.level,
|
||||
status=group.status,
|
||||
|
||||
Reference in New Issue
Block a user