feat(forms): added resolvedset show command
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
Seaswimmer 2023-09-08 13:56:44 -04:00
parent e9cee36171
commit 47703e9a49
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -12,15 +12,21 @@ class Forums(commands.Cog):
self.config = Config.get_conf(self, identifier=2352711325) self.config = Config.get_conf(self, identifier=2352711325)
self.config.register_guild( self.config.register_guild(
request_roles=[], request_roles=[],
forum_channel="", forum_channel=None,
forum_tag="" forum_tag=None
) )
@commands.command() @commands.command()
@commands.guild_only()
async def resolved(self, ctx: commands.Context, *, reason: str = None): async def resolved(self, ctx: commands.Context, *, reason: str = None):
"""Marks a thread as resolved.""" """Marks a thread as resolved."""
if isinstance(ctx.channel, discord.Thread) and ctx.channel.parent_id == await self.config.guild(ctx.guild).forum_channel(): channel_id = await self.config.guild(ctx.guild).forum_channel()
request_role_ids = await self.config.guild(ctx.guild).request_roles() tag = await self.config.guild(ctx.guild).forum_tag()
request_role_ids = await self.config.guild(ctx.guild).request_roles()
if channel_id is None or tag is None or request_role_ids is None:
await ctx.reply(f"Configuration not set properly! Please set configuration options with `{ctx.prefix}resolvedset`.")
return
if isinstance(ctx.channel, discord.Thread) and ctx.channel.parent_id == channel_id:
request_roles = [ctx.guild.get_role(role_id) for role_id in request_role_ids] request_roles = [ctx.guild.get_role(role_id) for role_id in request_role_ids]
match = any(role in ctx.author.roles for role in request_roles) match = any(role in ctx.author.roles for role in request_roles)
passed_info = { passed_info = {
@ -89,6 +95,43 @@ class Forums(commands.Cog):
async def resolvedset(self, ctx: commands.Context): async def resolvedset(self, ctx: commands.Context):
"""Manages the configuration for the [p]resolved command.""" """Manages the configuration for the [p]resolved command."""
@resolvedset.group(name='show', aliases=['settings'])
async def resolvedset_show(self, ctx: commands.Context):
"""Shows the current cog configuration."""
channel_id = await self.config.guild(ctx.guild).forum_channel()
tag = await self.config.guild(ctx.guild).forum_tag()
request_role_ids = await self.config.guild(ctx.guild).request_roles()
split_content = ctx.message.content.split()
command = ' '.join(split_content[:1])
already_in_list = []
for role_id in request_role_ids:
role_obj = ctx.guild.get_role(role_id)
if role_obj:
already_in_list.append(role_obj.mention)
if already_in_list:
roles_list = "Roles already in the allowed roles list:\n" + "\n".join(already_in_list) + f"\nUse `{command} add` to add roles to this list.\nUse `{command} remove` to remove roles from this list."
else:
roles_list = f"No roles are currently in the allowed roles list.\nUse `{command} add` to add some."
tag_str = None
if channel_id is not None:
channel_obj = ctx.guild.get_channel(channel_id)
if channel_obj is None:
channel = f"Channel: {channel_id}\n- ⚠️ This channel cannot be found in this guild. Is this the correct ID?\n\n"
else:
channel = f"Channel: {channel_obj.mention}\n\n"
if tag is not None:
tag_obj = channel_obj.get_tag(tag)
if tag_obj is None:
tag_str = f"Tag: {tag}\n- ⚠️ This tag cannot be found in the set forums channel. Is this the correct ID?\n\n"
else:
tag_str = f"Tag: {tag_obj.emoji} {tag_obj.name}\n\n"
else:
channel = f"Channel: Not set!\n- Use `{command} channel` to set the forums channel.\n\n"
if tag_str is None:
tag_str = f"Tag: Not set!\n- Use `{command} tag` to set the tag.\n\n"
embed = discord.Embed(title="resolvedset Settings", color=await self.bot.get_embed_color(None), description=channel + tag_str + roles_list)
await ctx.reply(embed=embed)
@resolvedset.group(name='role', invoke_without_command=True, aliases=['roles']) @resolvedset.group(name='role', invoke_without_command=True, aliases=['roles'])
async def resolvedset_role(self, ctx: commands.Context): async def resolvedset_role(self, ctx: commands.Context):
"""Manages the allowed roles list.""" """Manages the allowed roles list."""
@ -151,8 +194,7 @@ class Forums(commands.Cog):
async def resolvedset_tag(self, ctx: commands.Context, channel: discord.ForumChannel): async def resolvedset_tag(self, ctx: commands.Context, channel: discord.ForumChannel):
"""Sets the tag used by the [p]resolved command.""" """Sets the tag used by the [p]resolved command."""
options = self.create_select_options(ctx, channel.available_tags) 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("Select a forum tag below.")
msg = await ctx.send(f"Forum tag is currently set to `{str(tag)}`.")
await msg.edit(view=SelectView(msg, options)) await msg.edit(view=SelectView(msg, options))
class Select(ui.Select): class Select(ui.Select):