51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import os
|
|
import configparser
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
def validate_env_vars():
|
|
"""Validate that required environment variables are set and non-empty."""
|
|
required_vars = [
|
|
'DISCORD_TOKEN',
|
|
'ALLOWED_GUILD_ID',
|
|
'PANEL_URL',
|
|
'CLIENT_API_KEY',
|
|
'APPLICATION_API_KEY'
|
|
]
|
|
|
|
missing_vars = [var for var in required_vars if not os.getenv(var)]
|
|
if missing_vars:
|
|
raise ValueError(f"Missing required environment variables: {', '.join(missing_vars)}")
|
|
|
|
def generate_config():
|
|
"""Generate config.ini from environment variables."""
|
|
# Validate environment variables first
|
|
validate_env_vars()
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
# Discord section - ensure all values are strings
|
|
config['Discord'] = {
|
|
'Token': str(os.getenv('DISCORD_TOKEN')),
|
|
'AllowedGuildID': str(os.getenv('ALLOWED_GUILD_ID'))
|
|
}
|
|
|
|
# Pterodactyl section - ensure all values are strings
|
|
config['Pterodactyl'] = {
|
|
'PanelURL': str(os.getenv('PANEL_URL')),
|
|
'ClientAPIKey': str(os.getenv('CLIENT_API_KEY')),
|
|
'ApplicationAPIKey': str(os.getenv('APPLICATION_API_KEY'))
|
|
}
|
|
|
|
# Write to file
|
|
config_path = Path(os.getenv('CONFIG_PATH', 'config.ini'))
|
|
config_path.parent.mkdir(exist_ok=True, parents=True)
|
|
|
|
with open(config_path, 'w') as configfile:
|
|
config.write(configfile)
|
|
print(f"Config file generated at {config_path}")
|
|
|
|
if __name__ == "__main__":
|
|
load_dotenv()
|
|
generate_config()
|