modified: app.py
modified: templates/redeem_giveaway.html modified: templates/server_giveaways.html modified: templates/user_giveaways.html
This commit is contained in:
113
app.py
113
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,19 +445,12 @@ 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()
|
||||
|
||||
if user_data and user_data['permission'] >= 8:
|
||||
# Hole die Giveaways für diesen Server
|
||||
# Hole die Giveaways für den spezifischen Server
|
||||
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s", (guild_id,))
|
||||
giveaways = cursor.fetchall()
|
||||
|
||||
@@ -467,8 +458,104 @@ def server_giveaways(guild_id):
|
||||
connection.close()
|
||||
|
||||
return render_template("server_giveaways.html", giveaways=giveaways, guild_id=guild_id)
|
||||
return redirect(url_for("landing_page"))
|
||||
|
||||
return redirect(url_for("user_landing_page"))
|
||||
@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)
|
||||
|
||||
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():
|
||||
|
||||
@@ -8,38 +8,19 @@
|
||||
</head>
|
||||
<body>
|
||||
{% include 'navigation.html' %}
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1 class="text-center">Giveaway Prize</h1>
|
||||
<p class="text-center">Congratulations! You have won the giveaway for <strong>{{ giveaway.name }}</strong> on
|
||||
<strong>{{ giveaway.platform }}</strong>.</p>
|
||||
<h2>Redeem Giveaway - {{ giveaway.name }}</h2>
|
||||
<p><strong>Platform:</strong> {{ giveaway.platform }}</p>
|
||||
|
||||
{% if key %}
|
||||
<!-- Wenn der Key aufgedeckt wurde -->
|
||||
<div class="card mt-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Your Key</h5>
|
||||
<p class="card-text">{{ key }}</p>
|
||||
<div class="alert alert-success">
|
||||
<strong>Game Key:</strong> {{ key }}
|
||||
</div>
|
||||
</div>
|
||||
<a href="{{ url_for('user_giveaways') }}" class="btn btn-primary mt-4">Back to Giveaways</a>
|
||||
{% else %}
|
||||
<!-- Wenn der Key noch nicht aufgedeckt wurde -->
|
||||
<div class="card mt-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Claim Your Key</h5>
|
||||
<p class="card-text">Do you want to reveal your game key? Once revealed, it will be marked as claimed and cannot be undone.</p>
|
||||
|
||||
<form method="POST">
|
||||
<button type="submit" class="btn btn-success">Reveal Key</button>
|
||||
<form method="post">
|
||||
<button type="submit" class="btn btn-primary">Redeem Giveaway</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<a href="{{ url_for('user_giveaways') }}" class="btn btn-secondary mt-4">Back to Giveaways</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<td>{{ giveaway.platform }}</td>
|
||||
<td>{{ giveaway.winner_dc_id }}</td>
|
||||
<td>
|
||||
<a href="{{ url_for('edit_giveaway', giveaway_id=giveaway.id, guild_id=g.guild_id) }}" class="btn btn-warning">Edit</a>
|
||||
<a href="{{ url_for('edit_giveaway', guild_id=guild_id, uuid=giveaway['uuid']) }}" class="btn btn-primary">Edit Giveaway</a>
|
||||
<a href="{{ url_for('delete_giveaway', giveaway_id=giveaway.id, guild_id=g.guild_id) }}" class="btn btn-danger">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -3,36 +3,37 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Your Giveaways</title>
|
||||
<title>Your Won Giveaways</title>
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
{% include 'navigation.html' %}
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1 class="text-center">Your Giveaways</h1>
|
||||
<p class="text-center">Here you can view the giveaways you've won.</p>
|
||||
|
||||
<div class="row mt-4">
|
||||
{% if giveaways %}
|
||||
{% for giveaway in giveaways %}
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ giveaway.name }}</h5>
|
||||
<p class="card-text">Platform: {{ giveaway.platform }}</p>
|
||||
<a href="{{ url_for('redeem_giveaway', uuid=giveaway.uuid) }}" class="btn btn-primary">Claim Your Key</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<h2>Your Won Giveaways on Server {{ guild_id }}</h2>
|
||||
<table class="table table-bordered mt-4">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Platform</th>
|
||||
<th>Redeem</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for giveaway in won_giveaways %}
|
||||
<tr>
|
||||
<td>{{ giveaway.name }}</td>
|
||||
<td>{{ giveaway.platform }}</td>
|
||||
<td>
|
||||
{% if giveaway.aktiv %}
|
||||
<span class="badge badge-success">Redeemed</span>
|
||||
{% else %}
|
||||
<p class="text-center">You haven't won any giveaways yet.</p>
|
||||
<a href="{{ url_for('redeem_giveaway', guild_id=guild_id, uuid=giveaway['uuid']) }}" class="btn btn-primary btn-sm">Redeem</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user