modified: bot.py
This commit is contained in:
37
bot.py
37
bot.py
@@ -166,15 +166,11 @@ CREATE TABLE IF NOT EXISTS user_data (
|
|||||||
db_cursor.execute(create_table_query)
|
db_cursor.execute(create_table_query)
|
||||||
db_connection.commit()
|
db_connection.commit()
|
||||||
|
|
||||||
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):
|
def insert_user_data(user_id, guild_id, permission, points, ban, askmultus, filter_value, chat_history, xp=0, level=1):
|
||||||
insert_query = """
|
insert_query = """
|
||||||
INSERT INTO user_data (user_id, guild_id, permission, points, ban, askmultus, filter_value, rank, chat_history, xp, level)
|
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)
|
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)
|
serialized_chat_history = json.dumps(chat_history)
|
||||||
data = (user_id, guild_id, permission, points, ban, askmultus, filter_value, 0, serialized_chat_history, xp, level)
|
data = (user_id, guild_id, permission, points, ban, askmultus, filter_value, 0, serialized_chat_history, xp, level)
|
||||||
try:
|
try:
|
||||||
@@ -237,7 +233,7 @@ def load_user_data_from_mysql(user_id, guild_id):
|
|||||||
|
|
||||||
if result:
|
if result:
|
||||||
# Wenn das Level und die XP nicht vorhanden sind, initialisieren
|
# Wenn das Level und die XP nicht vorhanden sind, initialisieren
|
||||||
return {
|
user_data = {
|
||||||
"user_id": result[0],
|
"user_id": result[0],
|
||||||
"guild_id": result[1],
|
"guild_id": result[1],
|
||||||
"permission": result[2],
|
"permission": result[2],
|
||||||
@@ -247,14 +243,14 @@ def load_user_data_from_mysql(user_id, guild_id):
|
|||||||
"filter_value": result[6],
|
"filter_value": result[6],
|
||||||
"rank": result[7],
|
"rank": result[7],
|
||||||
"chat_history": json.loads(result[8]) if result[8] else [],
|
"chat_history": json.loads(result[8]) if result[8] else [],
|
||||||
"xp": result[9],
|
"asknotes_history": json.loads(result[9]) if result[9] else [],
|
||||||
"level": result[10]
|
"xp": result[10],
|
||||||
|
"level": result[11]
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
# Falls keine Benutzerdaten gefunden werden, lege sie an
|
# Wenn keine Benutzerdaten gefunden werden, neue Daten anlegen
|
||||||
print(f"No data found for user {user_id} in guild {guild_id}. Inserting new data.")
|
print(f"No data found for user {user_id} in guild {guild_id}. Inserting new data.")
|
||||||
insert_user_data(user_id, guild_id)
|
user_data = {
|
||||||
return {
|
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"guild_id": guild_id,
|
"guild_id": guild_id,
|
||||||
"permission": 0, # Standardberechtigung
|
"permission": 0, # Standardberechtigung
|
||||||
@@ -264,10 +260,26 @@ def load_user_data_from_mysql(user_id, guild_id):
|
|||||||
"filter_value": 0, # Standardwert für Filter
|
"filter_value": 0, # Standardwert für Filter
|
||||||
"rank": 0, # Standardrang
|
"rank": 0, # Standardrang
|
||||||
"chat_history": [], # Leerer Chatverlauf
|
"chat_history": [], # Leerer Chatverlauf
|
||||||
|
"asknotes_history": [], # Leerer Chatverlauf
|
||||||
"xp": 0, # Standard-XP
|
"xp": 0, # Standard-XP
|
||||||
"level": 1 # Standardlevel
|
"level": 1 # Standardlevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"],
|
||||||
|
user_data["xp"],
|
||||||
|
user_data["level"]
|
||||||
|
)
|
||||||
|
|
||||||
|
return user_data
|
||||||
|
|
||||||
cached_user_data = {}
|
cached_user_data = {}
|
||||||
pending_deletion = {}
|
pending_deletion = {}
|
||||||
|
|
||||||
@@ -290,13 +302,12 @@ def load_user_data(user_id, guild_id):
|
|||||||
if (user_id, guild_id) in cached_user_data:
|
if (user_id, guild_id) in cached_user_data:
|
||||||
return cached_user_data[(user_id, guild_id)]
|
return cached_user_data[(user_id, guild_id)]
|
||||||
|
|
||||||
# Daten aus der Datenbank laden oder einfügen
|
# Daten aus der Datenbank laden oder neu anlegen
|
||||||
user_data = load_user_data_from_mysql(user_id, guild_id)
|
user_data = load_user_data_from_mysql(user_id, guild_id)
|
||||||
asyncio.ensure_future(cache_user_data(user_id, guild_id, user_data))
|
asyncio.ensure_future(cache_user_data(user_id, guild_id, user_data))
|
||||||
|
|
||||||
return user_data
|
return user_data
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def save_giveaway_to_db(platform, name, prize_uuid, game_key, winner_dc_id=None):
|
def save_giveaway_to_db(platform, name, prize_uuid, game_key, winner_dc_id=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user