modified: bot.py
This commit is contained in:
35
bot.py
35
bot.py
@@ -181,17 +181,30 @@ def insert_user_data(user_id, permission, points, ban, askmultus, filter_value,
|
|||||||
|
|
||||||
|
|
||||||
def update_user_data(user_id, field, 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':
|
# Überprüfen, ob das Feld 'chat_history' aktualisiert wird
|
||||||
# Serialize the chat history list to a JSON string
|
if field == 'chat_history':
|
||||||
serialized_chat_history = json.dumps(value)
|
# Serialize the chat history list to a JSON string
|
||||||
db_cursor.execute(update_query, (serialized_chat_history, user_id))
|
serialized_chat_history = json.dumps(value)
|
||||||
else:
|
db_cursor.execute(update_query, (serialized_chat_history, user_id))
|
||||||
db_cursor.execute(update_query, (value, 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():
|
def connect_to_database():
|
||||||
return mysql.connector.connect(
|
return mysql.connector.connect(
|
||||||
|
|||||||
Reference in New Issue
Block a user