MCPcopy
hub / github.com/AstrBotDevs/AstrBot / _load_config

Function _load_config

astrbot/cli/commands/cmd_conf.py:81–101  ·  view source on GitHub ↗

Load or initialize config file

()

Source from the content-addressed store, hash-verified

79
80
81def _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
104def _save_config(config: dict[str, Any]) -> None:

Callers 3

set_configFunction · 0.85
get_configFunction · 0.85
passwordFunction · 0.85

Calls 4

check_astrbot_rootFunction · 0.85
write_textMethod · 0.80
get_astrbot_rootFunction · 0.50
read_textMethod · 0.45

Tested by

no test coverage detected