实例化一个平台
(self, platform_config: dict)
| 100 | self._start_platform_task("webchat", webchat_inst) |
| 101 | |
| 102 | async def load_platform(self, platform_config: dict) -> None: |
| 103 | """实例化一个平台""" |
| 104 | # 动态导入 |
| 105 | try: |
| 106 | if not platform_config["enable"]: |
| 107 | return |
| 108 | platform_id = platform_config.get("id") |
| 109 | if not self._is_valid_platform_id(platform_id): |
| 110 | sanitized_id, changed = self._sanitize_platform_id(platform_id) |
| 111 | if sanitized_id and changed: |
| 112 | logger.warning( |
| 113 | "平台 ID %r 包含非法字符 ':' 或 '!',已替换为 %r。", |
| 114 | platform_id, |
| 115 | sanitized_id, |
| 116 | ) |
| 117 | platform_config["id"] = sanitized_id |
| 118 | self.astrbot_config.save_config() |
| 119 | else: |
| 120 | logger.error( |
| 121 | f"平台 ID {platform_id!r} 不能为空,跳过加载该平台适配器。", |
| 122 | ) |
| 123 | return |
| 124 | |
| 125 | logger.info( |
| 126 | "Loading IM platform adapter %s(%s) ...", |
| 127 | platform_config["type"], |
| 128 | platform_config["id"], |
| 129 | ) |
| 130 | match platform_config["type"]: |
| 131 | case "aiocqhttp": |
| 132 | from .sources.aiocqhttp.aiocqhttp_platform_adapter import ( |
| 133 | AiocqhttpAdapter, # noqa: F401 |
| 134 | ) |
| 135 | case "qq_official": |
| 136 | from .sources.qqofficial.qqofficial_platform_adapter import ( |
| 137 | QQOfficialPlatformAdapter, # noqa: F401 |
| 138 | ) |
| 139 | case "qq_official_webhook": |
| 140 | from .sources.qqofficial_webhook.qo_webhook_adapter import ( |
| 141 | QQOfficialWebhookPlatformAdapter, # noqa: F401 |
| 142 | ) |
| 143 | case "lark": |
| 144 | from .sources.lark.lark_adapter import ( |
| 145 | LarkPlatformAdapter, # noqa: F401 |
| 146 | ) |
| 147 | case "dingtalk": |
| 148 | from .sources.dingtalk.dingtalk_adapter import ( |
| 149 | DingtalkPlatformAdapter, # noqa: F401 |
| 150 | ) |
| 151 | case "telegram": |
| 152 | from .sources.telegram.tg_adapter import ( |
| 153 | TelegramPlatformAdapter, # noqa: F401 |
| 154 | ) |
| 155 | case "wecom": |
| 156 | from .sources.wecom.wecom_adapter import ( |
| 157 | WecomPlatformAdapter, # noqa: F401 |
| 158 | ) |
| 159 | case "wecom_ai_bot": |
no test coverage detected