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