MatrixMediaBot/bot/config.py
2025-08-14 02:38:56 +04:00

32 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)