modified: bot.py

This commit is contained in:
SimolZimol
2024-09-14 19:27:51 +02:00
parent effc84dcc5
commit 7d741e2df1

31
bot.py
View File

@@ -181,17 +181,30 @@ def insert_user_data(user_id, permission, points, ban, askmultus, filter_value,
def update_user_data(user_id, field, value):
update_query = f"UPDATE user_data SET {field} = %s WHERE user_id = %s"
try:
update_query = f"UPDATE user_data SET {field} = %s WHERE user_id = %s"
# Überprüfen, ob das Feld 'chat_history' aktualisiert wird
if field == 'chat_history':
# Serialize the chat history list to a JSON string
serialized_chat_history = json.dumps(value)
db_cursor.execute(update_query, (serialized_chat_history, user_id))
else:
db_cursor.execute(update_query, (value, user_id))
# Überprüfen, ob das Feld 'chat_history' aktualisiert wird
if field == 'chat_history':
# Serialize the chat history list to a JSON string
serialized_chat_history = json.dumps(value)
db_cursor.execute(update_query, (serialized_chat_history, user_id))
else:
db_cursor.execute(update_query, (value, user_id))
db_connection.commit()
db_connection.commit()
except mysql.connector.Error as err:
logger.error(f"Database error: {err}")
if db_connection.is_connected():
db_cursor.close()
db_connection.close()
# Verbindung neu aufbauen
global db_connection, db_cursor
db_connection = connect_to_database()
db_cursor = db_connection.cursor()
# Wiederhole die Abfrage nach dem erneuten Verbinden
update_user_data(user_id, field, value)
def connect_to_database():
return mysql.connector.connect(