fix:移动config位置,修复颜文字bug

This commit is contained in:
SengokuCola
2025-04-16 21:10:34 +08:00
parent 0a74aba2ef
commit b4f284abca
41 changed files with 86 additions and 830 deletions

View File

@@ -1,5 +1,5 @@
from ..moods.moods import MoodManager # 导入情绪管理器
from ..config.config import global_config
from ...config.config import global_config
from .message import MessageRecv
from ..PFC.pfc_manager import PFCManager
from .chat_stream import chat_manager

View File

@@ -10,7 +10,7 @@ from PIL import Image
import io
from ...common.database import db
from ..config.config import global_config
from ...config.config import global_config
from ..chat.utils import get_embedding
from ..chat.utils_image import ImageManager, image_path_to_base64
from ..models.utils_model import LLMRequest

View File

@@ -9,7 +9,7 @@ from typing import Dict
from collections import OrderedDict
import random
import time
from ..config.config import global_config
from ...config.config import global_config
logger = get_module_logger("message_buffer")

View File

@@ -8,7 +8,7 @@ from ..message.api import global_api
from .message import MessageSending, MessageThinking, MessageSet
from ..storage.storage import MessageStorage
from ..config.config import global_config
from ...config.config import global_config
from .utils import truncate_message, calculate_typing_time, count_messages_between
from src.common.logger import LogConfig, SENDER_STYLE_CONFIG

View File

@@ -10,7 +10,7 @@ from src.common.logger import get_module_logger
from ..models.utils_model import LLMRequest
from ..utils.typo_generator import ChineseTypoGenerator
from ..config.config import global_config
from ...config.config import global_config
from .message import MessageRecv, Message
from ..message.message_base import UserInfo
from .chat_stream import ChatStream
@@ -520,8 +520,7 @@ def protect_kaomoji(sentence):
r"]"
r")"
r"|"
r"([▼▽・ᴥω・﹏^><≧≦ ̄`´∀ヮДд︿﹀へ。゚╥╯╰︶︹•⁄]{2,15"
r"}"
r"([▼▽・ᴥω・﹏^><≧≦ ̄`´∀ヮДд︿﹀へ。゚╥╯╰︶︹•⁄]{2,15})"
)
kaomoji_matches = kaomoji_pattern.findall(sentence)
@@ -718,12 +717,30 @@ def parse_text_timestamps(text: str, mode: str = "normal") -> str:
# normal模式: 直接转换所有时间戳
if mode == "normal":
result_text = text
# 将时间戳转换为可读格式并记录相同格式的时间戳
timestamp_readable_map = {}
readable_time_used = set()
for match in matches:
timestamp = float(match.group(1))
readable_time = translate_timestamp_to_human_readable(timestamp, "normal")
# 由于替换会改变文本长度,需要使用正则替换而非直接替换
pattern_instance = re.escape(match.group(0))
result_text = re.sub(pattern_instance, readable_time, result_text, count=1)
timestamp_readable_map[match.group(0)] = (timestamp, readable_time)
# 按时间戳排序
sorted_timestamps = sorted(timestamp_readable_map.items(), key=lambda x: x[1][0])
# 执行替换,相同格式的只保留最早的
for ts_str, (_, readable) in sorted_timestamps:
pattern_instance = re.escape(ts_str)
if readable in readable_time_used:
# 如果这个可读时间已经使用过,替换为空字符串
result_text = re.sub(pattern_instance, "", result_text, count=1)
else:
# 否则替换为可读时间并记录
result_text = re.sub(pattern_instance, readable, result_text, count=1)
readable_time_used.add(readable)
return result_text
else:
# lite模式: 按5秒间隔划分并选择性转换
@@ -782,15 +799,30 @@ def parse_text_timestamps(text: str, mode: str = "normal") -> str:
pattern_instance = re.escape(match.group(0))
result_text = re.sub(pattern_instance, "", result_text, count=1)
# 按照时间戳原始顺序排序,避免替换时位置错误
to_convert.sort(key=lambda x: x[1].start())
# 执行替换
# 由于替换会改变文本长度,从后向前替换
to_convert.reverse()
# 按照时间戳升序排序
to_convert.sort(key=lambda x: x[0])
# 将时间戳转换为可读时间并记录哪些可读时间已经使用过
converted_timestamps = []
readable_time_used = set()
for ts, match in to_convert:
readable_time = translate_timestamp_to_human_readable(ts, "relative")
converted_timestamps.append((ts, match, readable_time))
# 按照时间戳原始顺序排序,避免替换时位置错误
converted_timestamps.sort(key=lambda x: x[1].start())
# 从后向前替换,避免位置改变
converted_timestamps.reverse()
for ts, match, readable_time in converted_timestamps:
pattern_instance = re.escape(match.group(0))
result_text = re.sub(pattern_instance, readable_time, result_text, count=1)
if readable_time in readable_time_used:
# 如果相同格式的时间已存在,替换为空字符串
result_text = re.sub(pattern_instance, "", result_text, count=1)
else:
# 否则替换为可读时间并记录
result_text = re.sub(pattern_instance, readable_time, result_text, count=1)
readable_time_used.add(readable_time)
return result_text

View File

@@ -8,7 +8,7 @@ import io
from ...common.database import db
from ..config.config import global_config
from ...config.config import global_config
from ..models.utils_model import LLMRequest
from src.common.logger import get_module_logger