Load or initialize config file
()
| 79 | |
| 80 | |
| 81 | def _load_config() -> dict[str, Any]: |
| 82 | """Load or initialize config file""" |
| 83 | root = get_astrbot_root() |
| 84 | if not check_astrbot_root(root): |
| 85 | raise click.ClickException( |
| 86 | f"{root} is not a valid AstrBot root directory. Use 'astrbot init' to initialize", |
| 87 | ) |
| 88 | |
| 89 | config_path = root / "data" / "cmd_config.json" |
| 90 | if not config_path.exists(): |
| 91 | from astrbot.core.config.default import DEFAULT_CONFIG |
| 92 | |
| 93 | config_path.write_text( |
| 94 | json.dumps(DEFAULT_CONFIG, ensure_ascii=False, indent=2), |
| 95 | encoding="utf-8-sig", |
| 96 | ) |
| 97 | |
| 98 | try: |
| 99 | return json.loads(config_path.read_text(encoding="utf-8-sig")) |
| 100 | except json.JSONDecodeError as e: |
| 101 | raise click.ClickException(f"Failed to parse config file: {e!s}") |
| 102 | |
| 103 | |
| 104 | def _save_config(config: dict[str, Any]) -> None: |
no test coverage detected