modified: app.py
This commit is contained in:
37
app.py
37
app.py
@@ -22,12 +22,6 @@ DB_USER = os.getenv("DB_USER")
|
||||
DB_PASS = os.getenv("DB_PASSWORD")
|
||||
DB_NAME = os.getenv("DB_DATABASE")
|
||||
|
||||
GIVEAWAY_DB_HOST = os.getenv("GIVEAWAY_DB_HOST")
|
||||
GIVEAWAY_DB_PORT = os.getenv("GIVEAWAY_DB_PORT")
|
||||
GIVEAWAY_DB_USER = os.getenv("GIVEAWAY_DB_USER")
|
||||
GIVEAWAY_DB_PASSWORD = os.getenv("GIVEAWAY_DB_PASSWORD")
|
||||
GIVEAWAY_DB_DATABASE = os.getenv("GIVEAWAY_DB_DATABASE")
|
||||
|
||||
DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
|
||||
DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
|
||||
DISCORD_REDIRECT_URI = os.getenv("DISCORD_REDIRECT_URI")
|
||||
@@ -43,17 +37,6 @@ ASKNOTES_INTRO_FILE = "asknotesintro.txt"
|
||||
# Speichern der Prozess-ID
|
||||
bot_process = None
|
||||
|
||||
def get_giveaway_db_connection():
|
||||
"""Erstellt eine Verbindung zur Giveaway-Datenbank."""
|
||||
connection = mysql.connector.connect(
|
||||
host=os.getenv("GIVEAWAY_DB_HOST"),
|
||||
port=os.getenv("GIVEAWAY_DB_PORT"),
|
||||
user=os.getenv("GIVEAWAY_DB_USER"),
|
||||
password=os.getenv("GIVEAWAY_DB_PASSWORD"),
|
||||
database=os.getenv("GIVEAWAY_DB_DATABASE")
|
||||
)
|
||||
return connection
|
||||
|
||||
def bot_status():
|
||||
"""Überprüft, ob der Bot läuft."""
|
||||
global bot_process
|
||||
@@ -413,7 +396,7 @@ def download_logs():
|
||||
def admin_giveaways():
|
||||
"""Zeigt eine Liste aller Giveaways an und ermöglicht das Bearbeiten und Sortieren."""
|
||||
if is_admin():
|
||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
connection = get_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Sortierung nach bestimmten Feldern
|
||||
@@ -421,7 +404,7 @@ def admin_giveaways():
|
||||
order = request.args.get("order", "asc") # Standardmäßig aufsteigend sortieren
|
||||
|
||||
# Holen aller Giveaways aus der Datenbank
|
||||
cursor.execute(f"SELECT * FROM giveaways ORDER BY {sort_field} {order}")
|
||||
cursor.execute(f"SELECT * FROM giveaway_data ORDER BY {sort_field} {order}")
|
||||
giveaways = cursor.fetchall()
|
||||
|
||||
cursor.close()
|
||||
@@ -434,7 +417,7 @@ def admin_giveaways():
|
||||
def edit_giveaway(giveaway_id):
|
||||
"""Bearbeitet ein spezifisches Giveaway."""
|
||||
if is_admin():
|
||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
connection = get_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
if request.method == "POST":
|
||||
@@ -446,7 +429,7 @@ def edit_giveaway(giveaway_id):
|
||||
|
||||
# Update der Giveaways-Daten
|
||||
cursor.execute("""
|
||||
UPDATE giveaways
|
||||
UPDATE giveaway_data
|
||||
SET platform = %s, name = %s, game_key = %s, winner_dc_id = %s, aktiv = %s
|
||||
WHERE id = %s
|
||||
""", (platform, name, game_key, winner_dc_id, aktiv, giveaway_id))
|
||||
@@ -456,7 +439,7 @@ def edit_giveaway(giveaway_id):
|
||||
return redirect(url_for("admin_giveaways"))
|
||||
|
||||
# Daten des spezifischen Giveaways laden
|
||||
cursor.execute("SELECT * FROM giveaways WHERE id = %s", (giveaway_id,))
|
||||
cursor.execute("SELECT * FROM giveaway_data WHERE id = %s", (giveaway_id,))
|
||||
giveaway = cursor.fetchone()
|
||||
|
||||
cursor.close()
|
||||
@@ -473,12 +456,12 @@ def user_giveaways():
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
connection = get_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist
|
||||
cursor.execute("""
|
||||
SELECT * FROM giveaways WHERE winner_dc_id = %s
|
||||
SELECT * FROM giveaway_data WHERE winner_dc_id = %s
|
||||
""", (user_id,))
|
||||
won_giveaways = cursor.fetchall()
|
||||
|
||||
@@ -496,17 +479,17 @@ def redeem_giveaway(uuid):
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
connection = get_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Überprüfen, ob der eingeloggte Benutzer der Gewinner ist
|
||||
cursor.execute("SELECT * FROM giveaways WHERE uuid = %s AND winner_dc_id = %s", (uuid, user_id))
|
||||
cursor.execute("SELECT * FROM giveaway_data WHERE uuid = %s AND winner_dc_id = %s", (uuid, user_id))
|
||||
giveaway = cursor.fetchone()
|
||||
|
||||
if giveaway:
|
||||
if request.method == "POST":
|
||||
# Wenn der Benutzer den Key aufdeckt, setze `aktiv` auf TRUE
|
||||
cursor.execute("UPDATE giveaways SET aktiv = TRUE WHERE uuid = %s", (uuid,))
|
||||
cursor.execute("UPDATE giveaway_data SET aktiv = TRUE WHERE uuid = %s", (uuid,))
|
||||
connection.commit()
|
||||
|
||||
# Key aufdecken
|
||||
|
||||
Reference in New Issue
Block a user