fix(moderation): fixed blacklist add command

This commit is contained in:
Seaswimmer 2023-12-14 21:26:23 -05:00
parent 0630804267
commit 8ad36c8b42
Signed by untrusted user: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -1473,38 +1473,33 @@ class Moderation(commands.Cog):
@moderationset_blacklist.command(name='add') @moderationset_blacklist.command(name='add')
@checks.admin() @checks.admin()
async def moderationset_blacklist_add(self, ctx: commands.Context, role: discord.Role, duration: str = None): async def moderationset_blacklist_add(self, ctx: commands.Context, role: discord.Role, duration: str):
"""Add a role to the blacklist. """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 = await self.config.guild(ctx.guild).blacklist_roles() blacklist_roles: list = await self.config.guild(ctx.guild).blacklist_roles()
for blacklist_role in blacklist_roles: for blacklist_role in blacklist_roles:
if role.id == blacklist_role['role']: if role.id == blacklist_role['role']:
await ctx.send("Role already has an associated blacklist type!") await ctx.send("Role already has an associated blacklist type!")
return return
try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError:
await ctx.send("Please provide a valid duration!")
return
blacklist_roles.append( blacklist_roles.append(
{ {
'role': role.id, 'role': role.id,
'duration': duration 'duration': parsed_time
} }
) )
await self.config.guild(ctx.guild).blacklist_roles.set(blacklist_roles) 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()) await ctx.send(f"Role {role.mention} added as a blacklist type.", allowed_mentions=discord.AllowedMentions.none())
@moderationset_blacklist.command(name='remove') @moderationset_blacklist.command(name='remove')
@checks.admin() @checks.admin()
async def moderationset_blacklist_remove(self, ctx: commands.Context, role: discord.Role): async def moderationset_blacklist_remove(self, ctx: commands.Context, role: discord.Role):
"""Remove a role's blacklist type. """Remove a role's blacklist type."""
Parameters
-----------
role: discord.Role
What role are you removing a blacklist type for?"""
blacklist_roles: list = await self.config.guild(ctx.guild).blacklist_roles() blacklist_roles: list = await self.config.guild(ctx.guild).blacklist_roles()
for blacklist_role in blacklist_roles: for blacklist_role in blacklist_roles:
if role.id == blacklist_role['role']: if role.id == blacklist_role['role']: