refactor(managers): 重构单例管理器实现并优化代码结构
feat(ws_pool): 新增 WebSocket 连接池实现 perf(json): 使用 orjson 替代标准 json 库提升性能 style: 清理未使用的导入和冗余代码 docs: 更新架构文档和开发规范 test: 添加 WebSocket 连接池测试用例 fix(plugins): 修复自动审批插件 API 调用参数格式
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import json
|
||||
import orjson
|
||||
import abc
|
||||
import aiohttp
|
||||
from typing import Optional, Dict, Any, List, Union
|
||||
from cachetools import TTLCache
|
||||
|
||||
from core.utils.logger import logger
|
||||
from models import MessageEvent, MessageSegment
|
||||
from models import MessageEvent
|
||||
|
||||
|
||||
class BaseParser(metaclass=abc.ABCMeta):
|
||||
@@ -38,6 +37,7 @@ class BaseParser(metaclass=abc.ABCMeta):
|
||||
"""
|
||||
self.name = "Base Parser"
|
||||
self.url_pattern = re.compile(r"https?://[^\s]+")
|
||||
self.processed_messages = {} # 用于存储已处理的消息ID,防止重复处理
|
||||
|
||||
@classmethod
|
||||
def get_session(cls) -> aiohttp.ClientSession:
|
||||
@@ -105,12 +105,12 @@ class BaseParser(metaclass=abc.ABCMeta):
|
||||
if segment.type == "json":
|
||||
logger.info(f"[{self.name}] 检测到JSON CQ码: {segment.data}")
|
||||
try:
|
||||
json_data = json.loads(segment.data.get("data", "{}"))
|
||||
json_data = orjson.loads(segment.data.get("data", "{}"))
|
||||
short_url = json_data.get("meta", {}).get("detail_1", {}).get("qqdocurl")
|
||||
if short_url:
|
||||
logger.success(f"[{self.name}] 成功从JSON卡片中提取到链接: {short_url}")
|
||||
return short_url
|
||||
except (json.JSONDecodeError, KeyError) as e:
|
||||
except (orjson.JSONDecodeError, KeyError) as e:
|
||||
logger.error(f"[{self.name}] 解析JSON失败: {e}")
|
||||
continue
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user