feat(forums): working on more of the cog, nearly done
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
parent
f02fd84888
commit
4f9a1c9f4e
1 changed files with 105 additions and 7 deletions
112
forums/forums.py
112
forums/forums.py
|
@ -1,4 +1,5 @@
|
||||||
import discord
|
import discord
|
||||||
|
from discord import ui
|
||||||
from redbot.core import Config, checks, commands
|
from redbot.core import Config, checks, commands
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,15 +12,112 @@ 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 = "",
|
||||||
|
forum_tag = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def resolved(self, ctx: commands.Context):
|
async def resolved(self, ctx: commands.Context, reason: str = None):
|
||||||
"""Marks a thread as resolved."""
|
"""Marks a thread as resolved."""
|
||||||
channel = ctx.channel
|
if isinstance(ctx.channel, discord.Thread) and ctx.channel.parent_id == await self.config.guild(ctx.guild).forum_channel():
|
||||||
if isinstance(channel, discord.Thread) and channel.parent_id == await self.config.guild(ctx.guild.id).forum_channel():
|
match = any(role_id in ctx.author.roles for role_id in await self.config.guild(ctx.guild).request_roles())
|
||||||
await ctx.send("Are you sure you'd like to mark this thread as resolved?")
|
passed_info = {
|
||||||
|
"ctx": ctx,
|
||||||
|
"match": match
|
||||||
|
}
|
||||||
|
if match and reason:
|
||||||
|
passed_info.update({"reason": reason})
|
||||||
|
if match or ctx.author.id == ctx.channel.owner_id:
|
||||||
|
msg = await ctx.send("Are you sure you'd like to mark this thread as resolved?")
|
||||||
|
passed_info.update({"msg": msg})
|
||||||
|
await msg.edit(view=self.ResolvedButtons(timeout=180, passed_info=passed_info))
|
||||||
|
await ctx.message.add_reaction("❌")
|
||||||
|
|
||||||
|
class ResolvedButtons(ui.View):
|
||||||
|
def __init__(self, timeout, passed_info: dict):
|
||||||
|
super().__init__()
|
||||||
|
self.timeout = timeout
|
||||||
|
self.ctx: commands.Context = passed_info['ctx']
|
||||||
|
self.match: bool = passed_info['match']
|
||||||
|
self.msg: discord.Message = passed_info['msg']
|
||||||
|
if passed_info['reason']:
|
||||||
|
self.reason: str = passed_info['reason']
|
||||||
|
self.config = Config.get_conf(None, cog_name='Forums', identifier=2352711325)
|
||||||
|
|
||||||
|
@ui.button(label="Yes", style=discord.ButtonStyle.success, emoji="✅")
|
||||||
|
async def resolved_button_yes(self, button: ui.Button, interaction: discord.Interaction):
|
||||||
|
channel = self.ctx.channel
|
||||||
|
await channel.edit(locked=True, archived=True, applied_tags=channel.applied_tags + await self.config.guild(channel.guild).forum_tag())
|
||||||
|
|
||||||
|
@commands.group(name='forumconfig', invoke_without_command=True, aliases=['forumsset'])
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.admin()
|
||||||
|
async def forumsconfig(self, ctx: commands.Context):
|
||||||
|
"""Manages the request roles list."""
|
||||||
|
current_list = await self.config.guild(ctx.guild).request_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 request roles list:\n" + "\n".join(already_in_list), allowed_mentions = discord.AllowedMentions(roles=False))
|
||||||
else:
|
else:
|
||||||
await ctx.message.add_reaction("❌")
|
await ctx.send("No roles are currently in the request roles list.")
|
||||||
return
|
|
||||||
|
@forumsconfig.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."""
|
||||||
|
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!")
|
||||||
|
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))
|
||||||
|
else:
|
||||||
|
await ctx.send("Please provide a valid role.")
|
||||||
|
|
||||||
|
@forumsconfig.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."""
|
||||||
|
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))
|
||||||
|
else:
|
||||||
|
await ctx.send("Please provide a valid role that exists in the request roles list.")
|
||||||
|
|
||||||
|
# Function to create select options
|
||||||
|
def create_select_options(self, data):
|
||||||
|
options = []
|
||||||
|
for tag in data:
|
||||||
|
emoji = tag.emoji.id if tag.emoji.id else str(tag.emoji.name)
|
||||||
|
options.append(discord.SelectOption(label=tag.name, emoji=emoji, description=""))
|
||||||
|
return options
|
||||||
|
|
||||||
|
@forumsconfig.command()
|
||||||
|
async def forumsconfig_tag_set(self, ctx, channel: discord.ForumChannel):
|
||||||
|
# Create select options from the proxy data
|
||||||
|
options = self.create_select_options(channel.available_tags)
|
||||||
|
|
||||||
|
await ctx.send("Menus!", view=SelectView(options))
|
||||||
|
|
||||||
|
class Select(ui.Select):
|
||||||
|
def __init__(self, options):
|
||||||
|
super().__init__(placeholder="Select an option", max_values=1, min_values=1, options=options)
|
||||||
|
|
||||||
|
async def callback(self, interaction: discord.Interaction):
|
||||||
|
await interaction.response.send_message(content=f"Your choice is {self.values[0]}!", ephemeral=True)
|
||||||
|
|
||||||
|
class SelectView(ui.View):
|
||||||
|
def __init__(self, options, *, timeout=180):
|
||||||
|
super().__init__(timeout=timeout)
|
||||||
|
self.add_item(Select(options))
|
||||||
|
|
Loading…
Reference in a new issue