From 79ebb0b0bd62998282de33a1e4adf012cbefb384 Mon Sep 17 00:00:00 2001 From: Cursor User Date: Wed, 18 Jun 2025 18:00:38 +0200 Subject: [PATCH] Fix dependency and config validation issues - Removed invalid 'pip-requirements' line from requirements.txt that was causing pip errors - Added config validation before bot restart to prevent startup failures - Check for essential environment variables (API_ID, API_HASH, SESSION) in .env or config.py - Prevent restart attempts when configuration is incomplete - Enhanced error logging with specific config issues - Update script now validates environment before attempting restart --- requirements.txt | 1 - update_script.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e4b8536..16e4ba9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -pip-requirements google-api-python-client google-auth-httplib2 google-auth-oauthlib diff --git a/update_script.py b/update_script.py index e9518af..42b7ad5 100644 --- a/update_script.py +++ b/update_script.py @@ -132,10 +132,51 @@ def main(): print("✅ Update completed successfully!") return True +def validate_config(): + """Check if essential config is available before restart.""" + config_issues = [] + + # Check for essential environment variables + essential_vars = ['API_ID', 'API_HASH', 'SESSION'] + + # Check .env file + if os.path.exists('.env'): + with open('.env', 'r') as f: + env_content = f.read() + for var in essential_vars: + if f"{var}=" not in env_content or f"{var}=" in env_content and env_content.split(f"{var}=")[1].split('\n')[0].strip() == "": + config_issues.append(f"{var} not set or empty in .env") + else: + # Check config.py + if os.path.exists('config.py'): + with open('config.py', 'r') as f: + config_content = f.read() + for var in essential_vars: + if var not in config_content: + config_issues.append(f"{var} not found in config.py") + else: + config_issues.append("No .env or config.py file found") + + return config_issues + def restart_bot(): """Restart the bot after update.""" print("🔄 Restarting Ultroid...") + # Validate configuration first + config_issues = validate_config() + if config_issues: + print("⚠️ Configuration issues detected:") + for issue in config_issues: + print(f" - {issue}") + print("❌ Cannot restart bot without proper configuration") + with open("update_restart.log", "w") as f: + f.write(f"Restart failed due to config issues at {time.strftime('%Y-%m-%d %H:%M:%S')}\n") + for issue in config_issues: + f.write(f"Config issue: {issue}\n") + f.write("Please set up your bot configuration before restart\n") + return + # Check if we have a virtual environment venv_python = None if os.path.exists("venv/bin/python"):