mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-24 19:17:14 +00:00
refactor: 将 yirimirai 的组件集成进 platform 包
This commit is contained in:
@@ -8,8 +8,9 @@ import re
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
from mirai.models import MessageChain, Image as ImageComponent
|
||||
from mirai.models.message import MessageComponent
|
||||
# from mirai.models import MessageChain, Image as ImageComponent
|
||||
# from mirai.models.message import MessageComponent
|
||||
from ....platform.types import message as platform_message
|
||||
|
||||
from .. import strategy as strategy_model
|
||||
from ....core import entities as core_entities
|
||||
@@ -23,7 +24,7 @@ class Text2ImageStrategy(strategy_model.LongTextStrategy):
|
||||
async def initialize(self):
|
||||
self.text_render_font = ImageFont.truetype(self.ap.platform_cfg.data['long-text-process']['font-path'], 32, encoding="utf-8")
|
||||
|
||||
async def process(self, message: str, query: core_entities.Query) -> list[MessageComponent]:
|
||||
async def process(self, message: str, query: core_entities.Query) -> list[platform_message.MessageComponent]:
|
||||
img_path = self.text_to_image(
|
||||
text_str=message,
|
||||
save_as='temp/{}.png'.format(int(time.time()))
|
||||
@@ -46,7 +47,7 @@ class Text2ImageStrategy(strategy_model.LongTextStrategy):
|
||||
os.remove(compressed_path)
|
||||
|
||||
return [
|
||||
ImageComponent(
|
||||
platform_message.Image(
|
||||
base64=b64.decode('utf-8'),
|
||||
)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user