modified: bot.py
This commit is contained in:
43
bot.py
43
bot.py
@@ -21,6 +21,7 @@ import shutil
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
@@ -362,10 +363,11 @@ async def startgiveaway(ctx, platform: str, prize: str, num_winners: int, title:
|
|||||||
button = Button(label="Participate", 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()))
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=title,
|
title=title,
|
||||||
description=f"{subtitle}\n\nPrize: {prize}\nPlatform: {platform}\nNumber of winners: {num_winners}\nEnds in: {duration}",
|
description=f"{subtitle}\n\nPrize: {prize}\nPlatform: {platform}\nNumber of winners: {num_winners}\nEnds in: <t:{unix_end_time}:R>",
|
||||||
color=0x00ff00
|
color=0x00ff00
|
||||||
)
|
)
|
||||||
embed.set_footer(text=f"Giveaway endet at {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
embed.set_footer(text=f"Giveaway endet at {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
@@ -378,34 +380,25 @@ async def check_giveaway(giveaway_id):
|
|||||||
"""Checks every 1 minute to see if the giveaway has ended."""
|
"""Checks every 1 minute to see if the giveaway has ended."""
|
||||||
giveaway = giveaways.get(giveaway_id)
|
giveaway = giveaways.get(giveaway_id)
|
||||||
|
|
||||||
if giveaway:
|
if giveaway and giveaway.is_finished():
|
||||||
if giveaway.is_finished():
|
check_giveaway.stop()
|
||||||
check_giveaway.stop()
|
|
||||||
|
|
||||||
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"🎉 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}")
|
||||||
|
|
||||||
# Jeden Gewinner benachrichtigen und zur Webseite schicken
|
# Jeden Gewinner benachrichtigen und zur Webseite schicken
|
||||||
for winner in winners:
|
for winner in winners:
|
||||||
# Gewinner in der Datenbank speichern (winner_dc_id)
|
# Gewinner in der Datenbank speichern (winner_dc_id)
|
||||||
update_winner_in_db(giveaway.prize_uuid, winner.id)
|
update_winner_in_db(giveaway.prize_uuid, winner.id)
|
||||||
# Nachricht an den Gewinner senden
|
# Nachricht an den Gewinner senden
|
||||||
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:
|
|
||||||
await giveaway.ctx.send(f"The giveaway '{giveaway.title}' has ended, but there were no participants.")
|
|
||||||
|
|
||||||
del giveaways[giveaway_id]
|
|
||||||
else:
|
else:
|
||||||
# Berechne die verbleibende Zeit
|
await giveaway.ctx.send(f"The giveaway '{giveaway.title}' has ended, but there were no participants.")
|
||||||
remaining_time = giveaway.remaining_time()
|
|
||||||
|
|
||||||
# Aktualisiere die Embed-Nachricht mit der verbleibenden Zeit
|
del giveaways[giveaway_id]
|
||||||
embed = giveaway.message.embeds[0]
|
|
||||||
embed.set_footer(text=f"Giveaway ends in: {str(remaining_time).split('.')[0]}")
|
|
||||||
await giveaway.message.edit(embed=embed)
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_interaction(interaction):
|
async def on_interaction(interaction):
|
||||||
|
|||||||
Reference in New Issue
Block a user