fix(gewe): should not block main launching process (#1163) (#1252)

This commit is contained in:
Junyan Qin (Chin)
2025-03-30 23:14:56 +08:00
committed by GitHub
parent 23a0dba470
commit f5e98d4ebb
2 changed files with 16 additions and 14 deletions
+2 -2
View File
@@ -110,7 +110,7 @@ class PlatformManager:
if len(self.adapters) == 0: if len(self.adapters) == 0:
self.ap.logger.warning('未运行平台适配器,请根据文档配置并启用平台适配器。') 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 index = -2
for i, adapter in enumerate(self.adapters): for i, adapter in enumerate(self.adapters):
@@ -137,7 +137,7 @@ class PlatformManager:
**config **config
} }
self.ap.platform_cfg.data['platform-adapters'][real_index] = new_cfg 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): async def send(self, event: platform_events.MessageEvent, msg: platform_message.MessageChain, adapter: msadapter.MessagePlatformAdapter):
+14 -12
View File
@@ -428,26 +428,28 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter):
self.config["token"] self.config["token"]
) )
app_id, error_msg = self.bot.login(self.config["app_id"]) def gewechat_login_process():
if error_msg:
raise Exception(f"Gewechat 登录失败: {error_msg}")
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 self.ap.platform_mgr.write_back_config('gewechat', self, self.config)
profile = self.bot.get_profile(self.config["app_id"])
self.bot_account_id = profile["data"]["nickName"] # 获取 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"]) ret = self.bot.set_callback(self.config["token"], self.config["callback_url"])
print('设置 Gewechat 回调:', ret) print('设置 Gewechat 回调:', ret)
threading.Thread(target=thread_set_callback).start() threading.Thread(target=gewechat_login_process).start()
async def shutdown_trigger_placeholder(): async def shutdown_trigger_placeholder():
while True: while True: