modified: bot.py

This commit is contained in:
SimolZimol
2024-10-29 17:53:28 +01:00
parent 0950bd0bd4
commit 4e217cc2ff

24
bot.py
View File

@@ -335,11 +335,11 @@ 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 neues Giveaway, das nur für Admins verfügbar ist.""" """Creates a new giveaway, only available for admins."""
guild_id = ctx.guild.id guild_id = ctx.guild.id
user_data = load_user_data(ctx.author.id, guild_id) user_data = load_user_data(ctx.author.id, guild_id)
if user_data["permission"] < 5: if user_data["permission"] < 5:
await ctx.send("Du hast keine Berechtigung, ein Giveaway zu erstellen.") await ctx.send("You don't have permission to create a giveaway.")
return return
if duration.endswith("m"): if duration.endswith("m"):
@@ -349,25 +349,25 @@ 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 'm' für Minuten oder 'd' für Tage verwenden.") await ctx.send("Invalid duration. Please use 'm' for minutes or 'd' for days.")
return return
# Neues Giveaway erstellen # Create new giveaway
giveaway = Giveaway(ctx, platform, prize, num_winners, title, subtitle, duration, end_time) giveaway = Giveaway(ctx, platform, prize, num_winners, title, subtitle, duration, end_time)
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)
unix_end_time = int(time.mktime(end_time.timetuple())) unix_end_time = int(time.mktime(end_time.timetuple()))
embed = discord.Embed( embed = discord.Embed(
title=title, title=title,
description=f"{subtitle}\n\nPreis: {prize}\nPlattform: {platform}\nAnzahl der Gewinner: {num_winners}\nEndet <t:{unix_end_time}:R>", description=f"{subtitle}\n\nPrize: {prize}\nPlatform: {platform}\nNumber of winners: {num_winners}\nEnds <t:{unix_end_time}:R>",
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 ends at {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
await ctx.send(embed=embed, view=view) await ctx.send(embed=embed, view=view)
check_giveaway.start(giveaway_id) check_giveaway.start(giveaway_id)
@@ -399,16 +399,16 @@ 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}")
# Gewinner speichern und benachrichtigen # Notify and update the winners
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) update_winner_in_db(giveaway.guild_id, giveaway.prize_uuid, winner.id)
await winner.send(f"🎁 Glückwunsch! Du hast das Giveaway '{giveaway.title}' gewonnen!\n" await winner.send(f"🎁 Congratulations! You won the giveaway '{giveaway.title}'!\n"
f"Bitte hole deinen Preis unter folgendem Link ab: {GIVEAWAY_WEBSITE_URL}/{giveaway.guild_id}/{giveaway.prize_uuid}") f"Please claim your prize using the following link: {GIVEAWAY_WEBSITE_URL}{giveaway.guild_id}/{giveaway.prize_uuid}")
else: else:
await giveaway.ctx.send(f"Das Giveaway '{giveaway.title}' ist 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]