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)
|
Session(app)
|
||||||
print(f"Session Type: {app.config['SESSION_TYPE']}")
|
print(f"Session Type: {app.config['SESSION_TYPE']}")
|
||||||
|
|
||||||
# Verwende Umgebungsvariablen für die Datenbankverbindung
|
|
||||||
DB_HOST = os.getenv("DB_HOST")
|
DB_HOST = os.getenv("DB_HOST")
|
||||||
DB_PORT = os.getenv("DB_PORT")
|
DB_PORT = os.getenv("DB_PORT")
|
||||||
DB_USER = os.getenv("DB_USER")
|
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"
|
DISCORD_API_URL = "https://discord.com/api/users/@me"
|
||||||
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
|
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
|
||||||
|
|
||||||
# Speichern der Prozess-ID
|
|
||||||
bot_process = None
|
bot_process = None
|
||||||
|
|
||||||
def bot_status():
|
def bot_status():
|
||||||
@@ -447,19 +445,12 @@ def user_dashboard(guild_id):
|
|||||||
|
|
||||||
@app.route("/server_giveaways/<int:guild_id>")
|
@app.route("/server_giveaways/<int:guild_id>")
|
||||||
def server_giveaways(guild_id):
|
def server_giveaways(guild_id):
|
||||||
"""Serverbasiertes Giveaway-Management"""
|
"""Serverbasiertes Giveaway-Management."""
|
||||||
if g.user_info:
|
if is_server_admin(guild_id):
|
||||||
user_id = g.user_info["id"]
|
|
||||||
|
|
||||||
# Überprüfe, ob der Benutzer Admin-Rechte auf diesem Server hat
|
|
||||||
connection = get_db_connection()
|
connection = get_db_connection()
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s AND guild_id = %s", (user_id, guild_id))
|
# Hole die Giveaways für den spezifischen Server
|
||||||
user_data = cursor.fetchone()
|
|
||||||
|
|
||||||
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,))
|
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s", (guild_id,))
|
||||||
giveaways = cursor.fetchall()
|
giveaways = cursor.fetchall()
|
||||||
|
|
||||||
@@ -467,8 +458,104 @@ def server_giveaways(guild_id):
|
|||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
return render_template("server_giveaways.html", giveaways=giveaways, guild_id=guild_id)
|
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")
|
@app.route("/user_landing_page")
|
||||||
def user_landing_page():
|
def user_landing_page():
|
||||||
|
|||||||
@@ -8,38 +8,19 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include 'navigation.html' %}
|
{% include 'navigation.html' %}
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h1 class="text-center">Giveaway Prize</h1>
|
<h2>Redeem Giveaway - {{ giveaway.name }}</h2>
|
||||||
<p class="text-center">Congratulations! You have won the giveaway for <strong>{{ giveaway.name }}</strong> on
|
<p><strong>Platform:</strong> {{ giveaway.platform }}</p>
|
||||||
<strong>{{ giveaway.platform }}</strong>.</p>
|
|
||||||
|
|
||||||
{% if key %}
|
{% if key %}
|
||||||
<!-- Wenn der Key aufgedeckt wurde -->
|
<div class="alert alert-success">
|
||||||
<div class="card mt-4">
|
<strong>Game Key:</strong> {{ key }}
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title">Your Key</h5>
|
|
||||||
<p class="card-text">{{ key }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<a href="{{ url_for('user_giveaways') }}" class="btn btn-primary mt-4">Back to Giveaways</a>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<!-- Wenn der Key noch nicht aufgedeckt wurde -->
|
<form method="post">
|
||||||
<div class="card mt-4">
|
<button type="submit" class="btn btn-primary">Redeem Giveaway</button>
|
||||||
<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>
|
</form>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<a href="{{ url_for('user_giveaways') }}" class="btn btn-secondary mt-4">Back to Giveaways</a>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<td>{{ giveaway.platform }}</td>
|
<td>{{ giveaway.platform }}</td>
|
||||||
<td>{{ giveaway.winner_dc_id }}</td>
|
<td>{{ giveaway.winner_dc_id }}</td>
|
||||||
<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>
|
<a href="{{ url_for('delete_giveaway', giveaway_id=giveaway.id, guild_id=g.guild_id) }}" class="btn btn-danger">Delete</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -3,36 +3,37 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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">
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include 'navigation.html' %}
|
{% include 'navigation.html' %}
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h1 class="text-center">Your Giveaways</h1>
|
<h2>Your Won Giveaways on Server {{ guild_id }}</h2>
|
||||||
<p class="text-center">Here you can view the giveaways you've won.</p>
|
<table class="table table-bordered mt-4">
|
||||||
|
<thead>
|
||||||
<div class="row mt-4">
|
<tr>
|
||||||
{% if giveaways %}
|
<th>Name</th>
|
||||||
{% for giveaway in giveaways %}
|
<th>Platform</th>
|
||||||
<div class="col-md-4">
|
<th>Redeem</th>
|
||||||
<div class="card">
|
</tr>
|
||||||
<div class="card-body">
|
</thead>
|
||||||
<h5 class="card-title">{{ giveaway.name }}</h5>
|
<tbody>
|
||||||
<p class="card-text">Platform: {{ giveaway.platform }}</p>
|
{% for giveaway in won_giveaways %}
|
||||||
<a href="{{ url_for('redeem_giveaway', uuid=giveaway.uuid) }}" class="btn btn-primary">Claim Your Key</a>
|
<tr>
|
||||||
</div>
|
<td>{{ giveaway.name }}</td>
|
||||||
</div>
|
<td>{{ giveaway.platform }}</td>
|
||||||
</div>
|
<td>
|
||||||
{% endfor %}
|
{% if giveaway.aktiv %}
|
||||||
|
<span class="badge badge-success">Redeemed</span>
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user