From 5f07a9ae95c9a49650abf2f4030d4dcccd3c1572 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 11 Feb 2025 01:23:50 +0800 Subject: [PATCH] perf(core): better handle in loading platforms --- astrbot/core/platform/manager.py | 35 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/astrbot/core/platform/manager.py b/astrbot/core/platform/manager.py index 47f5e643f..65b718101 100644 --- a/astrbot/core/platform/manager.py +++ b/astrbot/core/platform/manager.py @@ -15,24 +15,23 @@ class PlatformManager(): self.settings = config['platform_settings'] self.event_queue = event_queue - for platform in self.platforms_config: - if not platform['enable']: - continue - match platform['type']: - case "aiocqhttp": - from .sources.aiocqhttp.aiocqhttp_platform_adapter import AiocqhttpAdapter # noqa: F401 - case "qq_official": - from .sources.qqofficial.qqofficial_platform_adapter import QQOfficialPlatformAdapter # noqa: F401 - case "vchat": - try: - from .sources.vchat.vchat_platform_adapter import VChatPlatformAdapter # noqa: F401 - except BaseException: - logger.warning("当前 astrbot 已不维护 vchat 的接入,如有需要请 pip 安装 vchat 然后重启") - case "gewechat": - from .sources.gewechat.gewechat_platform_adapter import GewechatPlatformAdapter # noqa: F401 - case "lark": - from .sources.lark.lark_adapter import LarkPlatformAdapter # noqa: F401 - + try: + for platform in self.platforms_config: + if not platform['enable']: + continue + match platform['type']: + case "aiocqhttp": + from .sources.aiocqhttp.aiocqhttp_platform_adapter import AiocqhttpAdapter # noqa: F401 + case "qq_official": + from .sources.qqofficial.qqofficial_platform_adapter import QQOfficialPlatformAdapter # noqa: F401 + case "gewechat": + from .sources.gewechat.gewechat_platform_adapter import GewechatPlatformAdapter # noqa: F401 + case "lark": + from .sources.lark.lark_adapter import LarkPlatformAdapter # noqa: F401 + except (ImportError, ModuleNotFoundError) as e: + logger.error(f"加载平台适配器 {platform['type']} 失败,原因:{e}。请检查依赖库是否安装。提示:可以在 管理面板->控制台->安装Pip库 中安装依赖库。") + except Exception as e: + logger.error(f"加载平台适配器 {platform['type']} 失败,原因:{e}。") async def initialize(self): for platform in self.platforms_config: