diff --git a/extensions/appointments.py b/extensions/appointments.py index 1b6bcae49f8abdb161de7f98855d377e1d5c1f4a..4eee61101d971cfcc7dd9cf51b0656841a1e98ae 100644 --- a/extensions/appointments.py +++ b/extensions/appointments.py @@ -18,7 +18,7 @@ async def send_notification(appointment, channel): if appointment.reminder_sent: return await channel.send(message, embed=appointment.get_embed(2)) - return await channel.send(message, embed=appointment.get_embed(1), view=AppointmentView()) + return await channel.send(message, embed=appointment.get_embed(1), view=AppointmentView(can_skip=appointment.recurring > 0)) @app_commands.guild_only() @@ -50,7 +50,7 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A Appointment.id == appointment.id).execute() updated_appointment = Appointment.get(Appointment.id == appointment.id) new_message = await channel.send(embed=updated_appointment.get_embed(0), - view=AppointmentView()) + view=AppointmentView(can_skip=appointment.recurring > 0)) Appointment.update(message=new_message.id).where(Appointment.id == appointment.id).execute() else: Appointment.update(reminder_sent=True).where(Appointment.id == appointment.id).execute() @@ -98,7 +98,7 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A reminder_sent=reminder == 0, uuid=uuid.uuid4()) Attendee.create(appointment=appointment, member_id=author_id) - await interaction.response.send_message(embed=appointment.get_embed(0), view=AppointmentView()) + await interaction.response.send_message(embed=appointment.get_embed(0), view=AppointmentView(can_skip=appointment.recurring > 0)) message = await interaction.original_response() Appointment.update(message=message.id).where(Appointment.id == appointment.id).execute() @@ -127,4 +127,4 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A async def setup(bot: commands.Bot) -> None: await bot.add_cog(Appointments(bot)) - bot.add_view(AppointmentView()) + bot.add_view(AppointmentView(can_skip=True)) diff --git a/views/appointment_view.py b/views/appointment_view.py index eca2e3a11da681fdc8782a9982fea2579d7156d3..724e06659284c55895c38e387bb878f0db64c542 100644 --- a/views/appointment_view.py +++ b/views/appointment_view.py @@ -1,12 +1,16 @@ +from datetime import timedelta + import discord from discord import File +import utils from models import Appointment, Attendee class AppointmentView(discord.ui.View): - def __init__(self): + def __init__(self, can_skip: bool): super().__init__(timeout=None) + self.on_skip.disabled = not can_skip @discord.ui.button(label='Anmelden', style=discord.ButtonStyle.green, custom_id='appointment_view:accept', emoji="ðŸ‘") async def accept(self, interaction: discord.Interaction, button: discord.ui.Button): @@ -37,6 +41,19 @@ class AppointmentView(discord.ui.View): await interaction.response.defer(thinking=False) + @discord.ui.button(label='Überspringen', style=discord.ButtonStyle.blurple, custom_id='appointment_view:skip', + emoji="âï¸") + async def on_skip(self, interaction: discord.Interaction, button: discord.ui.Button): + await interaction.response.defer(thinking=False) + if appointment := Appointment.get_or_none(Appointment.message == interaction.message.id): + if interaction.user.id == appointment.author or utils.is_mod(interaction.user): + new_date_time = appointment.date_time + timedelta(days=appointment.recurring) + Appointment.update(date_time=new_date_time, reminder_sent=False).where( + Appointment.id == appointment.id).execute() + updated_appointment = Appointment.get(Appointment.id == appointment.id) + await interaction.message.edit(embed=updated_appointment.get_embed(1 if updated_appointment.reminder_sent and updated_appointment.reminder > 0 else 0)) + + @discord.ui.button(label='Download .ics', style=discord.ButtonStyle.blurple, custom_id='appointment_view:ics', emoji="📅") async def ics(self, interaction: discord.Interaction, button: discord.ui.Button):