modified: bot.py
This commit is contained in:
40
bot.py
40
bot.py
@@ -166,13 +166,17 @@ CREATE TABLE IF NOT EXISTS user_data (
|
||||
db_cursor.execute(create_table_query)
|
||||
db_connection.commit()
|
||||
|
||||
def insert_user_data(user_id, guild_id, permission, points, ban, askmultus, filter_value, chat_history):
|
||||
def insert_user_data(user_id, guild_id, permission=0, points=0, ban=0, askmultus=0, filter_value=0, chat_history=None, xp=0, level=1):
|
||||
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)
|
||||
"""
|
||||
# Wenn kein Chat-Verlauf übergeben wird, setze ihn auf eine leere Liste
|
||||
if chat_history is None:
|
||||
chat_history = []
|
||||
|
||||
serialized_chat_history = json.dumps(chat_history)
|
||||
data = (user_id, guild_id, permission, points, ban, askmultus, filter_value, 0, serialized_chat_history, 0, 1) # XP auf 0 und Level auf 1 setzen
|
||||
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()
|
||||
@@ -232,7 +236,8 @@ def load_user_data_from_mysql(user_id, guild_id):
|
||||
close_database_connection(connection)
|
||||
|
||||
if result:
|
||||
user_data = {
|
||||
# Wenn das Level und die XP nicht vorhanden sind, initialisieren
|
||||
return {
|
||||
"user_id": result[0],
|
||||
"guild_id": result[1],
|
||||
"permission": result[2],
|
||||
@@ -242,13 +247,14 @@ def load_user_data_from_mysql(user_id, guild_id):
|
||||
"filter_value": result[6],
|
||||
"rank": result[7],
|
||||
"chat_history": json.loads(result[8]) if result[8] else [],
|
||||
"asknotes_history": json.loads(result[9]) if result[9] else [],
|
||||
"xp": result[10],
|
||||
"level": result[11]
|
||||
"xp": result[9],
|
||||
"level": result[10]
|
||||
}
|
||||
else:
|
||||
# Falls keine Benutzerdaten gefunden werden, initialisiere sie neu und füge sie in die DB ein
|
||||
user_data = {
|
||||
# Falls keine Benutzerdaten gefunden werden, lege sie an
|
||||
print(f"No data found for user {user_id} in guild {guild_id}. Inserting new data.")
|
||||
insert_user_data(user_id, guild_id)
|
||||
return {
|
||||
"user_id": user_id,
|
||||
"guild_id": guild_id,
|
||||
"permission": 0, # Standardberechtigung
|
||||
@@ -258,26 +264,10 @@ def load_user_data_from_mysql(user_id, guild_id):
|
||||
"filter_value": 0, # Standardwert für Filter
|
||||
"rank": 0, # Standardrang
|
||||
"chat_history": [], # Leerer Chatverlauf
|
||||
"asknotes_history": [], # Leerer Notizverlauf
|
||||
"xp": 0, # Standard-XP
|
||||
"level": 1 # Start-Level
|
||||
"level": 1 # Standardlevel
|
||||
}
|
||||
|
||||
# Initialisiere die Benutzerdaten in der Datenbank
|
||||
insert_user_data(
|
||||
user_data["user_id"],
|
||||
user_data["guild_id"],
|
||||
user_data["permission"],
|
||||
user_data["points"],
|
||||
user_data["ban"],
|
||||
user_data["askmultus"],
|
||||
user_data["filter_value"],
|
||||
user_data["chat_history"]
|
||||
)
|
||||
|
||||
return user_data
|
||||
|
||||
|
||||
cached_user_data = {}
|
||||
pending_deletion = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user