From a3a3d872fa418e0a9c1d27a6ed8a5213f6da18bd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 6 Jul 2025 14:13:25 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/message_receive/storage.py | 21 +++++++++++---------- src/chat/utils/utils_image.py | 8 ++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/chat/message_receive/storage.py b/src/chat/message_receive/storage.py index 23afe6c87..146a4372a 100644 --- a/src/chat/message_receive/storage.py +++ b/src/chat/message_receive/storage.py @@ -142,23 +142,24 @@ class MessageStorage: def replace_image_descriptions(text: str) -> str: """将[图片:描述]替换为[picid:image_id]""" # 先检查文本中是否有图片标记 - pattern = r'\[图片:([^\]]+)\]' + pattern = r"\[图片:([^\]]+)\]" matches = re.findall(pattern, text) - + if not matches: logger.debug("文本中没有图片标记,直接返回原文本") return text + def replace_match(match): description = match.group(1).strip() try: - image_record = (Images.select() - .where(Images.description == description) - .order_by(Images.timestamp.desc()) - .first()) + image_record = ( + Images.select().where(Images.description == description).order_by(Images.timestamp.desc()).first() + ) if image_record: return f"[picid:{image_record.image_id}]" - else: - return match.group(0) # 保持原样 - except Exception as e: + else: + return match.group(0) # 保持原样 + except Exception: return match.group(0) - return re.sub(r'\[图片:([^\]]+)\]', replace_match, text) + + return re.sub(r"\[图片:([^\]]+)\]", replace_match, text) diff --git a/src/chat/utils/utils_image.py b/src/chat/utils/utils_image.py index eed65ad88..17cfb2323 100644 --- a/src/chat/utils/utils_image.py +++ b/src/chat/utils/utils_image.py @@ -187,12 +187,12 @@ class ImageManager: existing_image = Images.get_or_none(Images.emoji_hash == image_hash) if existing_image: # 更新计数 - if hasattr(existing_image, 'count') and existing_image.count is not None: + if hasattr(existing_image, "count") and existing_image.count is not None: existing_image.count += 1 else: existing_image.count = 1 existing_image.save() - + # 如果已有描述,直接返回 if existing_image.description: return f"[图片:{existing_image.description}]" @@ -229,9 +229,9 @@ class ImageManager: existing_image.path = file_path existing_image.description = description existing_image.timestamp = current_timestamp - if not hasattr(existing_image, 'image_id') or not existing_image.image_id: + if not hasattr(existing_image, "image_id") or not existing_image.image_id: existing_image.image_id = str(uuid.uuid4()) - if not hasattr(existing_image, 'vlm_processed') or existing_image.vlm_processed is None: + if not hasattr(existing_image, "vlm_processed") or existing_image.vlm_processed is None: existing_image.vlm_processed = True existing_image.save() else: