From a10d68c55aa93f602af8fc573f99d360404567ff Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 8 Aug 2023 02:17:13 -0400 Subject: [PATCH] feat: added user blacklisting --- shortmute/shortmute.py | 51 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/shortmute/shortmute.py b/shortmute/shortmute.py index 31c92f5..372bb4c 100644 --- a/shortmute/shortmute.py +++ b/shortmute/shortmute.py @@ -1,6 +1,7 @@ import discord from pytimeparse2 import disable_dateutil, parse from discord import ui +from discord.ext.commands import Bot from redbot.core import Config, commands, app_commands class Shortmute(commands.Cog): @@ -12,7 +13,8 @@ class Shortmute(commands.Cog): self.config.register_guild( dm = True, logging_channels = [], - immune_roles = [] + immune_roles = [], + blacklisted_users = [] ) @app_commands.command() @@ -54,6 +56,11 @@ class Shortmute(commands.Cog): "color": await self.bot.get_embed_color(None), "evidence": evidence } + blacklisted_users_list = await self.config.guild(interaction.guild).blacklisted_users() + for user_id in blacklisted_users_list: + if user_id == interaction.user.id: + await interaction.response.send_message(content="You are blacklisted from `/shortmute`!", ephemeral=True) + return immune_roles_list = await self.config.guild(interaction.guild).immune_roles() for role_id in immune_roles_list: role = interaction.guild.get_role(role_id) @@ -204,7 +211,7 @@ class Shortmute(commands.Cog): @commands.guild_only() @commands.admin() async def shortmute_config_addrole(self, ctx: commands.Context, role: discord.Role = None): - """This command adds roles to the immune roles list for immunity from the the `/shortmute` slash command.""" + """This command adds roles to the immune roles list for immunity from the `/shortmute` slash command.""" current_list = await self.config.guild(ctx.guild).immune_roles() if role: if role.id in current_list: @@ -229,7 +236,7 @@ class Shortmute(commands.Cog): @commands.guild_only() @commands.admin() async def shortmute_config_removerole(self, ctx: commands.Context, role: discord.Role = None): - """This command removes roles from the immune roles list to remove immunity from the the `/shortmute` slash command.""" + """This command removes roles from the immune roles list to remove immunity from the `/shortmute` slash command.""" current_list = await self.config.guild(ctx.guild).immune_roles() if role.id in current_list: current_list.remove(role.id) @@ -238,6 +245,44 @@ class Shortmute(commands.Cog): else: await ctx.send("Please provide a valid role that exists in the immune roles list.") + @shortmute_config.command(name='blacklist add') + @commands.guild_only() + @commands.admin() + async def shortmute_config_blacklist_add(self, ctx: commands.Context, user: discord.User = None): + """This command adds users to the blacklist for the `/shortmute` slash command.""" + current_list = await self.config.guild(ctx.guild).blacklisted_users() + if user: + if user.id in current_list: + await ctx.send("That user is already in the blacklisted users list!") + return + else: + current_list.append(user.id) + await self.config.guild(ctx.guild).blacklisted_users.set(current_list) + await ctx.send(f"{user.mention} has been blacklisted from using `/shortmute`.", allowed_mentions = discord.AllowedMentions(users=False)) + else: + already_in_list = [] + for user_id in current_list: + user_obj = await Bot.fetch_user(user_id) + if user_obj: + already_in_list.append(user_obj.mention) + if already_in_list: + await ctx.send("Users already blacklisted:\n" + "\n".join(already_in_list), allowed_mentions = discord.AllowedMentions(users=False)) + else: + await ctx.send("Please provide a valid user.") + + @shortmute_config.command(name='blacklist remove') + @commands.guild_only() + @commands.admin() + async def shortmute_config_blacklist_remove(self, ctx: commands.Context, user: discord.User = None): + """This command adds users to the blacklist for the `/shortmute` slash command.""" + current_list = await self.config.guild(ctx.guild).blacklisted_users() + if user.id in current_list: + current_list.remove(user.id) + await self.config.guild(ctx.guild).blacklisted_users.set(current_list) + await ctx.send(f"{user.mention} has been removed from the `/shortmute` blacklist.", allowed_mentions = discord.AllowedMentions(users=False)) + else: + await ctx.send("Please provide a valid user who is blacklisted from `/shortmute`.") + @shortmute_config.command(name='dm') @commands.guild_only() @commands.admin()