From 5144dd09f1e2f90d1b578d2cc52cad1695c471a7 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 12 Dec 2024 19:07:04 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20Star=20=E6=8F=92=E4=BB=B6=E7=B1=BB?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/star/__init__.py | 19 +++++++++++++++++-- astrbot/core/star/star.py | 6 ------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/astrbot/core/star/__init__.py b/astrbot/core/star/__init__.py index 2574ba6dc..ca4b9ddb6 100644 --- a/astrbot/core/star/__init__.py +++ b/astrbot/core/star/__init__.py @@ -1,4 +1,19 @@ -from .star import Star, StarMetadata +from .star import StarMetadata from .star_manager import PluginManager from .context import Context -from astrbot.core.provider import Provider \ No newline at end of file +from astrbot.core.provider import Provider +from astrbot.core.utils.command_parser import CommandParserMixin +from astrbot.core import html_renderer + +class Star(CommandParserMixin): + '''所有插件(Star)的父类,所有插件都应该继承于这个类''' + def __init__(self, context: Context): + self.context = context + + async def text_to_image(self, text: str, return_url = True) -> str: + '''将文本转换为图片''' + return await html_renderer.render_t2i(text, return_url=return_url) + + async def html_render(self, tmpl: str, data: dict, return_url = True) -> str: + '''渲染 HTML''' + return await html_renderer.render_custom_template(tmpl, data, return_url=return_url) \ No newline at end of file diff --git a/astrbot/core/star/star.py b/astrbot/core/star/star.py index ddae6d7fb..cee93c5e6 100644 --- a/astrbot/core/star/star.py +++ b/astrbot/core/star/star.py @@ -3,17 +3,11 @@ from __future__ import annotations from types import ModuleType from typing import List, Dict from dataclasses import dataclass -from astrbot.core.utils.command_parser import CommandParserMixin star_registry: List[StarMetadata] = [] star_map: Dict[str, StarMetadata] = {} '''key 是模块路径,__module__''' -class Star(CommandParserMixin): - '''所有插件(Star)的父类,所有插件都应该继承于这个类''' - def __init__(self): - pass - @dataclass class StarMetadata: '''