modified: app.py
This commit is contained in:
27
app.py
27
app.py
@@ -22,6 +22,12 @@ DB_USER = os.getenv("DB_USER")
|
|||||||
DB_PASS = os.getenv("DB_PASSWORD")
|
DB_PASS = os.getenv("DB_PASSWORD")
|
||||||
DB_NAME = os.getenv("DB_DATABASE")
|
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_ID = os.getenv("DISCORD_CLIENT_ID")
|
||||||
DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
|
DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
|
||||||
DISCORD_REDIRECT_URI = os.getenv("DISCORD_REDIRECT_URI")
|
DISCORD_REDIRECT_URI = os.getenv("DISCORD_REDIRECT_URI")
|
||||||
@@ -37,6 +43,17 @@ ASKNOTES_INTRO_FILE = "asknotesintro.txt"
|
|||||||
# Speichern der Prozess-ID
|
# Speichern der Prozess-ID
|
||||||
bot_process = None
|
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():
|
def bot_status():
|
||||||
"""Überprüft, ob der Bot läuft."""
|
"""Überprüft, ob der Bot läuft."""
|
||||||
global bot_process
|
global bot_process
|
||||||
@@ -397,7 +414,7 @@ def download_logs():
|
|||||||
def admin_giveaways():
|
def admin_giveaways():
|
||||||
"""Zeigt eine Liste aller Giveaways an und ermöglicht das Bearbeiten und Sortieren."""
|
"""Zeigt eine Liste aller Giveaways an und ermöglicht das Bearbeiten und Sortieren."""
|
||||||
if is_admin():
|
if is_admin():
|
||||||
connection = get_db_connection()
|
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
# Sortierung nach bestimmten Feldern
|
# Sortierung nach bestimmten Feldern
|
||||||
@@ -418,7 +435,7 @@ def admin_giveaways():
|
|||||||
def edit_giveaway(giveaway_id):
|
def edit_giveaway(giveaway_id):
|
||||||
"""Bearbeitet ein spezifisches Giveaway."""
|
"""Bearbeitet ein spezifisches Giveaway."""
|
||||||
if is_admin():
|
if is_admin():
|
||||||
connection = get_db_connection()
|
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
@@ -449,6 +466,7 @@ def edit_giveaway(giveaway_id):
|
|||||||
return render_template("edit_giveaway.html", giveaway=giveaway)
|
return render_template("edit_giveaway.html", giveaway=giveaway)
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/user/giveaways", methods=["GET"])
|
@app.route("/user/giveaways", methods=["GET"])
|
||||||
def user_giveaways():
|
def user_giveaways():
|
||||||
"""Zeigt dem Benutzer die Giveaways, die er gewonnen hat."""
|
"""Zeigt dem Benutzer die Giveaways, die er gewonnen hat."""
|
||||||
@@ -456,7 +474,7 @@ def user_giveaways():
|
|||||||
user_info = session["discord_user"]
|
user_info = session["discord_user"]
|
||||||
user_id = user_info["id"]
|
user_id = user_info["id"]
|
||||||
|
|
||||||
connection = get_db_connection()
|
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
# Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist
|
# Suche nach Giveaways, bei denen der eingeloggte Benutzer der Gewinner ist
|
||||||
@@ -479,7 +497,7 @@ def redeem_giveaway(giveaway_id):
|
|||||||
user_info = session["discord_user"]
|
user_info = session["discord_user"]
|
||||||
user_id = user_info["id"]
|
user_id = user_info["id"]
|
||||||
|
|
||||||
connection = get_db_connection()
|
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
# Überprüfe, ob der eingeloggte Benutzer der Gewinner ist
|
# Überprüfe, ob der eingeloggte Benutzer der Gewinner ist
|
||||||
@@ -501,5 +519,6 @@ def redeem_giveaway(giveaway_id):
|
|||||||
|
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user