modified: app.py
modified: templates/redeem_giveaway.html modified: templates/server_giveaways.html modified: templates/user_giveaways.html
This commit is contained in:
121
app.py
121
app.py
@@ -19,7 +19,6 @@ app.config["SESSION_TYPE"] = "filesystem" # Oder 'redis' für Redis-basierte Sp
|
||||
Session(app)
|
||||
print(f"Session Type: {app.config['SESSION_TYPE']}")
|
||||
|
||||
# Verwende Umgebungsvariablen für die Datenbankverbindung
|
||||
DB_HOST = os.getenv("DB_HOST")
|
||||
DB_PORT = os.getenv("DB_PORT")
|
||||
DB_USER = os.getenv("DB_USER")
|
||||
@@ -34,7 +33,6 @@ DISCORD_TOKEN_URL = "https://discord.com/api/oauth2/token"
|
||||
DISCORD_API_URL = "https://discord.com/api/users/@me"
|
||||
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
|
||||
|
||||
# Speichern der Prozess-ID
|
||||
bot_process = None
|
||||
|
||||
def bot_status():
|
||||
@@ -447,28 +445,117 @@ def user_dashboard(guild_id):
|
||||
|
||||
@app.route("/server_giveaways/<int:guild_id>")
|
||||
def server_giveaways(guild_id):
|
||||
"""Serverbasiertes Giveaway-Management"""
|
||||
if g.user_info:
|
||||
user_id = g.user_info["id"]
|
||||
|
||||
# Überprüfe, ob der Benutzer Admin-Rechte auf diesem Server hat
|
||||
"""Serverbasiertes Giveaway-Management."""
|
||||
if is_server_admin(guild_id):
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s AND guild_id = %s", (user_id, guild_id))
|
||||
user_data = cursor.fetchone()
|
||||
# Hole die Giveaways für den spezifischen Server
|
||||
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s", (guild_id,))
|
||||
giveaways = cursor.fetchall()
|
||||
|
||||
if user_data and user_data['permission'] >= 8:
|
||||
# Hole die Giveaways für diesen Server
|
||||
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s", (guild_id,))
|
||||
giveaways = cursor.fetchall()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return render_template("server_giveaways.html", giveaways=giveaways, guild_id=guild_id)
|
||||
return redirect(url_for("landing_page"))
|
||||
|
||||
return render_template("server_giveaways.html", giveaways=giveaways, guild_id=guild_id)
|
||||
@app.route("/edit_giveaway/<int:guild_id>/<string:uuid>", methods=["GET", "POST"])
|
||||
def edit_giveaway(guild_id, uuid):
|
||||
"""Bearbeitet ein spezifisches Giveaway für einen bestimmten Server."""
|
||||
if is_server_admin(guild_id):
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
return redirect(url_for("user_landing_page"))
|
||||
if request.method == "POST":
|
||||
platform = request.form.get("platform")
|
||||
name = request.form.get("name")
|
||||
game_key = request.form.get("game_key")
|
||||
winner_dc_id = request.form.get("winner_dc_id")
|
||||
aktiv = bool(request.form.get("aktiv"))
|
||||
|
||||
# Update der Giveaways-Daten
|
||||
cursor.execute("""
|
||||
UPDATE giveaway_data
|
||||
SET platform = %s, name = %s, game_key = %s, winner_dc_id = %s, aktiv = %s
|
||||
WHERE guild_id = %s AND uuid = %s
|
||||
""", (platform, name, game_key, winner_dc_id, aktiv, guild_id, uuid))
|
||||
connection.commit()
|
||||
|
||||
flash("Giveaway updated successfully!", "success")
|
||||
return redirect(url_for("server_giveaways", guild_id=guild_id))
|
||||
|
||||
# Daten des spezifischen Giveaways laden
|
||||
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s AND uuid = %s", (guild_id, uuid))
|
||||
giveaway = cursor.fetchone()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
return render_template("edit_giveaway.html", giveaway=giveaway, guild_id=guild_id)
|
||||
return redirect(url_for("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."""
|
||||
if "discord_user" in session:
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist
|
||||
cursor.execute("""
|
||||
SELECT * FROM giveaway_data WHERE winner_dc_id = %s AND guild_id = %s
|
||||
""", (user_id, guild_id))
|
||||
won_giveaways = cursor.fetchall()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
return render_template("user_giveaways.html", won_giveaways=won_giveaways, guild_id=guild_id)
|
||||
|
||||
return redirect(url_for("landing_page"))
|
||||
|
||||
@app.route("/redeem_giveaway/<int:guild_id>/<string:uuid>", methods=["GET", "POST"])
|
||||
def redeem_giveaway(guild_id, uuid):
|
||||
"""Erlaubt dem Benutzer, einen gewonnenen Giveaway-Code für einen bestimmten Server einzulösen."""
|
||||
if "discord_user" in session:
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Überprüfen, ob der eingeloggte Benutzer der Gewinner ist
|
||||
cursor.execute("""
|
||||
SELECT * FROM giveaway_data WHERE guild_id = %s AND uuid = %s AND winner_dc_id = %s
|
||||
""", (guild_id, uuid, user_id))
|
||||
giveaway = cursor.fetchone()
|
||||
|
||||
if giveaway:
|
||||
if request.method == "POST":
|
||||
# Wenn der Benutzer den Key einlöst, setze `aktiv` auf TRUE
|
||||
cursor.execute("UPDATE giveaway_data SET aktiv = TRUE WHERE guild_id = %s AND uuid = %s", (guild_id, uuid))
|
||||
connection.commit()
|
||||
|
||||
# Key anzeigen
|
||||
flash("Giveaway redeemed successfully!", "success")
|
||||
return render_template("redeem_giveaway.html", giveaway=giveaway, key=giveaway["game_key"])
|
||||
|
||||
# Seite anzeigen, um den Key einzulösen
|
||||
return render_template("redeem_giveaway.html", giveaway=giveaway, key=None)
|
||||
|
||||
else:
|
||||
flash("You are not the winner of this giveaway or the giveaway is no longer available.", "danger")
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
return redirect(url_for("user_giveaways", guild_id=guild_id))
|
||||
|
||||
return redirect(url_for("landing_page"))
|
||||
|
||||
@app.route("/user_landing_page")
|
||||
def user_landing_page():
|
||||
|
||||
Reference in New Issue
Block a user