fix(aurora): fixed an error in the /edit command
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Successful in 29s
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 41s

This commit is contained in:
Seaswimmer 2024-08-19 14:33:11 -04:00
parent 46c1cf53bf
commit 5cd0ef61cb
Signed by: cswimr
GPG key ID: 3813315477F26F82

View file

@ -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)