From 03a1781b68f94df9a14a2c9fa851add6dd808ff2 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Mon, 24 Aug 2020 07:05:41 +0100 Subject: [PATCH] Updated commentary Added powerban command to ban users who aren't part of the guild --- cogs/moderation.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/cogs/moderation.py b/cogs/moderation.py index 40dc70dd..c98450c3 100644 --- a/cogs/moderation.py +++ b/cogs/moderation.py @@ -94,6 +94,7 @@ async def ummute_members(self, ctx, targets, reason): # Get the roles of the user result = await self.bot.check_cache(target.id, ctx.guild.id) + # Get muted roles of the user from cache/database and give them back role_ids = result["muted_roles"] roles = [ctx.guild.get_role(int(id_)) for id_ in role_ids.split(", ") if len(id_)] @@ -340,6 +341,51 @@ class Moderation(Cog): with ctx.typing(): await ban_members(self, ctx, members, reason) + @command(name="forceban", aliases=["powerban", "ultraban"], usage="`...` `[reason]`") + @guild_only() + @has_guild_permissions(ban_members=True) + @bot_has_guild_permissions(ban_members=True) + @cooldown(1, 1, BucketType.user) + async def force_ban(self, ctx, users: Greedy[int], *, reason: Optional[str] = "No Reason Given"): + """Ban User(s) from Server (MUST PROVIDE ID)""" + + if not await check(ctx, users): + # Get the list of banned users from the server + bans = await ctx.guild.bans() + ban_ids = list(map(lambda m: m.user.id, bans)) + + # Power ban users from guilds without them being in there + for user in users: + if user in ban_ids: + await self.bot.generate_embed(ctx, desc="❌ **Member Is Already Banned!** ❌") + else: + await ctx.guild.ban(discord.Object(id=user)) + target = self.bot.get_user(user) + # Send confirmation to the channel that the user is in + await self.bot.generate_embed(ctx, desc=f"✅ **{target}** Was Power Banned! ✅") + + # Get the channel of the modlog within the guild + modlog = self.bot.get_modlog_for_guild(ctx.guild.id) + + if modlog: + + channel = ctx.guild.get_channel(modlog) + + embed = Embed(title=f"User Power Banned", + colour=self.bot.admin_colour, + timestamp=datetime.datetime.utcnow()) + + embed.set_thumbnail(url=target.avatar_url) + + fields = [("User ID", target, False), + ("Actioned by", ctx.author.mention, False), + ("Reason", reason, False)] + + for name, value, inline in fields: + embed.add_field(name=name, value=value, inline=inline) + + await channel.send(embed=embed) + @command(name="unban", usage="`...` `[reason]`") @guild_only() @has_guild_permissions(ban_members=True)