perf: Star 插件类优化

This commit is contained in:
Soulter
2024-12-12 19:07:04 +08:00
parent 6a5f3720a2
commit 5144dd09f1
2 changed files with 17 additions and 8 deletions
+17 -2
View File
@@ -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
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)
-6
View File
@@ -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:
'''