mirror of https://github.com/Mai-with-u/MaiBot.git
fix Ruff
parent
eaef7f0e98
commit
6378bb2052
|
|
@ -1234,7 +1234,7 @@ class MCPClientManager:
|
||||||
return await client.read_resource(uri)
|
return await client.read_resource(uri)
|
||||||
|
|
||||||
# 自动查找拥有该资源的服务器
|
# 自动查找拥有该资源的服务器
|
||||||
for resource_key, (resource_info, client) in self._all_resources.items():
|
for _resource_key, (resource_info, client) in self._all_resources.items():
|
||||||
if resource_info.uri == uri:
|
if resource_info.uri == uri:
|
||||||
return await client.read_resource(uri)
|
return await client.read_resource(uri)
|
||||||
|
|
||||||
|
|
@ -1265,7 +1265,7 @@ class MCPClientManager:
|
||||||
return await client.get_prompt(name, arguments)
|
return await client.get_prompt(name, arguments)
|
||||||
|
|
||||||
# 自动查找拥有该提示模板的服务器
|
# 自动查找拥有该提示模板的服务器
|
||||||
for prompt_key, (prompt_info, client) in self._all_prompts.items():
|
for _prompt_key, (prompt_info, client) in self._all_prompts.items():
|
||||||
if prompt_info.name == name:
|
if prompt_info.name == name:
|
||||||
return await client.get_prompt(name, arguments)
|
return await client.get_prompt(name, arguments)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1201,7 +1201,7 @@ class MCPStatusTool(BaseTool):
|
||||||
|
|
||||||
lines = ["📦 可用 MCP 资源"]
|
lines = ["📦 可用 MCP 资源"]
|
||||||
by_server: Dict[str, List[MCPResourceInfo]] = {}
|
by_server: Dict[str, List[MCPResourceInfo]] = {}
|
||||||
for key, (resource_info, _) in resources.items():
|
for _key, (resource_info, _) in resources.items():
|
||||||
if server_name and resource_info.server_name != server_name:
|
if server_name and resource_info.server_name != server_name:
|
||||||
continue
|
continue
|
||||||
if resource_info.server_name not in by_server:
|
if resource_info.server_name not in by_server:
|
||||||
|
|
@ -1222,7 +1222,7 @@ class MCPStatusTool(BaseTool):
|
||||||
|
|
||||||
lines = ["📝 可用 MCP 提示模板"]
|
lines = ["📝 可用 MCP 提示模板"]
|
||||||
by_server: Dict[str, List[MCPPromptInfo]] = {}
|
by_server: Dict[str, List[MCPPromptInfo]] = {}
|
||||||
for key, (prompt_info, _) in prompts.items():
|
for _key, (prompt_info, _) in prompts.items():
|
||||||
if server_name and prompt_info.server_name != server_name:
|
if server_name and prompt_info.server_name != server_name:
|
||||||
continue
|
continue
|
||||||
if prompt_info.server_name not in by_server:
|
if prompt_info.server_name not in by_server:
|
||||||
|
|
@ -1559,7 +1559,7 @@ class MCPStatusCommand(BaseCommand):
|
||||||
|
|
||||||
# 按服务器分组显示
|
# 按服务器分组显示
|
||||||
by_server: Dict[str, List[Tuple[str, Any]]] = {}
|
by_server: Dict[str, List[Tuple[str, Any]]] = {}
|
||||||
for tool_key, tool_info, client in matched:
|
for tool_key, tool_info, _client in matched:
|
||||||
server_name = tool_info.server_name
|
server_name = tool_info.server_name
|
||||||
if server_name not in by_server:
|
if server_name not in by_server:
|
||||||
by_server[server_name] = []
|
by_server[server_name] = []
|
||||||
|
|
@ -1647,7 +1647,7 @@ class MCPStatusCommand(BaseCommand):
|
||||||
from src.plugin_system.core.component_registry import component_registry
|
from src.plugin_system.core.component_registry import component_registry
|
||||||
|
|
||||||
registered = 0
|
registered = 0
|
||||||
for name, chain in tool_chain_manager.get_enabled_chains().items():
|
for name, _chain in tool_chain_manager.get_enabled_chains().items():
|
||||||
tool_name = f"chain_{name}".replace("-", "_").replace(".", "_")
|
tool_name = f"chain_{name}".replace("-", "_").replace(".", "_")
|
||||||
if component_registry.get_component_info(tool_name, ComponentType.TOOL):
|
if component_registry.get_component_info(tool_name, ComponentType.TOOL):
|
||||||
registered += 1
|
registered += 1
|
||||||
|
|
@ -1788,7 +1788,7 @@ class MCPStatusCommand(BaseCommand):
|
||||||
if tools:
|
if tools:
|
||||||
lines.append("\n🔧 可用工具:")
|
lines.append("\n🔧 可用工具:")
|
||||||
by_server = {}
|
by_server = {}
|
||||||
for key, (info, _) in tools.items():
|
for _key, (info, _) in tools.items():
|
||||||
if server_name and info.server_name != server_name:
|
if server_name and info.server_name != server_name:
|
||||||
continue
|
continue
|
||||||
by_server.setdefault(info.server_name, []).append(info.name)
|
by_server.setdefault(info.server_name, []).append(info.name)
|
||||||
|
|
@ -3180,14 +3180,14 @@ mcp_bing_*""",
|
||||||
|
|
||||||
# 创建异步执行函数(使用闭包捕获 tool_key)
|
# 创建异步执行函数(使用闭包捕获 tool_key)
|
||||||
def make_execute_func(tk: str):
|
def make_execute_func(tk: str):
|
||||||
async def execute_func(**kwargs) -> str:
|
async def _execute_func(**kwargs) -> str:
|
||||||
result = await mcp_manager.call_tool(tk, kwargs)
|
result = await mcp_manager.call_tool(tk, kwargs)
|
||||||
if result.success:
|
if result.success:
|
||||||
return result.content or "(无返回内容)"
|
return result.content or "(无返回内容)"
|
||||||
else:
|
else:
|
||||||
return f"工具调用失败: {result.error}"
|
return f"工具调用失败: {result.error}"
|
||||||
|
|
||||||
return execute_func
|
return _execute_func
|
||||||
|
|
||||||
execute_func = make_execute_func(tool_key)
|
execute_func = make_execute_func(tool_key)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ def test_auth_required_list(client):
|
||||||
"""测试未认证访问列表端点(401)"""
|
"""测试未认证访问列表端点(401)"""
|
||||||
# Without mock_token_verify fixture
|
# Without mock_token_verify fixture
|
||||||
with patch("src.webui.routers.emoji.verify_auth_token", return_value=False):
|
with patch("src.webui.routers.emoji.verify_auth_token", return_value=False):
|
||||||
response = client.get("/emoji/list")
|
client.get("/emoji/list")
|
||||||
# verify_auth_token 返回 False 会触发 HTTPException
|
# verify_auth_token 返回 False 会触发 HTTPException
|
||||||
# 但具体状态码取决于 verify_auth_token_from_cookie_or_header 的实现
|
# 但具体状态码取决于 verify_auth_token_from_cookie_or_header 的实现
|
||||||
# 这里假设它抛出 401
|
# 这里假设它抛出 401
|
||||||
|
|
@ -397,7 +397,7 @@ def test_auth_required_update(client, sample_emojis):
|
||||||
"""测试未认证访问更新端点(401)"""
|
"""测试未认证访问更新端点(401)"""
|
||||||
with patch("src.webui.routers.emoji.verify_auth_token", return_value=False):
|
with patch("src.webui.routers.emoji.verify_auth_token", return_value=False):
|
||||||
emoji_id = sample_emojis[0].id
|
emoji_id = sample_emojis[0].id
|
||||||
response = client.patch(f"/emoji/{emoji_id}", json={"description": "test"})
|
client.patch(f"/emoji/{emoji_id}", json={"description": "test"})
|
||||||
# Should be unauthorized
|
# Should be unauthorized
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ from typing import Dict, List, Set, Tuple
|
||||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
sys.path.insert(0, project_root)
|
sys.path.insert(0, project_root)
|
||||||
|
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger # noqa: E402
|
||||||
|
|
||||||
logger = get_logger("evaluation_stats_analyzer")
|
logger = get_logger("evaluation_stats_analyzer")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,11 @@ from collections import defaultdict
|
||||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
sys.path.insert(0, project_root)
|
sys.path.insert(0, project_root)
|
||||||
|
|
||||||
from src.common.database.database_model import Expression
|
from src.common.database.database_model import Expression # noqa: E402
|
||||||
from src.common.database.database import db
|
from src.common.database.database import db # noqa: E402
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger # noqa: E402
|
||||||
from src.llm_models.utils_model import LLMRequest
|
from src.llm_models.utils_model import LLMRequest # noqa: E402
|
||||||
from src.config.config import model_config
|
from src.config.config import model_config # noqa: E402
|
||||||
|
|
||||||
logger = get_logger("expression_evaluator_count_analysis_llm")
|
logger = get_logger("expression_evaluator_count_analysis_llm")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ from typing import List, Dict, Set, Tuple
|
||||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
sys.path.insert(0, project_root)
|
sys.path.insert(0, project_root)
|
||||||
|
|
||||||
from src.llm_models.utils_model import LLMRequest
|
from src.llm_models.utils_model import LLMRequest # noqa: E402
|
||||||
from src.config.config import model_config
|
from src.config.config import model_config # noqa: E402
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger # noqa: E402
|
||||||
|
|
||||||
logger = get_logger("expression_evaluator_llm")
|
logger = get_logger("expression_evaluator_llm")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ from datetime import datetime
|
||||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
sys.path.insert(0, project_root)
|
sys.path.insert(0, project_root)
|
||||||
|
|
||||||
from src.common.database.database_model import Expression
|
from src.common.database.database_model import Expression # noqa: E402
|
||||||
from src.common.database.database import db
|
from src.common.database.database import db # noqa: E402
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger # noqa: E402
|
||||||
|
|
||||||
logger = get_logger("expression_evaluator_manual")
|
logger = get_logger("expression_evaluator_manual")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import Set
|
|
||||||
|
|
||||||
# 保证可以导入 src.*
|
# 保证可以导入 src.*
|
||||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||||
|
|
@ -32,7 +31,6 @@ def main() -> None:
|
||||||
# KG 统计
|
# KG 统计
|
||||||
nodes = kg.graph.get_node_list()
|
nodes = kg.graph.get_node_list()
|
||||||
edges = kg.graph.get_edge_list()
|
edges = kg.graph.get_edge_list()
|
||||||
node_set: Set[str] = set(nodes)
|
|
||||||
|
|
||||||
para_nodes = [n for n in nodes if n.startswith("paragraph-")]
|
para_nodes = [n for n in nodes if n.startswith("paragraph-")]
|
||||||
ent_nodes = [n for n in nodes if n.startswith("entity-")]
|
ent_nodes = [n for n in nodes if n.startswith("entity-")]
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,18 @@ PROJECT_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, ".."))
|
||||||
if PROJECT_ROOT not in sys.path:
|
if PROJECT_ROOT not in sys.path:
|
||||||
sys.path.append(PROJECT_ROOT)
|
sys.path.append(PROJECT_ROOT)
|
||||||
|
|
||||||
from src.common.logger import get_logger # type: ignore
|
from src.common.logger import get_logger # type: ignore # noqa: E402
|
||||||
from src.config.config import global_config, model_config # type: ignore
|
from src.config.config import global_config, model_config # type: ignore # noqa: E402
|
||||||
|
|
||||||
# 引入各功能脚本的入口函数
|
# 引入各功能脚本的入口函数
|
||||||
from import_openie import main as import_openie_main # type: ignore
|
from import_openie import main as import_openie_main # type: ignore # noqa: E402
|
||||||
from info_extraction import main as info_extraction_main # type: ignore
|
from info_extraction import main as info_extraction_main # type: ignore # noqa: E402
|
||||||
from delete_lpmm_items import main as delete_lpmm_items_main # type: ignore
|
from delete_lpmm_items import main as delete_lpmm_items_main # type: ignore # noqa: E402
|
||||||
from inspect_lpmm_batch import main as inspect_lpmm_batch_main # type: ignore
|
from inspect_lpmm_batch import main as inspect_lpmm_batch_main # type: ignore # noqa: E402
|
||||||
from inspect_lpmm_global import main as inspect_lpmm_global_main # type: ignore
|
from inspect_lpmm_global import main as inspect_lpmm_global_main # type: ignore # noqa: E402
|
||||||
from refresh_lpmm_knowledge import main as refresh_lpmm_knowledge_main # type: ignore
|
from refresh_lpmm_knowledge import main as refresh_lpmm_knowledge_main # type: ignore # noqa: E402
|
||||||
from test_lpmm_retrieval import main as test_lpmm_retrieval_main # type: ignore
|
from test_lpmm_retrieval import main as test_lpmm_retrieval_main # type: ignore # noqa: E402
|
||||||
from raw_data_preprocessor import load_raw_data # type: ignore
|
from raw_data_preprocessor import load_raw_data # type: ignore # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
logger = get_logger("lpmm_manager")
|
logger = get_logger("lpmm_manager")
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ from src.common.logger import get_logger
|
||||||
from src.llm_models.utils_model import LLMRequest
|
from src.llm_models.utils_model import LLMRequest
|
||||||
from src.config.config import model_config
|
from src.config.config import model_config
|
||||||
from src.chat.knowledge import qa_manager
|
from src.chat.knowledge import qa_manager
|
||||||
from src.chat.utils.chat_message_builder import build_readable_messages
|
|
||||||
from src.chat.brain_chat.PFC.observation_info import dict_to_database_message
|
|
||||||
|
|
||||||
logger = get_logger("knowledge_fetcher")
|
logger = get_logger("knowledge_fetcher")
|
||||||
|
|
||||||
|
|
@ -48,13 +46,7 @@ class KnowledgeFetcher:
|
||||||
Returns:
|
Returns:
|
||||||
Tuple[str, str]: (获取的知识, 知识来源)
|
Tuple[str, str]: (获取的知识, 知识来源)
|
||||||
"""
|
"""
|
||||||
db_messages = [dict_to_database_message(m) for m in chat_history]
|
_ = chat_history
|
||||||
chat_history_text = build_readable_messages(
|
|
||||||
db_messages,
|
|
||||||
replace_bot_name=True,
|
|
||||||
timestamp_mode="relative",
|
|
||||||
read_mark=0.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
# NOTE: Hippocampus memory system was redesigned in v0.12.2
|
# NOTE: Hippocampus memory system was redesigned in v0.12.2
|
||||||
# The old get_memory_from_text API no longer exists
|
# The old get_memory_from_text API no longer exists
|
||||||
|
|
|
||||||
|
|
@ -519,7 +519,7 @@ def _build_readable_messages_internal(
|
||||||
output_lines: List[str] = []
|
output_lines: List[str] = []
|
||||||
|
|
||||||
prev_timestamp: Optional[float] = None
|
prev_timestamp: Optional[float] = None
|
||||||
for timestamp, name, content, is_action in detailed_message:
|
for timestamp, name, content, _is_action in detailed_message:
|
||||||
# 检查是否需要插入长时间间隔提示
|
# 检查是否需要插入长时间间隔提示
|
||||||
if long_time_notice and prev_timestamp is not None:
|
if long_time_notice and prev_timestamp is not None:
|
||||||
time_diff = timestamp - prev_timestamp
|
time_diff = timestamp - prev_timestamp
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,8 @@ def init_dream_tools(chat_id: str) -> None:
|
||||||
finish_maintenance = make_finish_maintenance(chat_id)
|
finish_maintenance = make_finish_maintenance(chat_id)
|
||||||
|
|
||||||
search_jargon = make_search_jargon(chat_id)
|
search_jargon = make_search_jargon(chat_id)
|
||||||
delete_jargon = make_delete_jargon(chat_id)
|
_delete_jargon = make_delete_jargon(chat_id)
|
||||||
update_jargon = make_update_jargon(chat_id)
|
_update_jargon = make_update_jargon(chat_id)
|
||||||
|
|
||||||
_dream_tool_registry.register_tool(
|
_dream_tool_registry.register_tool(
|
||||||
DreamTool(
|
DreamTool(
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ def _cleanup_stale_not_found_thinking_back() -> None:
|
||||||
try:
|
try:
|
||||||
with get_db_session() as session:
|
with get_db_session() as session:
|
||||||
statement = select(ThinkingQuestion).where(
|
statement = select(ThinkingQuestion).where(
|
||||||
(ThinkingQuestion.found_answer == False)
|
col(ThinkingQuestion.found_answer).is_(False)
|
||||||
& (ThinkingQuestion.updated_timestamp < datetime.fromtimestamp(threshold_time))
|
& (ThinkingQuestion.updated_timestamp < datetime.fromtimestamp(threshold_time))
|
||||||
)
|
)
|
||||||
records = session.exec(statement).all()
|
records = session.exec(statement).all()
|
||||||
|
|
@ -786,8 +786,7 @@ def _get_recent_query_history(chat_id: str, time_window_seconds: float = 600.0)
|
||||||
str: 格式化的查询历史字符串
|
str: 格式化的查询历史字符串
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
current_time = time.time()
|
_current_time = time.time()
|
||||||
start_time = current_time - time_window_seconds
|
|
||||||
|
|
||||||
with get_db_session() as session:
|
with get_db_session() as session:
|
||||||
statement = (
|
statement = (
|
||||||
|
|
@ -838,15 +837,14 @@ def _get_recent_found_answers(chat_id: str, time_window_seconds: float = 600.0)
|
||||||
List[str]: 格式化的答案列表,每个元素格式为 "问题:xxx\n答案:xxx"
|
List[str]: 格式化的答案列表,每个元素格式为 "问题:xxx\n答案:xxx"
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
current_time = time.time()
|
_current_time = time.time()
|
||||||
start_time = current_time - time_window_seconds
|
|
||||||
|
|
||||||
# 查询最近时间窗口内已找到答案的记录,按更新时间倒序
|
# 查询最近时间窗口内已找到答案的记录,按更新时间倒序
|
||||||
with get_db_session() as session:
|
with get_db_session() as session:
|
||||||
statement = (
|
statement = (
|
||||||
select(ThinkingQuestion)
|
select(ThinkingQuestion)
|
||||||
.where(col(ThinkingQuestion.context) == chat_id)
|
.where(col(ThinkingQuestion.context) == chat_id)
|
||||||
.where(col(ThinkingQuestion.found_answer) == True)
|
.where(col(ThinkingQuestion.found_answer))
|
||||||
.where(col(ThinkingQuestion.answer).is_not(None))
|
.where(col(ThinkingQuestion.answer).is_not(None))
|
||||||
.where(col(ThinkingQuestion.answer) != "")
|
.where(col(ThinkingQuestion.answer) != "")
|
||||||
.order_by(col(ThinkingQuestion.updated_timestamp).desc())
|
.order_by(col(ThinkingQuestion.updated_timestamp).desc())
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ async def get_log_detail(chat_id: str, filename: str):
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
return PlanLogDetail(**data)
|
return PlanLogDetail(**data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}") from e
|
||||||
|
|
||||||
|
|
||||||
# ========== 兼容旧接口 ==========
|
# ========== 兼容旧接口 ==========
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ async def get_reply_log_detail(chat_id: str, filename: str):
|
||||||
success=data.get("success", True),
|
success=data.get("success", True),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"读取日志失败: {str(e)}") from e
|
||||||
|
|
||||||
|
|
||||||
# ========== 兼容接口 ==========
|
# ========== 兼容接口 ==========
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ async def get_social_network(year: int = 2025) -> SocialNetworkData:
|
||||||
statement = select(func.count()).where(
|
statement = select(func.count()).where(
|
||||||
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
|
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
|
||||||
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
|
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
|
||||||
col(Messages.is_at) == True,
|
col(Messages.is_at),
|
||||||
)
|
)
|
||||||
data.at_count = int(session.exec(statement).first() or 0)
|
data.at_count = int(session.exec(statement).first() or 0)
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ async def get_social_network(year: int = 2025) -> SocialNetworkData:
|
||||||
statement = select(func.count()).where(
|
statement = select(func.count()).where(
|
||||||
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
|
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
|
||||||
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
|
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
|
||||||
col(Messages.is_mentioned) == True,
|
col(Messages.is_mentioned),
|
||||||
)
|
)
|
||||||
data.mentioned_count = int(session.exec(statement).first() or 0)
|
data.mentioned_count = int(session.exec(statement).first() or 0)
|
||||||
|
|
||||||
|
|
@ -552,7 +552,7 @@ async def get_expression_vibe(year: int = 2025) -> ExpressionVibeData:
|
||||||
# 1. 表情包之王 - 使用次数最多的表情包
|
# 1. 表情包之王 - 使用次数最多的表情包
|
||||||
with get_db_session() as session:
|
with get_db_session() as session:
|
||||||
statement = (
|
statement = (
|
||||||
select(Images).where(col(Images.is_registered) == True).order_by(desc(col(Images.query_count))).limit(5)
|
select(Images).where(col(Images.is_registered)).order_by(desc(col(Images.query_count))).limit(5)
|
||||||
)
|
)
|
||||||
top_emojis = session.exec(statement).all()
|
top_emojis = session.exec(statement).all()
|
||||||
if top_emojis:
|
if top_emojis:
|
||||||
|
|
@ -636,7 +636,7 @@ async def get_expression_vibe(year: int = 2025) -> ExpressionVibeData:
|
||||||
statement = select(func.count()).where(
|
statement = select(func.count()).where(
|
||||||
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
|
col(Messages.timestamp) >= datetime.fromtimestamp(start_ts),
|
||||||
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
|
col(Messages.timestamp) <= datetime.fromtimestamp(end_ts),
|
||||||
col(Messages.is_picture) == True,
|
col(Messages.is_picture),
|
||||||
)
|
)
|
||||||
data.image_processed_count = int(session.exec(statement).first() or 0)
|
data.image_processed_count = int(session.exec(statement).first() or 0)
|
||||||
|
|
||||||
|
|
@ -781,12 +781,12 @@ async def get_achievements(year: int = 2025) -> AchievementData:
|
||||||
# 1. 新学到的黑话数量
|
# 1. 新学到的黑话数量
|
||||||
# Jargon 表没有时间字段,统计全部已确认的黑话
|
# Jargon 表没有时间字段,统计全部已确认的黑话
|
||||||
with get_db_session() as session:
|
with get_db_session() as session:
|
||||||
statement = select(func.count()).where(col(Jargon.is_jargon) == True)
|
statement = select(func.count()).where(col(Jargon.is_jargon))
|
||||||
data.new_jargon_count = int(session.exec(statement).first() or 0)
|
data.new_jargon_count = int(session.exec(statement).first() or 0)
|
||||||
|
|
||||||
# 2. 代表性黑话示例
|
# 2. 代表性黑话示例
|
||||||
with get_db_session() as session:
|
with get_db_session() as session:
|
||||||
statement = select(Jargon).where(col(Jargon.is_jargon) == True).order_by(desc(col(Jargon.count))).limit(5)
|
statement = select(Jargon).where(col(Jargon.is_jargon)).order_by(desc(col(Jargon.count))).limit(5)
|
||||||
jargon_samples = session.exec(statement).all()
|
jargon_samples = session.exec(statement).all()
|
||||||
data.sample_jargons = [
|
data.sample_jargons = [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -532,7 +532,7 @@ async def get_emoji_stats(maibot_session: Optional[str] = Cookie(None), authoriz
|
||||||
.select_from(Images)
|
.select_from(Images)
|
||||||
.where(
|
.where(
|
||||||
col(Images.image_type) == ImageType.EMOJI,
|
col(Images.image_type) == ImageType.EMOJI,
|
||||||
col(Images.is_registered) == True,
|
col(Images.is_registered),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
banned_statement = (
|
banned_statement = (
|
||||||
|
|
@ -540,7 +540,7 @@ async def get_emoji_stats(maibot_session: Optional[str] = Cookie(None), authoriz
|
||||||
.select_from(Images)
|
.select_from(Images)
|
||||||
.where(
|
.where(
|
||||||
col(Images.image_type) == ImageType.EMOJI,
|
col(Images.image_type) == ImageType.EMOJI,
|
||||||
col(Images.is_banned) == True,
|
col(Images.is_banned),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1283,7 +1283,7 @@ async def preheat_thumbnail_cache(
|
||||||
select(Images)
|
select(Images)
|
||||||
.where(
|
.where(
|
||||||
col(Images.image_type) == ImageType.EMOJI,
|
col(Images.image_type) == ImageType.EMOJI,
|
||||||
col(Images.is_banned) == False,
|
col(Images.is_banned).is_(False),
|
||||||
)
|
)
|
||||||
.order_by(col(Images.query_count).desc())
|
.order_by(col(Images.query_count).desc())
|
||||||
.limit(limit * 2)
|
.limit(limit * 2)
|
||||||
|
|
|
||||||
|
|
@ -315,15 +315,15 @@ async def get_jargon_stats():
|
||||||
total = session.exec(select(fn.count()).select_from(Jargon)).one()
|
total = session.exec(select(fn.count()).select_from(Jargon)).one()
|
||||||
|
|
||||||
confirmed_jargon = session.exec(
|
confirmed_jargon = session.exec(
|
||||||
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon) == True)
|
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon))
|
||||||
).one()
|
).one()
|
||||||
confirmed_not_jargon = session.exec(
|
confirmed_not_jargon = session.exec(
|
||||||
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon) == False)
|
select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon).is_(False))
|
||||||
).one()
|
).one()
|
||||||
pending = session.exec(select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon).is_(None))).one()
|
pending = session.exec(select(fn.count()).select_from(Jargon).where(col(Jargon.is_jargon).is_(None))).one()
|
||||||
|
|
||||||
complete_count = session.exec(
|
complete_count = session.exec(
|
||||||
select(fn.count()).select_from(Jargon).where(col(Jargon.is_complete) == True)
|
select(fn.count()).select_from(Jargon).where(col(Jargon.is_complete))
|
||||||
).one()
|
).one()
|
||||||
|
|
||||||
chat_count = session.exec(
|
chat_count = session.exec(
|
||||||
|
|
|
||||||
|
|
@ -370,7 +370,7 @@ async def get_person_stats(maibot_session: Optional[str] = Cookie(None), authori
|
||||||
|
|
||||||
with get_db_session() as session:
|
with get_db_session() as session:
|
||||||
total = len(session.exec(select(PersonInfo.id)).all())
|
total = len(session.exec(select(PersonInfo.id)).all())
|
||||||
known = len(session.exec(select(PersonInfo.id).where(col(PersonInfo.is_known) == True)).all())
|
known = len(session.exec(select(PersonInfo.id).where(col(PersonInfo.is_known))).all())
|
||||||
unknown = total - known
|
unknown = total - known
|
||||||
|
|
||||||
# 按平台统计
|
# 按平台统计
|
||||||
|
|
|
||||||
|
|
@ -1762,7 +1762,7 @@ async def update_plugin_config_raw(
|
||||||
try:
|
try:
|
||||||
tomlkit.loads(request.config)
|
tomlkit.loads(request.config)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=f"TOML 格式错误: {str(e)}")
|
raise HTTPException(status_code=400, detail=f"TOML 格式错误: {str(e)}") from e
|
||||||
|
|
||||||
# 备份旧配置
|
# 备份旧配置
|
||||||
import shutil
|
import shutil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue