perf: improve platform compatibility checks

This commit is contained in:
Soulter
2025-04-10 11:01:04 +08:00
parent e349671fdf
commit cd18806c39
3 changed files with 8 additions and 1 deletions

View File

@@ -248,6 +248,9 @@ CONFIG_METADATA_2 = {
"description": "平台设置",
"type": "object",
"items": {
"plugin_enable": {
"invisible": True, # 隐藏插件启用配置
},
"unique_session": {
"description": "会话隔离",
"type": "bool",

View File

@@ -3,6 +3,7 @@ from ..context import PipelineContext
from typing import Union, AsyncGenerator
from astrbot.core.platform.astr_message_event import AstrMessageEvent
from astrbot.core.star.star import star_map
from astrbot.core.star.star_handler import StarHandlerMetadata
from astrbot.core import logger
@@ -34,6 +35,8 @@ class PlatformCompatibilityStage(Stage):
# 标记不兼容的处理器
for handler in activated_handlers:
if not isinstance(handler, StarHandlerMetadata):
continue
# 检查处理器是否在当前平台启用
enabled = handler.is_enabled_for_platform(platform_id)
if not enabled:
@@ -43,6 +46,7 @@ class PlatformCompatibilityStage(Stage):
f"[PlatformCompatibilityStage] 插件 {plugin_name} 在平台 {platform_id} 未启用,标记处理器 {handler.handler_name} 为平台不兼容"
)
# 设置处理器为平台不兼容状态
# TODO: 更好的标记方式
handler.platform_compatible = False
else:
# 确保处理器为平台兼容状态

View File

@@ -15,7 +15,7 @@ class SharedPreferences:
def _save_preferences(self):
with open(self.path, "w") as f:
json.dump(self._data, f, indent=4)
json.dump(self._data, f, indent=4, ensure_ascii=False)
f.flush()
def get(self, key, default=None):