WIP: Refactor Aurora (3.0.0) #29
1 changed files with 21 additions and 22 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue