fix(aurora): fixed most of the moderation handlers having improper error handling for incorrect durations
This commit is contained in:
parent
7b3608e264
commit
46c1cf53bf
1 changed files with 35 additions and 33 deletions
|
@ -169,12 +169,14 @@ class AddRole(Type):
|
||||||
return
|
return
|
||||||
|
|
||||||
if duration is not None:
|
if duration is not None:
|
||||||
parsed_time = parse_timedelta(duration)
|
try:
|
||||||
if parsed_time is None:
|
parsed_time = parse_relativedelta(argument=duration)
|
||||||
await ctx.send(
|
if parsed_time is None:
|
||||||
content=error("Please provide a valid duration!"), ephemeral=True
|
raise commands.BadArgument()
|
||||||
)
|
parsed_time = timedelta_from_relativedelta(relativedelta=parsed_time)
|
||||||
return
|
except (commands.BadArgument, ValueError):
|
||||||
|
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
|
||||||
|
return cls()
|
||||||
else:
|
else:
|
||||||
parsed_time = None
|
parsed_time = None
|
||||||
|
|
||||||
|
@ -342,12 +344,14 @@ class RemoveRole(Type):
|
||||||
return
|
return
|
||||||
|
|
||||||
if duration is not None:
|
if duration is not None:
|
||||||
parsed_time = parse_timedelta(duration)
|
try:
|
||||||
if parsed_time is None:
|
parsed_time = parse_relativedelta(argument=duration)
|
||||||
await ctx.send(
|
if parsed_time is None:
|
||||||
content=error("Please provide a valid duration!"), ephemeral=True
|
raise commands.BadArgument()
|
||||||
)
|
parsed_time = timedelta_from_relativedelta(relativedelta=parsed_time)
|
||||||
return
|
except (commands.BadArgument, ValueError):
|
||||||
|
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
|
||||||
|
return cls()
|
||||||
else:
|
else:
|
||||||
parsed_time = None
|
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 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 log(ctx=ctx, moderation_id=moderation.id)
|
||||||
await send_evidenceformat(ctx=ctx, moderation_id=moderation.id)
|
await send_evidenceformat(ctx=ctx, moderation_id=moderation.id)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def resolve_handler(cls, moderation: Moderation, reason: str) -> Tuple[bool, str]:
|
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 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 log(ctx=ctx, moderation_id=moderation.id)
|
||||||
await send_evidenceformat(ctx=ctx, moderation_id=moderation.id)
|
await send_evidenceformat(ctx=ctx, moderation_id=moderation.id)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def resolve_handler(cls, moderation: Moderation, reason: str) -> Tuple[bool, str]:
|
async def resolve_handler(cls, moderation: Moderation, reason: str) -> Tuple[bool, str]:
|
||||||
|
@ -847,15 +851,14 @@ class Tempban(Ban):
|
||||||
else:
|
else:
|
||||||
delete_messages_seconds = delete_messages.value
|
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:
|
try:
|
||||||
parsed_time = timedelta_from_relativedelta(parsed_time)
|
parsed_time = parse_relativedelta(argument=duration)
|
||||||
except ValueError:
|
if parsed_time is None:
|
||||||
await ctx.send(content=error("Please provide a valid duration!"), ephemeral=True)
|
raise commands.BadArgument()
|
||||||
return cls
|
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)}")
|
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 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 log(ctx, moderation.id)
|
||||||
await send_evidenceformat(ctx, moderation.id)
|
await send_evidenceformat(ctx, moderation.id)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def expiry_handler(cls, moderation: Moderation) -> int:
|
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 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 log(ctx, moderation.id)
|
||||||
await send_evidenceformat(ctx, moderation.id)
|
await send_evidenceformat(ctx, moderation.id)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def resolve_handler(cls, moderation: Moderation, reason: str) -> Tuple[bool, str]:
|
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 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 log(ctx, moderation.id)
|
||||||
await send_evidenceformat(ctx, moderation.id)
|
await send_evidenceformat(ctx, moderation.id)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
class Slowmode(Type):
|
class Slowmode(Type):
|
||||||
key="slowmode"
|
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
|
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."""
|
"""Set the slowmode in a channel."""
|
||||||
bot = ctx.bot
|
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:
|
try:
|
||||||
|
parsed_time = parse_relativedelta(argument=duration)
|
||||||
|
if parsed_time is None:
|
||||||
|
raise commands.BadArgument()
|
||||||
parsed_time = timedelta_from_relativedelta(relativedelta=parsed_time)
|
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)
|
await ctx.send(content=error(text="Please provide a valid duration!"), ephemeral=True)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
if ceil(parsed_time.total_seconds()) > 21600:
|
if ceil(parsed_time.total_seconds()) > 21600:
|
||||||
await ctx.send(content=error(text="The slowmode duration cannot exceed 6 hours!"), ephemeral=True)
|
await ctx.send(content=error(text="The slowmode duration cannot exceed 6 hours!"), ephemeral=True)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
if isinstance(target, TextChannel):
|
if isinstance(target, TextChannel):
|
||||||
await target.edit(slowmode_delay=ceil(parsed_time.total_seconds()))
|
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 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)
|
await log(ctx=ctx, moderation_id=moderation.id)
|
||||||
return cls
|
return cls()
|
||||||
|
|
||||||
class Lockdown(Type):
|
class Lockdown(Type):
|
||||||
key="lockdown"
|
key="lockdown"
|
||||||
|
|
Loading…
Reference in a new issue