mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Use timedelta converter for ban duration and add option to pass delete days to [p]tempban (#3958)
* add duration atribute * sanity checks * add days parameter * maybe resolve conflicts? * black and make linting happy * right... I need to send this * but I still need to return... oops
This commit is contained in:
parent
2d63e3d6aa
commit
802641ce6b
@ -398,15 +398,15 @@ class KickBanMixin(MixinMeta):
|
|||||||
self,
|
self,
|
||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
user: discord.Member,
|
user: discord.Member,
|
||||||
duration: Optional[int] = 1,
|
duration: Optional[commands.TimedeltaConverter] = timedelta(days=1),
|
||||||
|
days: Optional[int] = 0,
|
||||||
*,
|
*,
|
||||||
reason: str = None,
|
reason: str = None,
|
||||||
):
|
):
|
||||||
"""Temporarily ban a user from this server."""
|
"""Temporarily ban a user from this server."""
|
||||||
guild = ctx.guild
|
guild = ctx.guild
|
||||||
author = ctx.author
|
author = ctx.author
|
||||||
days_delta = timedelta(days=int(duration))
|
unban_time = datetime.utcnow() + duration
|
||||||
unban_time = datetime.utcnow() + days_delta
|
|
||||||
|
|
||||||
if author == user:
|
if author == user:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
@ -425,7 +425,10 @@ class KickBanMixin(MixinMeta):
|
|||||||
elif guild.me.top_role <= user.top_role or user == guild.owner:
|
elif guild.me.top_role <= user.top_role or user == guild.owner:
|
||||||
await ctx.send(_("I cannot do that due to discord hierarchy rules"))
|
await ctx.send(_("I cannot do that due to discord hierarchy rules"))
|
||||||
return
|
return
|
||||||
invite = await self.get_invite_for_reinvite(ctx, int(days_delta.total_seconds() + 86400))
|
elif not (0 <= days <= 7):
|
||||||
|
await ctx.send(_("Invalid days. Must be between 0 and 7."))
|
||||||
|
return
|
||||||
|
invite = await self.get_invite_for_reinvite(ctx, int(duration.total_seconds() + 86400))
|
||||||
if invite is None:
|
if invite is None:
|
||||||
invite = ""
|
invite = ""
|
||||||
|
|
||||||
@ -447,7 +450,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await guild.ban(user)
|
await guild.ban(user, reason=reason, delete_message_days=days)
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
await ctx.send(_("I can't do that for some reason."))
|
await ctx.send(_("I can't do that for some reason."))
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user