fix(aurora): fixed most of the moderation handlers having improper error handling for incorrect durations
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Successful in 31s
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 44s

This commit is contained in:
Seaswimmer 2024-08-19 14:24:25 -04:00
parent 7b3608e264
commit 46c1cf53bf
Signed by: cswimr
GPG key ID: 3813315477F26F82

View file

@ -169,12 +169,14 @@ class AddRole(Type):
return
if duration is not None:
parsed_time = parse_timedelta(duration)
if parsed_time is None:
await ctx.send(
content=error("Please provide a valid duration!"), ephemeral=True
)
return
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):
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
return cls()
else:
parsed_time = None
@ -342,12 +344,14 @@ class RemoveRole(Type):
return
if duration is not None:
parsed_time = parse_timedelta(duration)
if parsed_time is None:
await ctx.send(
content=error("Please provide a valid duration!"), ephemeral=True
)
return
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):
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
return cls()
else:
parsed_time = None
@ -721,7 +725,7 @@ class Kick(Type):
await response_message.edit(content=f"{target.mention} has been {cls.verb}! (Case {inline(f'#{moderation.id}')})\n{bold('Reason:')} {inline(reason)}")
await log(ctx=ctx, moderation_id=moderation.id)
await send_evidenceformat(ctx=ctx, moderation_id=moderation.id)
return cls
return cls()
@classmethod
async def resolve_handler(cls, moderation: Moderation, reason: str) -> Tuple[bool, str]:
@ -795,7 +799,7 @@ class Ban(Type):
await response_message.edit(content=f"{target.mention} has been {cls.verb}! (Case {inline(f'#{moderation.id}')})\n{bold('Reason:')} {inline(reason)}")
await log(ctx=ctx, moderation_id=moderation.id)
await send_evidenceformat(ctx=ctx, moderation_id=moderation.id)
return cls
return cls()
@classmethod
async def resolve_handler(cls, moderation: Moderation, reason: str) -> Tuple[bool, str]:
@ -847,15 +851,14 @@ class Tempban(Ban):
else:
delete_messages_seconds = delete_messages.value
parsed_time = parse_relativedelta(duration)
if not parsed_time:
await ctx.send(content=error("Please provide a valid duration!"), ephemeral=True)
return cls
try:
parsed_time = timedelta_from_relativedelta(parsed_time)
except ValueError:
await ctx.send(content=error("Please provide a valid duration!"), ephemeral=True)
return cls
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):
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
return cls()
response_message = await ctx.send(content=f"{target.mention} has been {cls.verb} for {humanize_timedelta(timedelta=parsed_time)}!\n{bold(text='Reason:')} {inline(text=reason)}")
@ -890,7 +893,7 @@ class Tempban(Ban):
await response_message.edit(content=f"{target.mention} has been {cls.verb} for {humanize_timedelta(timedelta=parsed_time)}! (Case {inline(text=f'#{moderation.id}')})\n{bold(text='Reason:')} {inline(reason)}")
await log(ctx, moderation.id)
await send_evidenceformat(ctx, moderation.id)
return cls
return cls()
@classmethod
async def expiry_handler(cls, moderation: Moderation) -> int:
@ -1003,7 +1006,7 @@ class Softban(Type):
await response_message.edit(content=f"{target.mention} has been {cls.verb}! (Case {inline(f'#{moderation.id}')})\n{bold('Reason:')} {inline(reason)}")
await log(ctx, moderation.id)
await send_evidenceformat(ctx, moderation.id)
return cls
return cls()
@classmethod
async def resolve_handler(cls, moderation: Moderation, reason: str) -> Tuple[bool, str]:
@ -1071,7 +1074,7 @@ class Unban(Type):
await response_message.edit(content=f"{target.mention} has been {cls.verb}! (Case {inline(f'#{moderation.id}')})\n{bold('Reason:')} {inline(reason)}")
await log(ctx, moderation.id)
await send_evidenceformat(ctx, moderation.id)
return cls
return cls()
class Slowmode(Type):
key="slowmode"
@ -1086,19 +1089,18 @@ class Slowmode(Type):
async def handler(cls, ctx: commands.Context, target: Messageable, silent: bool, duration: str, reason: str) -> 'Slowmode': # pylint: disable=unused-argument
"""Set the slowmode in a channel."""
bot = ctx.bot
parsed_time = parse_relativedelta(argument=duration)
if not parsed_time:
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
return cls
try:
parsed_time = parse_relativedelta(argument=duration)
if parsed_time is None:
raise commands.BadArgument()
parsed_time = timedelta_from_relativedelta(relativedelta=parsed_time)
except ValueError:
except (commands.BadArgument, ValueError):
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
return cls
return cls()
if ceil(parsed_time.total_seconds()) > 21600:
await ctx.send(content=error(text="The slowmode duration cannot exceed 6 hours!"), ephemeral=True)
return cls
return cls()
if isinstance(target, TextChannel):
await target.edit(slowmode_delay=ceil(parsed_time.total_seconds()))
@ -1115,7 +1117,7 @@ class Slowmode(Type):
)
await ctx.send(content=f"{ctx.author.mention} has {cls.verb} {target.mention} to {humanize_timedelta(timedelta=parsed_time)}!\n{bold(text='Reason:')} {inline(text=reason)}")
await log(ctx=ctx, moderation_id=moderation.id)
return cls
return cls()
class Lockdown(Type):
key="lockdown"