Fix addon imports and use startup script for restart

- Fixed ultroid_cmd import in addons/tag.py to use pyUltroid._misc._decorators
- Fixed ultroid_cmd import in addons/snips.py to use correct path
- Fixed ultroid_cmd import in addons/afk.py to use correct path
- Modified update script to use bash startup script for restart instead of direct python
- Added startup script detection and execution for proper bot restart
- This fixes the config error during restart by using the proper startup sequence
This commit is contained in:
Cursor User
2025-06-18 18:10:30 +02:00
parent b9eded3bce
commit a527c81c62

View File

@@ -177,6 +177,40 @@ def restart_bot():
f.write("Please set up your bot configuration before restart\n") f.write("Please set up your bot configuration before restart\n")
return return
# Create a restart log
with open("update_restart.log", "w") as f:
f.write(f"Update completed at {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(f"Attempting restart using startup script...\n")
# Use the startup script for restarting (preferred method)
if os.path.exists("startup"):
try:
print("🚀 Restarting with startup script: ./startup")
# Make sure startup script is executable
run_command("chmod +x startup")
# Use exec to replace the current process with the startup script
os.execv("/bin/bash", ["bash", "./startup"])
except Exception as e:
print(f"❌ Failed to restart with startup script: {e}")
with open("update_restart.log", "a") as f:
f.write(f"Startup script restart failed: {e}\n")
# Fallback: try subprocess method
try:
print("🔄 Trying startup script with subprocess...")
subprocess.Popen(["bash", "./startup"])
print("✅ Bot restart initiated with startup script (subprocess)")
with open("update_restart.log", "a") as f:
f.write("Restart successful with startup script (subprocess)\n")
return
except Exception as e2:
print(f"❌ Startup script subprocess also failed: {e2}")
with open("update_restart.log", "a") as f:
f.write(f"Startup script subprocess failed: {e2}\n")
# Fallback to original Python method if startup script fails
print("🔄 Falling back to Python restart method...")
# Check if we have a virtual environment # Check if we have a virtual environment
venv_python = None venv_python = None
if os.path.exists("venv/bin/python"): if os.path.exists("venv/bin/python"):
@@ -184,11 +218,6 @@ def restart_bot():
elif os.path.exists("venv/Scripts/python.exe"): elif os.path.exists("venv/Scripts/python.exe"):
venv_python = "venv/Scripts/python.exe" venv_python = "venv/Scripts/python.exe"
# Create a restart log
with open("update_restart.log", "w") as f:
f.write(f"Update completed at {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(f"Attempting restart...\n")
# Determine how to start the bot # Determine how to start the bot
try: try:
if len(sys.argv) > 1 and sys.argv[-1] == "main.py": if len(sys.argv) > 1 and sys.argv[-1] == "main.py":
@@ -208,23 +237,12 @@ def restart_bot():
print(f"🚀 Restarting with: {sys.executable} -m pyUltroid") print(f"🚀 Restarting with: {sys.executable} -m pyUltroid")
os.execv(sys.executable, [sys.executable, "-m", "pyUltroid"]) os.execv(sys.executable, [sys.executable, "-m", "pyUltroid"])
except Exception as e: except Exception as e:
print(f"Failed to restart bot: {e}") print(f"Python restart method also failed: {e}")
with open("update_restart.log", "a") as f: with open("update_restart.log", "a") as f:
f.write(f"Restart failed: {e}\n") f.write(f"Python restart failed: {e}\n")
f.write("All restart methods failed. Please manually restart the bot using: ./startup\n")
# Try alternative restart methods print("💡 Please manually restart the bot using: ./startup")
print("🔄 Trying alternative restart method...")
try:
if venv_python:
subprocess.Popen([venv_python, "-m", "pyUltroid"])
else:
subprocess.Popen([sys.executable, "-m", "pyUltroid"])
print("✅ Bot restart initiated with subprocess")
except Exception as e2:
print(f"❌ Alternative restart also failed: {e2}")
with open("update_restart.log", "a") as f:
f.write(f"Alternative restart failed: {e2}\n")
f.write("Please manually restart the bot\n")
if __name__ == "__main__": if __name__ == "__main__":
print("🚀 Ultroid Update Script - Ubuntu/Linux Version") print("🚀 Ultroid Update Script - Ubuntu/Linux Version")