From 5cd0ef61cbb6b8488a9e9c3d8711c1a9dc4724d3 Mon Sep 17 00:00:00 2001 From: cswimr Date: Mon, 19 Aug 2024 14:33:11 -0400 Subject: [PATCH] fix(aurora): fixed an error in the `/edit` command --- aurora/aurora.py | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 718a1f8..779667f 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -37,7 +37,7 @@ from .utilities.config import config, register_config from .utilities.factory import addrole_embed, case_factory, changes_factory, evidenceformat_factory, guild_embed, immune_embed, overrides_embed, type_embed from .utilities.json import dump from .utilities.logger import logger -from .utilities.utils import check_moddable, check_permissions, create_guild_table, log +from .utilities.utils import check_moddable, check_permissions, create_guild_table, log, timedelta_from_relativedelta class Aurora(commands.Cog): @@ -1002,7 +1002,7 @@ class Aurora(commands.Cog): self, interaction: discord.Interaction, case: int, - reason: str, + reason: str | None = None, duration: str | None = None, ): """Edit the reason of a specific case. @@ -1046,8 +1046,12 @@ class Aurora(commands.Cog): ) if duration: - moderation.duration = parse_timedelta(duration) - if moderation.duration is None: + try: + parsed_time = parse_relativedelta(argument=duration) + if parsed_time is None: + raise commands.BadArgument() + parsed_time = timedelta_from_relativedelta(relativedelta=parsed_time) + except (commands.BadArgument, ValueError): return await interaction.response.send_message( error("Please provide a valid duration!"), ephemeral=True ) @@ -1066,6 +1070,11 @@ class Aurora(commands.Cog): if reason: moderation.reason = reason + if not reason and not duration: + return await interaction.response.send_message( + error("Please provide a new reason or duration to edit this case!"), ephemeral=True + ) + if not moderation.changes: moderation.changes.append(Change.from_dict(interaction.client, { "type": "ORIGINAL", @@ -1075,24 +1084,14 @@ class Aurora(commands.Cog): "duration": old_moderation.duration, "end_timestamp": old_moderation.end_timestamp, })) - if duration: - moderation.changes.append(Change.from_dict(interaction.client, { - "type": "EDIT", - "timestamp": int(time.time()), - "reason": reason, - "user_id": interaction.user.id, - "duration": moderation.duration, - "end_timestamp": moderation.end_timestamp, - })) - else: - moderation.changes.append(Change.from_dict(interaction.client, { - "type": "EDIT", - "timestamp": int(time.time()), - "reason": reason, - "user_id": interaction.user.id, - "duration": moderation.duration, - "end_timestamp": moderation.end_timestamp, - })) + moderation.changes.append(Change.from_dict(interaction.client, { + "type": "EDIT", + "timestamp": int(time.time()), + "reason": moderation.reason, + "user_id": interaction.user.id, + "duration": moderation.duration, + "end_timestamp": moderation.end_timestamp, + })) await moderation.update() embed = await case_factory(interaction=interaction, moderation=moderation)