modified: app.py
This commit is contained in:
22
app.py
22
app.py
@@ -38,15 +38,14 @@ ASKNOTES_INTRO_FILE = "asknotesintro.txt"
|
||||
bot_process = None
|
||||
|
||||
def bot_status():
|
||||
"""Überprüft, ob der Bot läuft, indem der Prozess nach dem Skript-Namen durchsucht wird."""
|
||||
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
||||
# Überprüfen, ob 'bot.py' im Befehlszeilen-Argument des Prozesses vorhanden ist
|
||||
if 'python' in proc.info['name'] and 'bot.py' in proc.info['cmdline']:
|
||||
return True
|
||||
"""Überprüft, ob der Bot läuft."""
|
||||
global bot_process
|
||||
if bot_process is None:
|
||||
return False
|
||||
return bot_process.poll() is None # None bedeutet, dass der Prozess noch läuft
|
||||
|
||||
def start_bot():
|
||||
"""Startet den Bot, falls er nicht bereits läuft."""
|
||||
"""Startet den Bot."""
|
||||
global bot_process
|
||||
if not bot_status():
|
||||
bot_process = subprocess.Popen(["python", "bot.py"], cwd=os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -56,12 +55,9 @@ def start_bot():
|
||||
def stop_bot():
|
||||
"""Stoppt den Bot."""
|
||||
global bot_process
|
||||
if bot_status():
|
||||
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
||||
if 'python' in proc.info['name'] and 'bot.py' in proc.info['cmdline']:
|
||||
proc.terminate()
|
||||
proc.wait()
|
||||
print("Bot wurde gestoppt.")
|
||||
if bot_process and bot_status():
|
||||
bot_process.terminate()
|
||||
bot_process.wait() # Warten, bis der Prozess beendet ist
|
||||
bot_process = None
|
||||
else:
|
||||
print("Bot läuft nicht.")
|
||||
@@ -203,7 +199,7 @@ def admin_dashboard():
|
||||
connection.close()
|
||||
|
||||
if user_data and user_data["permission"] >= 8:
|
||||
return render_template("admin_dashboard.html", user_info=user_info)
|
||||
return render_template("admin_dashboard.html", user_info=user_info, bot_running=bot_status())
|
||||
else:
|
||||
return redirect(url_for("user_dashboard"))
|
||||
return redirect(url_for("landing_page"))
|
||||
|
||||
Reference in New Issue
Block a user