modified: app.py

modified:   bot.py
	modified:   templates/server_admin_dashboard.html
	new file:   templates/server_settings.html
This commit is contained in:
SimolZimol
2025-08-19 18:35:32 +02:00
parent 59a9960155
commit 196d2ac570
4 changed files with 1298 additions and 8 deletions

98
app.py
View File

@@ -580,6 +580,104 @@ def edit_giveaway(guild_id, uuid):
return render_template("edit_giveaway.html", giveaway=giveaway, guild_id=guild_id)
return redirect(url_for("landing_page"))
@app.route("/server_settings/<int:guild_id>", methods=["GET", "POST"])
def server_settings(guild_id):
"""Serverbasierte Einstellungen für Moderation und andere Features."""
if is_server_admin(guild_id):
connection = get_db_connection()
cursor = connection.cursor(dictionary=True)
if request.method == "POST":
# Verarbeite Formular-Daten
try:
# Hole aktuelle Einstellungen
cursor.execute("SELECT * FROM guild_settings WHERE guild_id = %s", (guild_id,))
current_settings = cursor.fetchone()
# Parse Formular-Daten
mute_role_id = request.form.get("mute_role_id")
mute_role_name = request.form.get("mute_role_name", "Muted")
auto_create_mute_role = bool(request.form.get("auto_create_mute_role"))
max_warn_threshold = int(request.form.get("max_warn_threshold", 3))
auto_mute_on_warns = bool(request.form.get("auto_mute_on_warns"))
auto_mute_duration = request.form.get("auto_mute_duration", "1h")
log_channel_id = request.form.get("log_channel_id")
mod_log_enabled = bool(request.form.get("mod_log_enabled"))
# Validierung
if max_warn_threshold < 1 or max_warn_threshold > 10:
flash("Warn-Limit muss zwischen 1 und 10 liegen.", "danger")
return redirect(url_for("server_settings", guild_id=guild_id))
# Zeitformat validieren
time_units = {'m': 60, 'h': 3600, 'd': 86400}
if auto_mute_duration and (not auto_mute_duration[-1] in time_units or not auto_mute_duration[:-1].isdigit()):
flash("Ungültiges Zeitformat für Auto-Mute-Dauer. Verwende: 10m, 1h, 2d", "danger")
return redirect(url_for("server_settings", guild_id=guild_id))
# Konvertiere leere Strings zu NULL
mute_role_id = int(mute_role_id) if mute_role_id and mute_role_id.isdigit() else None
log_channel_id = int(log_channel_id) if log_channel_id and log_channel_id.isdigit() else None
# Update oder Insert Einstellungen
if current_settings:
cursor.execute("""
UPDATE guild_settings
SET mute_role_id = %s, mute_role_name = %s, auto_create_mute_role = %s,
max_warn_threshold = %s, auto_mute_on_warns = %s, auto_mute_duration = %s,
log_channel_id = %s, mod_log_enabled = %s
WHERE guild_id = %s
""", (mute_role_id, mute_role_name, auto_create_mute_role, max_warn_threshold,
auto_mute_on_warns, auto_mute_duration, log_channel_id, mod_log_enabled, guild_id))
else:
cursor.execute("""
INSERT INTO guild_settings
(guild_id, mute_role_id, mute_role_name, auto_create_mute_role, max_warn_threshold,
auto_mute_on_warns, auto_mute_duration, log_channel_id, mod_log_enabled)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
""", (guild_id, mute_role_id, mute_role_name, auto_create_mute_role, max_warn_threshold,
auto_mute_on_warns, auto_mute_duration, log_channel_id, mod_log_enabled))
connection.commit()
flash("Server-Einstellungen erfolgreich gespeichert!", "success")
except ValueError as e:
flash(f"Fehler bei der Eingabe: {str(e)}", "danger")
except Exception as e:
flash(f"Fehler beim Speichern der Einstellungen: {str(e)}", "danger")
connection.rollback()
# Lade aktuelle Einstellungen
cursor.execute("SELECT * FROM guild_settings WHERE guild_id = %s", (guild_id,))
settings = cursor.fetchone()
# Falls keine Einstellungen existieren, erstelle Default-Werte
if not settings:
settings = {
"guild_id": guild_id,
"mute_role_id": None,
"mute_role_name": "Muted",
"auto_create_mute_role": True,
"max_warn_threshold": 3,
"auto_mute_on_warns": False,
"auto_mute_duration": "1h",
"log_channel_id": None,
"mod_log_enabled": True
}
# Hole Servername
cursor.execute("SELECT name FROM guilds WHERE guild_id = %s", (guild_id,))
guild_name_result = cursor.fetchone()
guild_name = guild_name_result["name"] if guild_name_result else "Unknown Guild"
cursor.close()
connection.close()
return render_template("server_settings.html", settings=settings, guild_id=guild_id, guild_name=guild_name)
flash("Du hast keine Berechtigung, auf die Server-Einstellungen zuzugreifen.", "danger")
return redirect(url_for("user_landing_page"))
@app.route("/user_giveaways/<int:guild_id>")
def user_giveaways(guild_id):
"""Zeigt dem Benutzer die Giveaways an, die er auf einem bestimmten Server gewonnen hat."""