feat: added configurable role immunity
This commit is contained in:
parent
615bf62d8b
commit
672e7c2936
1 changed files with 44 additions and 1 deletions
|
@ -11,7 +11,8 @@ class Shortmute(commands.Cog):
|
|||
self.config = Config.get_conf(self, identifier=25781647388294, force_registration=True)
|
||||
self.config.register_guild(
|
||||
dm = True,
|
||||
logging_channels = []
|
||||
logging_channels = [],
|
||||
immune_roles = []
|
||||
)
|
||||
|
||||
@app_commands.command()
|
||||
|
@ -116,11 +117,13 @@ class Shortmute(commands.Cog):
|
|||
|
||||
@commands.group(name='shortmuteset', autohelp=True)
|
||||
@commands.guild_only()
|
||||
@commands.admin()
|
||||
async def shortmute_config(self, ctx: commands.Context):
|
||||
"""This command group is used to configure the `/shortmute` slash command."""
|
||||
|
||||
@shortmute_config.command(name='addchannel')
|
||||
@commands.guild_only()
|
||||
@commands.admin()
|
||||
async def shortmute_config_addchannel(self, ctx: commands.Context, channel: discord.TextChannel = None):
|
||||
"""This command changes where the `/shortmute` slash command will log shortmutes. You can set multiple channels as well!"""
|
||||
current_list = await self.config.guild(ctx.guild.id).logging_channels()
|
||||
|
@ -145,6 +148,7 @@ class Shortmute(commands.Cog):
|
|||
|
||||
@shortmute_config.command(name='removechannel')
|
||||
@commands.guild_only()
|
||||
@commands.admin()
|
||||
async def shortmute_config_removechannel(self, ctx: commands.Context, channel: discord.TextChannel = None):
|
||||
"""This command removes a channel from the `/shortmute`slash command's logging channels list."""
|
||||
current_list = await self.config.guild(ctx.guild.id).logging_channels()
|
||||
|
@ -155,8 +159,47 @@ class Shortmute(commands.Cog):
|
|||
else:
|
||||
await ctx.send("Please provide a valid channel that exists in the logging channels list.")
|
||||
|
||||
@shortmute_config.command(name='addrole')
|
||||
@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."""
|
||||
current_list = await self.config.guild(ctx.guild.id).immune_roles()
|
||||
if role:
|
||||
if role.id in current_list:
|
||||
await ctx.send("This role is already in the immune roles list!")
|
||||
return
|
||||
else:
|
||||
current_list.append(role.id)
|
||||
await self.config.guild(ctx.guild.id).immune_roles.set(current_list)
|
||||
await ctx.send(f"{role.mention} has been added to the logging channels list.", allowed_mentions = discord.AllowedMentions(roles=False))
|
||||
else:
|
||||
already_in_list = []
|
||||
for role_id in current_list:
|
||||
role_obj = ctx.guild.get_role(role_id)
|
||||
if role_obj:
|
||||
already_in_list.append(role_obj.mention)
|
||||
if already_in_list:
|
||||
await ctx.send("Roles already in the immune roles list:\n" + "\n".join(already_in_list), allowed_mentions = discord.AllowedMentions(roles=False))
|
||||
else:
|
||||
await ctx.send("Please provide a valid role.")
|
||||
|
||||
@shortmute_config.command(name='removerole')
|
||||
@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."""
|
||||
current_list = await self.config.guild(ctx.guild.id).immune_roles()
|
||||
if role.id in current_list:
|
||||
current_list.remove(role.id)
|
||||
await self.config.guild(ctx.guild.id).immune_roles.set(current_list)
|
||||
await ctx.send(f"{role.mention} has been removed from the immune roles list.", allowed_mentions = discord.AllowedMentions(roles=False))
|
||||
else:
|
||||
await ctx.send("Please provide a valid role that exists in the immune roles list.")
|
||||
|
||||
@shortmute_config.command(name='dm')
|
||||
@commands.guild_only()
|
||||
@commands.admin()
|
||||
async def shortmute_config_dm(self, ctx: commands.Context, enabled: bool = None):
|
||||
"""This command changes if the `/shortmute` slash command Direct Messages its target."""
|
||||
old_value = await self.config.guild(ctx.guild.id).dm()
|
||||
|
|
Loading…
Reference in a new issue