🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-07-06 14:13:25 +00:00
parent 1daba178c5
commit a3a3d872fa
2 changed files with 15 additions and 14 deletions

View File

@@ -142,23 +142,24 @@ class MessageStorage:
def replace_image_descriptions(text: str) -> str: def replace_image_descriptions(text: str) -> str:
"""将[图片:描述]替换为[picid:image_id]""" """将[图片:描述]替换为[picid:image_id]"""
# 先检查文本中是否有图片标记 # 先检查文本中是否有图片标记
pattern = r'\[图片:([^\]]+)\]' pattern = r"\[图片:([^\]]+)\]"
matches = re.findall(pattern, text) matches = re.findall(pattern, text)
if not matches: if not matches:
logger.debug("文本中没有图片标记,直接返回原文本") logger.debug("文本中没有图片标记,直接返回原文本")
return text return text
def replace_match(match): def replace_match(match):
description = match.group(1).strip() description = match.group(1).strip()
try: try:
image_record = (Images.select() image_record = (
.where(Images.description == description) Images.select().where(Images.description == description).order_by(Images.timestamp.desc()).first()
.order_by(Images.timestamp.desc()) )
.first())
if image_record: if image_record:
return f"[picid:{image_record.image_id}]" return f"[picid:{image_record.image_id}]"
else: else:
return match.group(0) # 保持原样 return match.group(0) # 保持原样
except Exception as e: except Exception:
return match.group(0) return match.group(0)
return re.sub(r'\[图片:([^\]]+)\]', replace_match, text)
return re.sub(r"\[图片:([^\]]+)\]", replace_match, text)

View File

@@ -187,7 +187,7 @@ class ImageManager:
existing_image = Images.get_or_none(Images.emoji_hash == image_hash) existing_image = Images.get_or_none(Images.emoji_hash == image_hash)
if existing_image: 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 existing_image.count += 1
else: else:
existing_image.count = 1 existing_image.count = 1
@@ -229,9 +229,9 @@ class ImageManager:
existing_image.path = file_path existing_image.path = file_path
existing_image.description = description existing_image.description = description
existing_image.timestamp = current_timestamp 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()) 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.vlm_processed = True
existing_image.save() existing_image.save()
else: else: