modified: bot.py

This commit is contained in:
SimolZimol
2025-08-16 10:13:02 +02:00
parent d956a92557
commit b484a552b7

23
bot.py
View File

@@ -354,6 +354,22 @@ def save_giveaway_to_db(guild_id, platform, name, prize_uuid, game_key):
cursor.close() cursor.close()
connection.close() connection.close()
def save_winner_to_db(guild_id, platform, name, winner_dc_id, game_key="PREDEFINED_GAME_KEY"):
"""Erstellt einen eigenen Datenbankeintrag für jeden Gewinner mit eigener UUID"""
connection = connect_to_database()
cursor = connection.cursor()
winner_uuid = uuid.uuid4()
insert_query = """
INSERT INTO giveaway_data (guild_id, uuid, platform, name, game_key, winner_dc_id)
VALUES (%s, %s, %s, %s, %s, %s)
"""
data = (guild_id, str(winner_uuid), platform, name, game_key, winner_dc_id)
cursor.execute(insert_query, data)
connection.commit()
cursor.close()
connection.close()
return winner_uuid
def update_winner_in_db(guild_id, prize_uuid, winner_dc_id): def update_winner_in_db(guild_id, prize_uuid, winner_dc_id):
connection = connect_to_database() connection = connect_to_database()
cursor = connection.cursor() cursor = connection.cursor()
@@ -583,12 +599,13 @@ async def check_giveaway(giveaway_id):
winner_mentions = ", ".join([winner.mention for winner in winners]) winner_mentions = ", ".join([winner.mention for winner in winners])
await giveaway.ctx.send(f"🎉 Congratulations to the winners of the giveaway '{giveaway.title}'! The winners are: {winner_mentions}") await giveaway.ctx.send(f"🎉 Congratulations to the winners of the giveaway '{giveaway.title}'! The winners are: {winner_mentions}")
# Notify and update the winners # Notify and update the winners - Erstelle für jeden Gewinner einen eigenen DB-Eintrag
for winner in winners: for winner in winners:
user_data = load_user_data(winner.id, giveaway.guild_id) user_data = load_user_data(winner.id, giveaway.guild_id)
update_winner_in_db(giveaway.guild_id, giveaway.prize_uuid, winner.id) # Erstelle einen eigenen Datenbankeintrag für diesen Gewinner mit eigener UUID
winner_uuid = save_winner_to_db(giveaway.guild_id, giveaway.platform, giveaway.title, winner.id)
await winner.send(f"🎁 Congratulations! You won the giveaway '{giveaway.title}'!\n" await winner.send(f"🎁 Congratulations! You won the giveaway '{giveaway.title}'!\n"
f"Please claim your prize using the following link: {GIVEAWAY_WEBSITE_URL}{giveaway.guild_id}/{giveaway.prize_uuid}") f"Please claim your prize using the following link: {GIVEAWAY_WEBSITE_URL}{giveaway.guild_id}/{winner_uuid}")
else: else:
await giveaway.ctx.send(f"The giveaway '{giveaway.title}' has ended, but there were no participants.") await giveaway.ctx.send(f"The giveaway '{giveaway.title}' has ended, but there were no participants.")