diff --git a/pkg/platform/manager.py b/pkg/platform/manager.py index acdf0990..96c50602 100644 --- a/pkg/platform/manager.py +++ b/pkg/platform/manager.py @@ -110,7 +110,7 @@ class PlatformManager: if len(self.adapters) == 0: self.ap.logger.warning('未运行平台适配器,请根据文档配置并启用平台适配器。') - async def write_back_config(self, adapter_name: str, adapter_inst: msadapter.MessagePlatformAdapter, config: dict): + def write_back_config(self, adapter_name: str, adapter_inst: msadapter.MessagePlatformAdapter, config: dict): index = -2 for i, adapter in enumerate(self.adapters): @@ -137,7 +137,7 @@ class PlatformManager: **config } self.ap.platform_cfg.data['platform-adapters'][real_index] = new_cfg - await self.ap.platform_cfg.dump_config() + self.ap.platform_cfg.dump_config_sync() async def send(self, event: platform_events.MessageEvent, msg: platform_message.MessageChain, adapter: msadapter.MessagePlatformAdapter): diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index 869e05c6..ad96971e 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -428,26 +428,28 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): self.config["token"] ) - app_id, error_msg = self.bot.login(self.config["app_id"]) - if error_msg: - raise Exception(f"Gewechat 登录失败: {error_msg}") + def gewechat_login_process(): - self.config["app_id"] = app_id + app_id, error_msg = self.bot.login(self.config["app_id"]) + if error_msg: + raise Exception(f"Gewechat 登录失败: {error_msg}") - self.ap.logger.info(f"Gewechat 登录成功,app_id: {app_id}") + self.config["app_id"] = app_id - await self.ap.platform_mgr.write_back_config('gewechat', self, self.config) + self.ap.logger.info(f"Gewechat 登录成功,app_id: {app_id}") - # 获取 nickname - profile = self.bot.get_profile(self.config["app_id"]) - self.bot_account_id = profile["data"]["nickName"] + self.ap.platform_mgr.write_back_config('gewechat', self, self.config) + + # 获取 nickname + profile = self.bot.get_profile(self.config["app_id"]) + self.bot_account_id = profile["data"]["nickName"] + + time.sleep(2) - def thread_set_callback(): - time.sleep(3) ret = self.bot.set_callback(self.config["token"], self.config["callback_url"]) print('设置 Gewechat 回调:', ret) - threading.Thread(target=thread_set_callback).start() + threading.Thread(target=gewechat_login_process).start() async def shutdown_trigger_placeholder(): while True: