From c9079b929936bd9f0a6be46e84223a535d3e290d Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Sun, 13 Apr 2025 06:06:02 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E9=A3=9E?= =?UTF-8?q?=E4=B9=A6=E9=80=82=E9=85=8D=E5=99=A8=E8=BD=AC=E6=8D=A2=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E8=BF=87=E7=A8=8B=E4=B8=AD=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=BD=AC=E5=8C=96Base64=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/sources/lark/lark_event.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/astrbot/core/platform/sources/lark/lark_event.py b/astrbot/core/platform/sources/lark/lark_event.py index 544a7a5be..fdb873ce3 100644 --- a/astrbot/core/platform/sources/lark/lark_event.py +++ b/astrbot/core/platform/sources/lark/lark_event.py @@ -1,6 +1,8 @@ import json import uuid +import base64 import lark_oapi as lark +from io import BytesIO from typing import List from astrbot.api.event import AstrMessageEvent, MessageChain from astrbot.api.message_components import Plain, Image as AstrBotImage, At @@ -27,22 +29,29 @@ class LarkMessageEvent(AstrMessageEvent): _stage.append({"tag": "at", "user_id": comp.qq, "style": []}) elif isinstance(comp, AstrBotImage): file_path = "" + image_file = None + if comp.file and comp.file.startswith("file:///"): file_path = comp.file.replace("file:///", "") elif comp.file and comp.file.startswith("http"): image_file_path = await download_image_by_url(comp.file) file_path = image_file_path elif comp.file and comp.file.startswith("base64://"): - pass + base64_str = comp.file[9:] + image_data = base64.b64decode(base64_str) + image_file = BytesIO(image_data).getvalue() else: file_path = comp.file + if image_file is None: + image_file = open(file_path, "rb") + request = ( CreateImageRequest.builder() .request_body( CreateImageRequestBody.builder() .image_type("message") - .image(open(file_path, "rb")) + .image(image_file) .build() ) .build() @@ -51,7 +60,7 @@ class LarkMessageEvent(AstrMessageEvent): if not response.success(): logger.error(f"无法上传飞书图片({response.code}): {response.msg}") image_key = response.data.image_key - print(image_key) + logger.debug(image_key) ret.append(_stage) ret.append([{"tag": "img", "image_key": image_key}]) _stage.clear()