Merge pull request #186 from Naptie/contrib

refactor: 使用 Base64 编码的表情包 CQ 码
pull/195/head
SengokuCola 2025-03-11 11:47:08 +08:00 committed by GitHub
commit 450f378791
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 10 deletions

View File

@ -1,6 +1,5 @@
import base64
import html
import os
import time
from dataclasses import dataclass
from typing import Dict, Optional
@ -17,7 +16,7 @@ from urllib3.util import create_urllib3_context
from ..models.utils_model import LLM_request
from .config import global_config
from .mapper import emojimapper
from .utils_image import storage_emoji, storage_image
from .utils_image import image_path_to_base64, storage_emoji, storage_image
from .utils_user import get_user_nickname
driver = get_driver()
@ -328,15 +327,10 @@ class CQCode:
Returns:
表情包CQ码字符串
"""
# 确保使用绝对路径
abs_path = os.path.abspath(file_path)
# 转义特殊字符
escaped_path = abs_path.replace('&', '&') \
.replace('[', '[') \
.replace(']', ']') \
.replace(',', ',')
base64_content = image_path_to_base64(file_path)
# 生成CQ码设置sub_type=1表示这是表情包
return f"[CQ:image,file=file:///{escaped_path},sub_type=1]"
return f"[CQ:image,file=base64://{base64_content},sub_type=1]"
class CQCode_tool: