feat: vastly improved the shortmuteset command

This commit is contained in:
Seaswimmer 2023-08-08 02:25:47 -04:00
parent a10d68c55a
commit c0fd2e7dc2
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -169,10 +169,26 @@ class Shortmute(commands.Cog):
async def shortmute_config(self, ctx: commands.Context): async def shortmute_config(self, ctx: commands.Context):
"""This command group is used to configure the `/shortmute` slash command.""" """This command group is used to configure the `/shortmute` slash command."""
@shortmute_config.command(name='addchannel') @shortmute_config.group(name='channel', invoke_without_command=True)
@commands.guild_only() @commands.guild_only()
@commands.admin() @commands.admin()
async def shortmute_config_addchannel(self, ctx: commands.Context, channel: discord.TextChannel = None): async def shortmute_config_channel(self, ctx: commands.Context):
"""This command checks the existing list of channels that `/shortmute` is logging to."""
current_list = await self.config.guild(ctx.guild).logging_channels()
already_in_list = []
for channel_id in current_list:
channel_obj = ctx.guild.get_channel(channel_id)
if channel_obj:
already_in_list.append(channel_obj.mention)
if already_in_list:
await ctx.send("Channels already in the list:\n" + "\n".join(already_in_list))
else:
await ctx.send("Please provide a valid channel.")
@shortmute_config_channel.command(name='add')
@commands.guild_only()
@commands.admin()
async def shortmute_config_channel_add(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!""" """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).logging_channels() current_list = await self.config.guild(ctx.guild).logging_channels()
if channel: if channel:
@ -184,20 +200,12 @@ class Shortmute(commands.Cog):
await self.config.guild(ctx.guild).logging_channels.set(current_list) await self.config.guild(ctx.guild).logging_channels.set(current_list)
await ctx.send(f"{channel.mention} has been added to the logging channels list.") await ctx.send(f"{channel.mention} has been added to the logging channels list.")
else: else:
already_in_list = [] await ctx.send("Please provide a valid channel!")
for channel_id in current_list:
channel_obj = ctx.guild.get_channel(channel_id)
if channel_obj:
already_in_list.append(channel_obj.mention)
if already_in_list:
await ctx.send("Channels already in the list:\n" + "\n".join(already_in_list))
else:
await ctx.send("Please provide a valid channel.")
@shortmute_config.command(name='removechannel') @shortmute_config_channel.command(name='remove')
@commands.guild_only() @commands.guild_only()
@commands.admin() @commands.admin()
async def shortmute_config_removechannel(self, ctx: commands.Context, channel: discord.TextChannel = None): async def shortmute_config_channel_remove(self, ctx: commands.Context, channel: discord.TextChannel = None):
"""This command removes a channel from the `/shortmute`slash command's logging channels list.""" """This command removes a channel from the `/shortmute`slash command's logging channels list."""
current_list = await self.config.guild(ctx.guild).logging_channels() current_list = await self.config.guild(ctx.guild).logging_channels()
if channel.id in current_list: if channel.id in current_list:
@ -207,10 +215,24 @@ class Shortmute(commands.Cog):
else: else:
await ctx.send("Please provide a valid channel that exists in the logging channels list.") await ctx.send("Please provide a valid channel that exists in the logging channels list.")
@shortmute_config.command(name='addrole') @shortmute_config.group(name='role', invoke_without_command=True)
@commands.guild_only() @commands.guild_only()
@commands.admin() @commands.admin()
async def shortmute_config_addrole(self, ctx: commands.Context, role: discord.Role = None): async def shortmute_config_role(self, ctx: commands.Context):
"""This command checks the existing list of roles that are immune from `/shortmute`."""
current_list = await self.config.guild(ctx.guild).immune_roles()
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))
@shortmute_config_role.command(name='add')
@commands.guild_only()
@commands.admin()
async def shortmute_config_role_add(self, ctx: commands.Context, role: discord.Role = None):
"""This command adds roles to the immune roles list for immunity from 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() current_list = await self.config.guild(ctx.guild).immune_roles()
if role: if role:
@ -222,20 +244,12 @@ class Shortmute(commands.Cog):
await self.config.guild(ctx.guild).immune_roles.set(current_list) await self.config.guild(ctx.guild).immune_roles.set(current_list)
await ctx.send(f"{role.mention} has been added to the immune roles list.", allowed_mentions = discord.AllowedMentions(roles=False)) await ctx.send(f"{role.mention} has been added to the immune roles list.", allowed_mentions = discord.AllowedMentions(roles=False))
else: else:
already_in_list = [] await ctx.send("Please provide a valid role.")
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') @shortmute_config_role.command(name='remove')
@commands.guild_only() @commands.guild_only()
@commands.admin() @commands.admin()
async def shortmute_config_removerole(self, ctx: commands.Context, role: discord.Role = None): async def shortmute_config_role_remove(self, ctx: commands.Context, role: discord.Role = None):
"""This command removes roles from the immune roles list to remove immunity from 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() current_list = await self.config.guild(ctx.guild).immune_roles()
if role.id in current_list: if role.id in current_list:
@ -245,7 +259,21 @@ class Shortmute(commands.Cog):
else: else:
await ctx.send("Please provide a valid role that exists in the immune roles list.") await ctx.send("Please provide a valid role that exists in the immune roles list.")
@shortmute_config.command(name='blacklist add') @shortmute_config.group(name='blacklist', invoke_without_command=True)
@commands.guild_only()
@commands.admin()
async def shortmute_config_blacklist(self, ctx: commands.Context):
"""This command checks the existing list of users that are blacklisted from using `/shortmute`."""
current_list = await self.config.guild(ctx.guild).blacklisted_users()
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))
@shortmute_config_blacklist.command(name='add')
@commands.guild_only() @commands.guild_only()
@commands.admin() @commands.admin()
async def shortmute_config_blacklist_add(self, ctx: commands.Context, user: discord.User = None): async def shortmute_config_blacklist_add(self, ctx: commands.Context, user: discord.User = None):
@ -260,17 +288,9 @@ class Shortmute(commands.Cog):
await self.config.guild(ctx.guild).blacklisted_users.set(current_list) 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)) await ctx.send(f"{user.mention} has been blacklisted from using `/shortmute`.", allowed_mentions = discord.AllowedMentions(users=False))
else: else:
already_in_list = [] await ctx.send("Please provide a valid user.")
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') @shortmute_config_blacklist.command(name='remove')
@commands.guild_only() @commands.guild_only()
@commands.admin() @commands.admin()
async def shortmute_config_blacklist_remove(self, ctx: commands.Context, user: discord.User = None): async def shortmute_config_blacklist_remove(self, ctx: commands.Context, user: discord.User = None):
@ -283,10 +303,10 @@ class Shortmute(commands.Cog):
else: else:
await ctx.send("Please provide a valid user who is blacklisted from `/shortmute`.") await ctx.send("Please provide a valid user who is blacklisted from `/shortmute`.")
@shortmute_config.command(name='dm') @shortmute_config.command(name='message')
@commands.guild_only() @commands.guild_only()
@commands.admin() @commands.admin()
async def shortmute_config_dm(self, ctx: commands.Context, enabled: bool = None): async def shortmute_config_message(self, ctx: commands.Context, enabled: bool = None):
"""This command changes if the `/shortmute` slash command Direct Messages its target.""" """This command changes if the `/shortmute` slash command Direct Messages its target."""
old_value = await self.config.guild(ctx.guild).dm() old_value = await self.config.guild(ctx.guild).dm()
if enabled: if enabled: