modified: app.py

modified:   templates/settings.html
This commit is contained in:
SimolZimol
2024-09-03 09:21:00 +02:00
parent b093d88178
commit 8a2245a61b
2 changed files with 38 additions and 5 deletions

33
app.py
View File

@@ -6,6 +6,10 @@ import psutil
app = Flask(__name__)
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
# Globale Variablen für die Intros
INTRO_FILE = "introduction.txt"
ASKNOTES_INTRO_FILE = "asknotesintro.txt"
# Speichern der Prozess-ID
bot_process = None
@@ -34,6 +38,18 @@ def stop_bot():
else:
print("Bot läuft nicht.")
def load_text_file(file_path):
"""Lädt den Inhalt einer Textdatei."""
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
return ""
def save_text_file(file_path, content):
"""Speichert den Inhalt in einer Textdatei."""
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)
@app.route("/")
def index():
if "username" in session:
@@ -75,9 +91,20 @@ def stop():
def settings():
if "username" in session:
if request.method == "POST":
# Hier kannst du Formulareingaben für Bot-Einstellungen verarbeiten
pass
return render_template("settings.html")
introduction = request.form.get("introduction")
asknotes_introduction = request.form.get("asknotes_introduction")
# Speichern der Intros
save_text_file(INTRO_FILE, introduction)
save_text_file(ASKNOTES_INTRO_FILE, asknotes_introduction)
return redirect(url_for("settings"))
# Laden der aktuellen Inhalte aus den Textdateien
introduction = load_text_file(INTRO_FILE)
asknotes_introduction = load_text_file(ASKNOTES_INTRO_FILE)
return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction)
return redirect(url_for("login"))
if __name__ == "__main__":