modified: bot.py

This commit is contained in:
SimolZimol
2024-09-12 21:32:13 +02:00
parent c237a65b39
commit 44e0fdff20

24
bot.py
View File

@@ -338,10 +338,10 @@ class Giveaway:
@client.hybrid_command() @client.hybrid_command()
async def startgiveaway(ctx, platform: str, prize: str, num_winners: int, title: str, subtitle: str, duration: str): async def startgiveaway(ctx, platform: str, prize: str, num_winners: int, title: str, subtitle: str, duration: str):
"""Erstellt ein Giveaway. Nur für Mods und höher verfügbar.""" """Creates a giveaway. Only available for mods and higher."""
user_data = load_user_data(ctx.author.id) user_data = load_user_data(ctx.author.id)
if user_data["permission"] < 5: if user_data["permission"] < 5:
await ctx.send("Du hast keine Berechtigung, um ein Giveaway zu erstellen.") await ctx.send("You do not have permission to create a giveaway.")
return return
if duration.endswith("m"): if duration.endswith("m"):
@@ -351,7 +351,7 @@ async def startgiveaway(ctx, platform: str, prize: str, num_winners: int, title:
days = int(duration[:-1]) days = int(duration[:-1])
end_time = datetime.now() + timedelta(days=days) end_time = datetime.now() + timedelta(days=days)
else: else:
await ctx.send("Ungültige Dauer. Bitte benutze 'm' für Minuten oder 'd' für Tage.") await ctx.send("Invalid duration. Please use 'm' for minutes or 'd' for days.")
return return
# Neues Giveaway erstellen # Neues Giveaway erstellen
@@ -359,13 +359,13 @@ async def startgiveaway(ctx, platform: str, prize: str, num_winners: int, title:
giveaway_id = len(giveaways) + 1 giveaway_id = len(giveaways) + 1
giveaways[giveaway_id] = giveaway giveaways[giveaway_id] = giveaway
button = Button(label="Teilnehmen", style=discord.ButtonStyle.green, custom_id=f"giveaway_{giveaway_id}") button = Button(label="Participate", style=discord.ButtonStyle.green, custom_id=f"giveaway_{giveaway_id}")
view = View() view = View()
view.add_item(button) view.add_item(button)
embed = discord.Embed( embed = discord.Embed(
title=title, title=title,
description=f"{subtitle}\n\nPreis: {prize}\nPlattform: {platform}\nAnzahl der Gewinner: {num_winners}\nEndet in: {duration}", description=f"{subtitle}\n\nPrize: {prize}\nPlatform: {platform}\nNumber of winners: {num_winners}\nEnds in: {duration}",
color=0x00ff00 color=0x00ff00
) )
embed.set_footer(text=f"Giveaway endet am {end_time.strftime('%Y-%m-%d %H:%M:%S')}") embed.set_footer(text=f"Giveaway endet am {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
@@ -375,7 +375,7 @@ async def startgiveaway(ctx, platform: str, prize: str, num_winners: int, title:
@tasks.loop(minutes=1) @tasks.loop(minutes=1)
async def check_giveaway(giveaway_id): async def check_giveaway(giveaway_id):
"""Überprüft alle 1 Minute, ob das Giveaway beendet ist.""" """Checks every 1 minute to see if the giveaway has ended."""
giveaway = giveaways.get(giveaway_id) giveaway = giveaways.get(giveaway_id)
if giveaway and giveaway.is_finished(): if giveaway and giveaway.is_finished():
@@ -384,7 +384,7 @@ async def check_giveaway(giveaway_id):
winners = giveaway.pick_winners() winners = giveaway.pick_winners()
if winners: if winners:
winner_mentions = ", ".join([winner.mention for winner in winners]) winner_mentions = ", ".join([winner.mention for winner in winners])
await giveaway.ctx.send(f"🎉 Glückwunsch an die Gewinner des Giveaways '{giveaway.title}'! Die Gewinner sind: {winner_mentions}") await giveaway.ctx.send(f"🎉 Congratulations to the winners of the giveaway '{giveaway.title}'! The winners are: {winner_mentions}")
# Jeden Gewinner benachrichtigen und zur Webseite schicken # Jeden Gewinner benachrichtigen und zur Webseite schicken
for winner in winners: for winner in winners:
@@ -394,13 +394,13 @@ async def check_giveaway(giveaway_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.prize_uuid}") f"Please claim your prize using the following link: {GIVEAWAY_WEBSITE_URL}{giveaway.prize_uuid}")
else: else:
await giveaway.ctx.send(f"Das Giveaway '{giveaway.title}' wurde beendet, aber es gab keine Teilnehmer.") await giveaway.ctx.send(f"The giveaway '{giveaway.title}' has ended, but there were no participants.")
del giveaways[giveaway_id] del giveaways[giveaway_id]
@client.event @client.event
async def on_interaction(interaction): async def on_interaction(interaction):
"""Bearbeitet die Teilnahme an einem Giveaway.""" """Processes participation in a giveaway."""
# Überprüfen, ob es sich um eine Button-Interaktion handelt und ein custom_id vorhanden ist # Überprüfen, ob es sich um eine Button-Interaktion handelt und ein custom_id vorhanden ist
if interaction.type == discord.InteractionType.component and "custom_id" in interaction.data: if interaction.type == discord.InteractionType.component and "custom_id" in interaction.data:
if interaction.data["custom_id"].startswith("giveaway_"): if interaction.data["custom_id"].startswith("giveaway_"):
@@ -409,13 +409,13 @@ async def on_interaction(interaction):
if giveaway: if giveaway:
if giveaway.is_finished(): if giveaway.is_finished():
await interaction.response.send_message("Dieses Giveaway ist bereits beendet.", ephemeral=True) await interaction.response.send_message("This giveaway has already ended.", ephemeral=True)
else: else:
added = giveaway.add_participant(interaction.user) added = giveaway.add_participant(interaction.user)
if added: if added:
await interaction.response.send_message("Du hast erfolgreich am Giveaway teilgenommen!", ephemeral=True) await interaction.response.send_message("You have successfully entered the giveaway!", ephemeral=True)
else: else:
await interaction.response.send_message("Du nimmst bereits am Giveaway teil.", ephemeral=True) await interaction.response.send_message("You're already participating in this giveaway.", ephemeral=True)
else: else:
# Logge Interaktionen, die nicht den erwarteten Typ haben # Logge Interaktionen, die nicht den erwarteten Typ haben
logger.error(f"Unbekannte Interaktion: {interaction.type}, Daten: {interaction.data}") logger.error(f"Unbekannte Interaktion: {interaction.type}, Daten: {interaction.data}")