From a21c9c68aab3380af7159983ce51fb020a596b53 Mon Sep 17 00:00:00 2001 From: nottherealtar <67793100+nottherealtar@users.noreply.github.com> Date: Sun, 23 Jun 2024 18:50:09 +0200 Subject: [PATCH] . --- serverassistant/__init__.py | 4 ++ serverassistant/info.json | 17 +++++++ serverassistant/serverassistant.py | 79 ++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 serverassistant/__init__.py create mode 100644 serverassistant/info.json create mode 100644 serverassistant/serverassistant.py diff --git a/serverassistant/__init__.py b/serverassistant/__init__.py new file mode 100644 index 0000000..0fef2b4 --- /dev/null +++ b/serverassistant/__init__.py @@ -0,0 +1,4 @@ +from .serverassistnat import ServerAssistant + +async def setup(bot): + await bot.add_cog(ServerAssistant(bot)) \ No newline at end of file diff --git a/serverassistant/info.json b/serverassistant/info.json new file mode 100644 index 0000000..3a96f64 --- /dev/null +++ b/serverassistant/info.json @@ -0,0 +1,17 @@ +{ + "author": [ + "nottherealtar" + ], + "install_msg": "`[p]serverassistant help`", + "name": "ServerAssistant", + "short": "Lets help organize your server!", + "description": "ServerAssistant is a cog that helps you organize your server by providing useful commands for managing channels; colourizing them in a rainbow order, generating mind maps of the channels structures etc.", + "min_bot_version": "3.5.0", + "tags": [ + "util", + "admin", + "channels" + ], + "end_user_data_statement": "This cog does not persistently store any data or metadata about users.", + "type": "COG" +} \ No newline at end of file diff --git a/serverassistant/serverassistant.py b/serverassistant/serverassistant.py new file mode 100644 index 0000000..64de34e --- /dev/null +++ b/serverassistant/serverassistant.py @@ -0,0 +1,79 @@ +from redbot.core import commands, Config +import discord + +class ServerAssistant(commands.Cog): + """A cog for organizing your Discord server.""" + + def __init__(self, bot): + self.bot = bot + + @commands.group() + async def serverassistant(self, ctx): + """Base command for the ServerAssistant cog.""" + if ctx.invoked_subcommand is None: + await ctx.send_help(str(ctx.command)) + + @serverassistant.command(name="help") + async def _help(self, ctx): + """Displays the help diagram for ServerAssistant commands.""" + help_message = discord.Embed(title="ServerAssistant Commands", description="Helpful commands for managing your Discord server.", color=0x00ff00) + help_message.add_field(name="[P]serverassistant createcolorroles", value="Create a set of predefined color roles.", inline=False) + help_message.add_field(name="[P]serverassistant selectcolorrole", value="Select a color for your role (requires interaction support).", inline=False) + help_message.add_field(name="[P]serverassistant channelmap", value="Generate a mind map of your server's channels.", inline=False) + await ctx.send(embed=help_message) + + @serverassistant.command(name="createcolorroles") + async def create_color_roles(self, ctx): + """Create a set of predefined color roles.""" + colors = { + "Red": discord.Color.red(), + "Green": discord.Color.green(), + "Blue": discord.Color.blue(), + "Yellow": discord.Color.gold(), + "Purple": discord.Color.purple(), + "Orange": discord.Color.orange(), + "Pink": discord.Color.magenta(), + "Teal": discord.Color.teal(), + "Cyan": discord.Color.blue(), + "White": discord.Color.from_rgb(255, 255, 255), + "Black": discord.Color.from_rgb(0, 0, 0), + # Add more colors as needed + } + for color_name, color in colors.items(): + if discord.utils.get(ctx.guild.roles, name=color_name): + await ctx.send(f"Role `{color_name}` already exists.") + else: + await ctx.guild.create_role(name=color_name, color=color) + await ctx.send(f"Role `{color_name}` created.") + + @serverassistant.command(name="selectcolorrole") + async def select_color_role(self, ctx): + """Send an embed with a dropdown for selecting a color role.""" + # This is a conceptual outline. Actual implementation depends on your Discord library version and its support for interactions. + await ctx.send("This feature requires interaction support from your Discord library. Please refer to the documentation for implementing dropdowns and handling interactions.") + + @serverassistant.command(name="channelmap") + async def channel_map(self, ctx): + """Generate a mind map of the server's channels.""" + channel_list = ctx.guild.channels # Fetch all channels + channel_list.sort(key=lambda x: (x.position, x.type)) # Sort channels by position and type + + tree_string = "Server Channel Structure:\n" + for channel in channel_list: + if isinstance(channel, discord.CategoryChannel): + tree_string += f"📁 {channel.name}\n" + for sub_channel in channel.channels: + tree_string += f" ├ {sub_channel.name}\n" + elif isinstance(channel, discord.TextChannel) and channel.category is None: + tree_string += f"📄 {channel.name}\n" + elif isinstance(channel, discord.VoiceChannel) and channel.category is None: + tree_string += f"🔊 {channel.name}\n" + + # Ensure the message does not exceed Discord's max message length (2000 characters) + if len(tree_string) > 2000: + await ctx.send("The server structure is too large to display in one message. Consider breaking it down.") + else: + await ctx.send(f"```{tree_string}```") + +def setup(bot): + bot.add_cog(ServerAssistant(bot)) \ No newline at end of file