From 593079dbbb32947d297396360a5a61812cfcad50 Mon Sep 17 00:00:00 2001 From: Dav Date: Thu, 11 Jun 2020 22:30:11 +0000 Subject: [PATCH] [Mod] Make tempban more consistent with other ban commands. (#3957) * add duration atribute * sanity checks * obviously that didn't work... * insert facepalm here --- redbot/cogs/mod/kickban.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/redbot/cogs/mod/kickban.py b/redbot/cogs/mod/kickban.py index 6be373785..c99d55fcc 100644 --- a/redbot/cogs/mod/kickban.py +++ b/redbot/cogs/mod/kickban.py @@ -395,14 +395,36 @@ class KickBanMixin(MixinMeta): @commands.bot_has_permissions(ban_members=True) @checks.admin_or_permissions(ban_members=True) async def tempban( - self, ctx: commands.Context, user: discord.Member, days: int = 1, *, reason: str = None + self, + ctx: commands.Context, + user: discord.Member, + duration: Optional[int] = 1, + *, + reason: str = None, ): """Temporarily ban a user from this server.""" guild = ctx.guild author = ctx.author - days_delta = timedelta(days=int(days)) + days_delta = timedelta(days=int(duration)) unban_time = datetime.utcnow() + days_delta + if author == user: + await ctx.send( + _("I cannot let you do that. Self-harm is bad {}").format("\N{PENSIVE FACE}") + ) + return + elif not await is_allowed_by_hierarchy(self.bot, self.config, guild, author, user): + await ctx.send( + _( + "I cannot let you do that. You are " + "not higher than the user in the role " + "hierarchy." + ) + ) + return + 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)) if invite is None: invite = ""