feat(moderation): added configuration to add immune roles and blacklist types

This commit is contained in:
Seaswimmer 2023-12-14 21:19:14 -05:00
parent b55e3da63e
commit 154e871dfc
Signed by untrusted user: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -64,10 +64,12 @@ class Moderation(commands.Cog):
ignore_other_bots = True,
dm_users = True,
log_channel = " ",
immune_roles = [],
history_ephemeral = False,
history_inline = False,
history_pagesize = 5,
history_inline_pagesize = 6
history_inline_pagesize = 6,
blacklist_roles = []
)
self.config.register_user(
history_ephemeral = None,
@ -448,13 +450,18 @@ class Moderation(commands.Cog):
for change in case_dict['changes']:
if change['user_id'] not in memory_dict:
memory_dict[str(change['user_id'])] = await self.fetch_user_dict(interaction, change['user_id'])
user = memory_dict[str(change['user_id'])]
name = user['name'] if user['discriminator'] == "0" else f"{user['name']}#{user['discriminator']}"
timestamp = f"<t:{change['timestamp']}> | <t:{change['timestamp']}:R>"
if change['type'] == 'ORIGINAL':
embed.add_field(name='Original', value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change['reason']}\n**Timestamp:** {timestamp}", inline=False)
elif change['type'] == 'EDIT':
embed.add_field(name='Edit', value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change['reason']}\n**Timestamp:** {timestamp}", inline=False)
elif change['type'] == 'RESOLVE':
embed.add_field(name='Resolve', value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change['reason']}\n**Timestamp:** {timestamp}", inline=False)
@ -1306,6 +1313,10 @@ class Moderation(commands.Cog):
cursor.close()
database.close()
#######################################################################################################################
### CONFIGURATION COMMANDS
#######################################################################################################################
@commands.group(autohelp=True)
async def moderationset(self, ctx: commands.Context):
"""Manage moderation commands."""
@ -1409,6 +1420,117 @@ class Moderation(commands.Cog):
await self.config.guild(ctx.guild).history_inline_pagesize.set(pagesize)
await ctx.send(f"Inline pagesize set to {await self.config.guild(ctx.guild).history_inline_pagesize()}")
@moderationset.group(autohelp=True, name='immunity')
@checks.admin()
async def moderationset_immunity(self, ctx: commands.Context):
"""Manage configuration for immune roles."""
@moderationset_immunity.command(name='add')
@checks.admin()
async def moderationset_immunity_add(self, ctx: commands.Context, role: discord.Role):
"""Add a role to the immune roles list."""
immune_roles: list = self.config.guild(ctx.guild).immune_roles()
if role.id in immune_roles:
await ctx.send("Role is already immune!")
return
immune_roles.append(role.id)
await self.config.guild(ctx.guild).immune_roles.set(immune_roles)
await ctx.send(f"Role {role.name} added to immune roles.")
@moderationset_immunity.command(name='remove')
@checks.admin()
async def moderationset_immunity_remove(self, ctx: commands.Context, role: discord.Role):
"""Remove a role from the immune roles list."""
immune_roles: list = self.config.guild(ctx.guild).immune_roles()
if role.id not in immune_roles:
await ctx.send("Role is not immune!")
return
immune_roles.remove(role.id)
await self.config.guild(ctx.guild).immune_roles.set(immune_roles)
await ctx.send(f"Role {role.name} removed from immune roles.")
@moderationset_immunity.command(name='list')
@checks.admin()
async def moderationset_immunity_list(self, ctx: commands.Context):
"""List all immune roles."""
immune_roles: list = self.config.guild(ctx.guild).immune_roles()
if not immune_roles:
await ctx.send("No immune roles set!")
return
role_list = ""
for role_id in immune_roles:
role = ctx.guild.get_role(role_id)
if role:
role_list += f"{role.mention}\n"
if role_list:
embed = discord.Embed(title="Immune Roles", description=role_list, color=await self.bot.get_embed_color(None))
await ctx.send(embed)
@moderationset.group(autohelp=True, name='blacklist')
@checks.admin()
async def moderationset_blacklist(self, ctx: commands.Context):
"""Manage configuration for the /blacklist command."""
@moderationset_blacklist.command(name='add')
@checks.admin()
async def moderationset_blacklist_add(self, ctx: commands.Context, role: discord.Role, duration: str = None):
"""Add a role to the blacklist.
Parameters
-----------
role: discord.Role
What role are you adding a blacklist type for?
duration: str
How long should the target be blacklisted for?"""
blacklist_roles: list = self.config.guild(ctx.guild).blacklist_roles()
for blacklist_role in blacklist_roles:
if role.id == blacklist_role['role']:
await ctx.send("Role already has an associated blacklist type!")
return
blacklist_roles.append(
{
'role': role.id,
'duration': duration
}
)
await self.config.guild(ctx.guild).blacklist_roles.set(blacklist_roles)
await ctx.send(f"Role {role.mention} added to blacklist.", allowed_mentions=discord.AllowedMentions.none())
@moderationset_blacklist.command(name='remove')
@checks.admin()
async def moderationset_blacklist_remove(self, ctx: commands.Context, role: discord.Role):
"""Remove a role's blacklist type.
Parameters
-----------
role: discord.Role
What role are you removing a blacklist type for?"""
blacklist_roles: list = self.config.guild(ctx.guild).blacklist_roles()
for blacklist_role in blacklist_roles:
if role.id == blacklist_role['role']:
blacklist_roles.remove(blacklist_role)
await self.config.guild(ctx.guild).blacklist_roles.set(blacklist_roles)
await ctx.send(f"Role {role.mention} removed from blacklist types.", allowed_mentions=discord.AllowedMentions.none())
return
await ctx.send("Role does not have an associated blacklist type!")
@moderationset_blacklist.command(name='list')
@checks.admin()
async def moderationset_blacklist_list(self, ctx: commands.Context):
"""List all blacklist types."""
blacklist_roles: list = self.config.guild(ctx.guild).blacklist_roles()
if not blacklist_roles:
await ctx.send("No blacklist types set!")
return
blacklist_list = ""
for blacklist_role in blacklist_roles:
role = ctx.guild.get_role(blacklist_role['role'])
if role:
blacklist_list += f"{role.mention} - {blacklist_role['duration']}\n"
if blacklist_list:
embed = discord.Embed(title="Blacklist Types", description=blacklist_list, color=await self.bot.get_embed_color(None))
await ctx.send(embed)
@moderationset.command(name="ignorebots")
@checks.admin()
async def moderationset_ignorebots(self, ctx: commands.Context):