feat(forums): vastly improved configuration commands
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
Seaswimmer 2023-09-07 20:03:16 -04:00
parent a561fda6d2
commit 449123b6ee
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -83,11 +83,17 @@ class Forums(commands.Cog):
else:
await interaction.response.send_message(content="You cannot close this thread!", ephemeral=True)
@commands.group(name='forumsconfig', invoke_without_command=True, aliases=['forumconfig'])
@commands.group(name='resolvedset', autohelp=True, aliases=['resolvedconfig'])
@commands.guild_only()
@commands.admin()
async def forumsconfig(self, ctx: commands.Context):
"""Manages the request roles list."""
async def resolvedset(self, ctx: commands.Context):
"""Manages the configuration for the [p]resolved command."""
@resolvedset.group(name='role', invoke_without_command=True, aliases=['roles'])
@commands.guild_only()
@commands.admin()
async def resolvedset_role(self, ctx: commands.Context):
"""Manages the allowed roles list."""
current_list = await self.config.guild(ctx.guild).request_roles()
already_in_list = []
for role_id in current_list:
@ -95,39 +101,39 @@ class Forums(commands.Cog):
if role_obj:
already_in_list.append(role_obj.mention)
if already_in_list:
await ctx.send("Roles already in the request roles list:\n" + "\n".join(already_in_list), allowed_mentions=discord.AllowedMentions(roles=False))
await ctx.send("Roles already in the allowed roles list:\n" + "\n".join(already_in_list) + f"\nUse `{ctx.prefix}forumconfig add` to add roles to this list.\nUse `{ctx.prefix}forumconfig remove` to remove roles from this list.", allowed_mentions=discord.AllowedMentions(roles=False))
else:
await ctx.send("No roles are currently in the request roles list.")
await ctx.send(f"No roles are currently in the allowed roles list.\nUse `{ctx.prefix}forumconfig add` to add some!")
@forumsconfig.command(name='add')
@resolvedset_role.command(name='add')
@commands.guild_only()
@commands.admin()
async def forumsconfig_add(self, ctx: commands.Context, role: discord.Role = None):
"""Adds roles to the request roles list."""
async def resolvedset_role_add(self, ctx: commands.Context, role: discord.Role = None):
"""Adds roles to the allowed roles list."""
current_list = await self.config.guild(ctx.guild).request_roles()
if role:
if role.id in current_list:
await ctx.send("This role is already in the request roles list!")
await ctx.send("This role is already in the allowed roles list!")
return
else:
current_list.append(role.id)
await self.config.guild(ctx.guild).request_roles.set(current_list)
await ctx.send(f"{role.mention} has been added to the request roles list.", allowed_mentions = discord.AllowedMentions(roles=False))
await ctx.send(f"{role.mention} has been added to the allowed roles list.", allowed_mentions = discord.AllowedMentions(roles=False))
else:
await ctx.send("Please provide a valid role.")
@forumsconfig.command(name='remove')
@resolvedset_role.command(name='remove')
@commands.guild_only()
@commands.admin()
async def forumsconfig_remove(self, ctx: commands.Context, role: discord.Role = None):
"""Removes roles from the request roles list."""
async def resolvedset_role_remove(self, ctx: commands.Context, role: discord.Role = None):
"""Removes roles from the allowed roles list."""
current_list = await self.config.guild(ctx.guild).request_roles()
if role.id in current_list:
current_list.remove(role.id)
await self.config.guild(ctx.guild).request_roles.set(current_list)
await ctx.send(f"{role.mention} has been removed from the request roles list.", allowed_mentions = discord.AllowedMentions(roles=False))
await ctx.send(f"{role.mention} has been removed from the allowed roles list.", allowed_mentions = discord.AllowedMentions(roles=False))
else:
await ctx.send("Please provide a valid role that exists in the request roles list.")
await ctx.send("Please provide a valid role that exists in the allowed roles list.")
def create_select_options(self, ctx: commands.Context, data):
options = []
@ -136,15 +142,17 @@ class Forums(commands.Cog):
options.append(discord.SelectOption(label=tag.name, emoji=emoji, description="", value=tag.id))
return options
@forumsconfig.command(name="tag")
async def forumsconfig_tag_set(self, ctx: commands.Context, channel: discord.ForumChannel):
@resolvedset.command(name="tag")
async def resolvedset_tag(self, ctx: commands.Context, channel: discord.ForumChannel):
"""Sets the tag used by the [p]resolved command."""
options = self.create_select_options(ctx, channel.available_tags)
tag = channel.get_tag(await self.config.guild(ctx.guild).forum_tag())
msg = await ctx.send(f"Forum tag is currently set to `{str(tag)}`.")
await msg.edit(view=SelectView(msg, options))
@forumsconfig.command(name="channel")
async def forumsconfig_channel_set(self, ctx: commands.Context, channel: discord.ForumChannel):
@resolvedset.command(name="channel")
async def resolvedset_channel(self, ctx: commands.Context, channel: discord.ForumChannel):
"""Sets the tag used by the [p]resolved command."""
await self.config.guild(ctx.guild).forum_channel.set(channel.id)
await ctx.send(f"Forum channel has been set to `{channel.name}`.")