From a5ca5c7fff2e61b6d2f3b3a245e7edc8ef5332c3 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:05:42 +0200 Subject: [PATCH] modified: bot.py --- bot.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/bot.py b/bot.py index 6753b98..28e7c4a 100644 --- a/bot.py +++ b/bot.py @@ -170,17 +170,15 @@ def insert_user_data(user_id, guild_id, permission, points, ban, askmultus, filt insert_query = """ INSERT INTO user_data (user_id, guild_id, permission, points, ban, askmultus, filter_value, rank, chat_history, xp, level) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) - ON DUPLICATE KEY UPDATE - permission = VALUES(permission), points = VALUES(points), ban = VALUES(ban), askmultus = VALUES(askmultus), filter_value = VALUES(filter_value), rank = VALUES(rank), chat_history = VALUES(chat_history), xp = VALUES(xp), level = VALUES(level) """ serialized_chat_history = json.dumps(chat_history) data = (user_id, guild_id, permission, points, ban, askmultus, filter_value, 0, serialized_chat_history, xp, level) try: db_cursor.execute(insert_query, data) db_connection.commit() - print("User data inserted or updated successfully.") + print("User data inserted successfully.") except Exception as e: - print(f"Error inserting or updating user data: {e}") + print(f"Error inserting user data: {e}") db_connection.rollback() def update_user_data(user_id, guild_id, field, value): @@ -234,6 +232,7 @@ def load_user_data_from_mysql(user_id, guild_id): close_database_connection(connection) if result: + # Wenn das Level und die XP nicht vorhanden sind, initialisieren user_data = { "user_id": result[0], "guild_id": result[1], @@ -249,21 +248,23 @@ def load_user_data_from_mysql(user_id, guild_id): "level": result[11] } else: + # Wenn keine Benutzerdaten gefunden werden, neue Daten anlegen print(f"No data found for user {user_id} in guild {guild_id}. Inserting new data.") user_data = { "user_id": user_id, "guild_id": guild_id, - "permission": 0, - "points": 0, - "ban": 0, - "askmultus": 0, - "filter_value": 0, - "rank": 0, - "chat_history": [], - "asknotes_history": [], - "xp": 0, - "level": 1 + "permission": 0, # Standardberechtigung + "points": 0, # Standardpunkte + "ban": 0, # Standardbannstatus + "askmultus": 0, # Standardwert für askmultus + "filter_value": 0, # Standardwert für Filter + "rank": 0, # Standardrang + "chat_history": [], # Leerer Chatverlauf + "asknotes_history": [], # Leerer Chatverlauf + "xp": 0, # Standard-XP + "level": 1 # Standardlevel } + insert_user_data( user_data["user_id"], user_data["guild_id"], @@ -301,11 +302,13 @@ def load_user_data(user_id, guild_id): if (user_id, guild_id) in cached_user_data: return cached_user_data[(user_id, guild_id)] + # Daten aus der Datenbank laden oder neu anlegen user_data = load_user_data_from_mysql(user_id, guild_id) asyncio.ensure_future(cache_user_data(user_id, guild_id, user_data)) return user_data + #----------------------------------------------------------------------------------------------------------- def save_giveaway_to_db(platform, name, prize_uuid, game_key, winner_dc_id=None): @@ -449,6 +452,7 @@ async def on_interaction(interaction): # Logge Interaktionen, die nicht den erwarteten Typ haben logger.error(f"Unbekannte Interaktion: {interaction.type}, Daten: {interaction.data}") + def read_introduction(): try: with open("introduction.txt", "r", encoding="utf-8") as file: