32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import yaml
|
||
import os
|
||
|
||
|
||
def load_config(filename="data/config.yaml"):
|
||
"""Загрузка конфигурации с установкой значений по умолчанию"""
|
||
try:
|
||
if not os.path.exists(filename):
|
||
raise FileNotFoundError(f"Config file not found: {filename}")
|
||
|
||
with open(filename, "r") as file:
|
||
config = yaml.safe_load(file)
|
||
|
||
# Установка значений по умолчанию
|
||
defaults = {
|
||
"command_prefix": "/media",
|
||
"trusted_homeservers": []
|
||
}
|
||
|
||
for key, value in defaults.items():
|
||
config.setdefault(key, value)
|
||
|
||
# Проверка обязательных параметров
|
||
required = ["homeserver_url", "bot_user", "bot_password"]
|
||
for param in required:
|
||
if param not in config:
|
||
raise ValueError(f"Missing required config parameter: {param}")
|
||
|
||
return config
|
||
except (FileNotFoundError, yaml.YAMLError, ValueError) as e:
|
||
print(f"[CRITICAL] Config error: {str(e)}")
|
||
exit(1) |