调整登录态默认存储到provider目录
This commit is contained in:
20
robot.py
20
robot.py
@@ -278,7 +278,9 @@ class Robot:
|
||||
# 3. 这样未来切到 864 时,主链路只需要替换 provider,而不是继续改这里的大循环。
|
||||
await self.ipad_bot.run_runtime(
|
||||
ipad_config=self.ipad_config,
|
||||
state_path=str(self.ipad_config.get("state_file", "temp/wechat_ipad/config.toml") or "temp/wechat_ipad/config.toml"),
|
||||
state_path=str(
|
||||
self.ipad_config.get("state_file", "") or self._default_wechat_state_path(self.ipad_config)
|
||||
),
|
||||
logger=self.LOG,
|
||||
on_login_ready=self._on_ipad_login_ready,
|
||||
on_history_message=self._archive_startup_history_message,
|
||||
@@ -301,7 +303,7 @@ class Robot:
|
||||
3. 最后兼容历史 `wechat_ipad/config.toml`,让老环境升级后可以平滑迁移。
|
||||
"""
|
||||
base_config = dict(getattr(self.config, "wechat_ipad", {}) or {})
|
||||
state_path = str(base_config.get("state_file", "temp/wechat_ipad/config.toml") or "temp/wechat_ipad/config.toml")
|
||||
state_path = str(base_config.get("state_file", "") or self._default_wechat_state_path(base_config))
|
||||
legacy_config_path = str(
|
||||
base_config.get("legacy_config_path", "wechat_ipad/config.toml") or "wechat_ipad/config.toml"
|
||||
)
|
||||
@@ -341,6 +343,20 @@ class Robot:
|
||||
merged_config["legacy_config_path"] = legacy_config_path
|
||||
return merged_config
|
||||
|
||||
@staticmethod
|
||||
def _default_wechat_state_path(ipad_config: dict) -> str:
|
||||
"""根据当前 provider 类型返回默认的本地状态文件路径。
|
||||
|
||||
设计原因:
|
||||
1. 用户希望登录态跟随 provider 放置,避免散落在 `temp/` 目录中;
|
||||
2. 后续新增 864 等 provider 时,可以天然形成“每个 provider 自己维护自己的状态”;
|
||||
3. 这里统一在主程序收口默认路径,避免把路径规则写散到文档、脚本和 provider 内部。
|
||||
"""
|
||||
server_type = str(ipad_config.get("server_type", "legacy_855") or "legacy_855").strip().lower()
|
||||
if not server_type:
|
||||
server_type = "legacy_855"
|
||||
return os.path.join("wechat_ipad", "providers", server_type, "runtime_state.toml")
|
||||
|
||||
def _load_toml_config_if_exists(self, file_path: str) -> dict:
|
||||
"""安全读取一个 TOML 文件,缺失或格式异常时回退为空配置。"""
|
||||
normalized_path = str(file_path or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user