From 802641ce6b981d2b3496233b83ee4baeb0a6a8ce Mon Sep 17 00:00:00 2001 From: Dav Date: Thu, 18 Jun 2020 23:51:06 +0000 Subject: [PATCH] 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 --- redbot/cogs/mod/kickban.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/redbot/cogs/mod/kickban.py b/redbot/cogs/mod/kickban.py index c99d55fcc..b3a97b143 100644 --- a/redbot/cogs/mod/kickban.py +++ b/redbot/cogs/mod/kickban.py @@ -398,15 +398,15 @@ class KickBanMixin(MixinMeta): self, ctx: commands.Context, user: discord.Member, - duration: Optional[int] = 1, + duration: Optional[commands.TimedeltaConverter] = timedelta(days=1), + days: Optional[int] = 0, *, reason: str = None, ): """Temporarily ban a user from this server.""" guild = ctx.guild author = ctx.author - days_delta = timedelta(days=int(duration)) - unban_time = datetime.utcnow() + days_delta + unban_time = datetime.utcnow() + duration if author == user: await ctx.send( @@ -425,7 +425,10 @@ class KickBanMixin(MixinMeta): elif guild.me.top_role <= user.top_role or user == guild.owner: await ctx.send(_("I cannot do that due to discord hierarchy rules")) 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: invite = "" @@ -447,7 +450,7 @@ class KickBanMixin(MixinMeta): ) ) try: - await guild.ban(user) + await guild.ban(user, reason=reason, delete_message_days=days) except discord.Forbidden: await ctx.send(_("I can't do that for some reason.")) except discord.HTTPException: