From 6949313e70f7baecf1d092acde752f72a9abe76c Mon Sep 17 00:00:00 2001 From: dnns01 <git@dnns01.de> Date: Mon, 20 May 2024 23:09:30 +0200 Subject: [PATCH] Fix issues in text commands and made an enhancement to appointments. When sending notifications for appointments, the embed is sent again. --- extensions/appointments.py | 11 +++++++---- extensions/text_commands.py | 7 ++++--- models.py | 9 ++++++--- requirements.txt | 6 +++--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/extensions/appointments.py b/extensions/appointments.py index e6080da..7ed69cb 100644 --- a/extensions/appointments.py +++ b/extensions/appointments.py @@ -20,7 +20,10 @@ async def send_notification(appointment, channel): message += f"\n" message += " ".join([f"<@!{str(attendee.member_id)}>" for attendee in appointment.attendees]) - await channel.send(message) + if appointment.reminder_sent: + return await channel.send(message, embed=appointment.get_embed()) + + return await channel.send(message, embed=appointment.get_embed(), view=AppointmentView()) @app_commands.guild_only() @@ -41,11 +44,11 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A try: channel = await self.bot.fetch_channel(appointment.channel) message = await channel.fetch_message(appointment.message) - await send_notification(appointment, channel) + new_message = await send_notification(appointment, channel) + Appointment.update(message=new_message.id).where(Appointment.id == appointment.id).execute() + await message.delete() if appointment.reminder_sent: - await message.delete() - if appointment.recurring == 0: appointment.delete_instance(recursive=True) else: diff --git a/extensions/text_commands.py b/extensions/text_commands.py index 88dea00..b119b30 100644 --- a/extensions/text_commands.py +++ b/extensions/text_commands.py @@ -56,8 +56,9 @@ class TextCommands(commands.GroupCog, name="commands", description="Text Command text="Text, der bei Benutzung des Commands ausgegeben werden soll.") async def cmd_add(self, interaction: Interaction, cmd: str, text: str): if not re.match(r"^[a-z0-9]+(-[a-z0-9]+)*$", cmd): - await interaction.edit_original_response( - content="Ein Command darf nur aus Kleinbuchstaben und Zahlen bestehen, die durch Bindestriche getrennt werden können.") + await interaction.response.send_message( + "Ein Command darf nur aus Kleinbuchstaben und Zahlen bestehen, die durch Bindestriche getrennt werden können.", + ephemeral=True) return command = Command.get_or_none(Command.command == cmd) @@ -127,7 +128,7 @@ class TextCommands(commands.GroupCog, name="commands", description="Text Command else: if self.exists(cmd): return False - command = Command.create(command=cmd, description=description) + command = Command.create(command=cmd, description=description, guild_id=guild_id) CommandText.create(text=text, command=command.id) await self.register_command(command) diff --git a/models.py b/models.py index dbee384..a7c41ba 100644 --- a/models.py +++ b/models.py @@ -120,10 +120,13 @@ class Appointment(BaseModel): def get_embed(self): attendees = self.attendees + description = "" if self.reminder_sent else (f"Wenn du eine Benachrichtigung zum Beginn des Termins " + f"{f', sowie {self.reminder} Minuten vorher, ' if self.reminder > 0 else f''}" + f" erhalten möchtest, verwende den \"Zusagen\" Button unter dieser Nachricht." + f" Hast du bereits zugesagt und möchtest keine Benachrichtigung erhalten, " + f"kannst du den \"Absagen\" Button benutzen.") embed = discord.Embed(title=self.title, - description=f"Wenn du eine Benachrichtigung zum Beginn des Termins" - f"{f', sowie {self.reminder} Minuten vorher, ' if self.reminder > 0 else f''}" - f" erhalten möchtest, reagiere mit :thumbsup: auf diese Nachricht.", + description=description, color=19607) if len(self.description) > 0: diff --git a/requirements.txt b/requirements.txt index e7f2c8a..b5199bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,11 @@ aiohttp==3.9.5 beautifulsoup4==4.12.3 discord.py==2.3.2 -emoji==2.11.1 -peewee==3.17.3 +emoji==2.12.1 +peewee==3.17.5 PyNaCl==1.5.0 python-dotenv==1.0.1 -requests==2.31.0 +requests==2.32.0 aiosignal==1.3.1 attrs==23.2.0 -- GitLab