Skip to content

Commit

Permalink
Merge pull request #4 from LeDeathAmongst/main
Browse files Browse the repository at this point in the history
LeDeathAmongst: Fixed Minor Bugs
  • Loading branch information
nottherealtar authored Sep 25, 2024
2 parents 6813a30 + bfb3985 commit 8dea661
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 28 deletions.
6 changes: 5 additions & 1 deletion coffeestatus/coffeestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def __init__(self, bot):
}
self.config.register_global(**default_global)

def random_activity(self, activities):
"""Selects a random activity from the list."""
return random.choice(activities)

def cog_unload(self):
self.presence_task.cancel()

Expand Down Expand Up @@ -169,4 +173,4 @@ async def presence_updater(self):
else:
await self.bot.change_presence(
activity=discord.Activity(name=new_activity, type=_type), status=status
)
)
6 changes: 3 additions & 3 deletions projectpost/projectpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ async def delete_messages(messages):

messages_to_delete.extend([question3, project_url_message])

# Create the timestamp for the current time
timestamp = datetime.now()
# Create the timestamp for the current time in a human-readable format
timestamp = datetime.now().strftime("%A, %B %d, %Y %I:%M %p")

# Create the nicely formatted embed
embed = Embed(title=project_title.content, url=project_url_message.content)
Expand All @@ -73,4 +73,4 @@ async def delete_messages(messages):
await ctx.message.delete()

# Send the nicely formatted embed to the channel
await ctx.send(embed=embed)
await ctx.send(embed=embed)
5 changes: 4 additions & 1 deletion serverassistant/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
"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",
"requirements": [
"git+https://github.com/LeDeathAmongst/Star_Utils.git"
],
"tags": [
"util",
"admin",
"channels"
],
"end_user_data_statement": "This cog does not persistently store any data or metadata about users.",
"type": "COG"
}
}
115 changes: 92 additions & 23 deletions serverassistant/serverassistant.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from redbot.core import commands, Config
import discord
from Star_Utils import Dropdown
import asyncio

class ServerAssistant(commands.Cog):
"""A cog for organizing your Discord server."""

def __init__(self, bot):
self.bot = bot

@commands.group()
@commands.group(invoke_without_command=True)
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 = 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)
Expand All @@ -34,46 +34,115 @@ async def create_color_roles(self, ctx):
"Orange": discord.Color.orange(),
"Pink": discord.Color.magenta(),
"Teal": discord.Color.teal(),
"Cyan": discord.Color.blue(),
"Cyan": discord.Color.from_rgb(0, 255, 255),
"White": discord.Color.from_rgb(255, 255, 255),
"Black": discord.Color.from_rgb(0, 0, 0),
"Brown": discord.Color.from_rgb(139, 69, 19),
"Gray": discord.Color.from_rgb(128, 128, 128),
"Lime": discord.Color.from_rgb(191, 255, 0),
"Indigo": discord.Color.from_rgb(75, 0, 130),
"Violet": discord.Color.from_rgb(238, 130, 238),
"Gold": discord.Color.gold(),
"Silver": discord.Color.from_rgb(192, 192, 192),
# Add more colors as needed
}

created_roles = []
skipped_roles = []

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.")
skipped_roles.append(color_name)
else:
await ctx.guild.create_role(name=color_name, color=color)
await ctx.send(f"Role `{color_name}` created.")
created_roles.append(color_name)

if created_roles:
await ctx.send(f"Created roles: {', '.join(created_roles)}")
if skipped_roles:
await ctx.send(f"Skipped existing roles: {', '.join(skipped_roles)}")

@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.")
colors = [
"Red", "Green", "Blue", "Yellow", "Purple", "Orange", "Pink", "Teal", "Cyan",
"White", "Black", "Brown", "Gray", "Lime", "Indigo", "Violet", "Gold", "Silver"
]
await self.paginate_colors(ctx, colors)

async def paginate_colors(self, ctx, colors, start_index=0):
"""Paginate through color options."""
page_size = 25
end_index = min(start_index + page_size, len(colors))
current_colors = colors[start_index:end_index]

options = [{"label": color} for color in current_colors]

async def color_select_callback(view, interaction, selected_values):
selected_color = selected_values[0]
role = discord.utils.get(ctx.guild.roles, name=selected_color)
if role:
# Remove any existing color roles
for color in colors:
existing_role = discord.utils.get(ctx.author.roles, name=color)
if existing_role:
await ctx.author.remove_roles(existing_role)
# Add the new color role
await ctx.author.add_roles(role)
await interaction.response.send_message(f"You have been given the `{selected_color}` role.", ephemeral=True)
else:
await interaction.response.send_message("Role not found.", ephemeral=True)

view = Dropdown(
options=options,
placeholder="Choose a color role",
function=color_select_callback,
members=[ctx.author.id]
)

if start_index > 0:
view.add_item(discord.ui.Button(label="Previous", style=discord.ButtonStyle.primary, custom_id="previous"))
if end_index < len(colors):
view.add_item(discord.ui.Button(label="Next", style=discord.ButtonStyle.primary, custom_id="next"))

message = await ctx.send("Select a color for your role:", view=view)

def check(interaction):
return interaction.user.id == ctx.author.id and interaction.message.id == message.id

try:
interaction = await self.bot.wait_for("interaction", check=check, timeout=60)
if interaction.data["custom_id"] == "next" and end_index < len(colors):
await interaction.response.defer()
await self.paginate_colors(ctx, colors, start_index=end_index)
elif interaction.data["custom_id"] == "previous" and start_index > 0:
await interaction.response.defer()
await self.paginate_colors(ctx, colors, start_index=start_index - page_size)
except asyncio.TimeoutError:
pass

@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 = list(ctx.guild.channels) # Convert SequenceProxy to a list
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"
tree_string += f" {channel.name}\n"
for sub_channel in channel.channels:
tree_string += f" {sub_channel.name}\n"
tree_string += f" {sub_channel.name}\n"
elif isinstance(channel, discord.TextChannel) and channel.category is None:
tree_string += f"📄 {channel.name}\n"
tree_string += f" {channel.name}\n"
elif isinstance(channel, discord.VoiceChannel) and channel.category is None:
tree_string += f"🔊 {channel.name}\n"
tree_string += f" {channel.name}\n"

# Ensure the message does not exceed Discord's max message length (2000 characters)
# Split the message if it exceeds 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.")
chunks = [tree_string[i:i+1990] for i in range(0, len(tree_string), 1990)]
for chunk in chunks:
await ctx.send(f"```{chunk}```")
else:
await ctx.send(f"```{tree_string}```")

def setup(bot):
bot.add_cog(ServerAssistant(bot))

0 comments on commit 8dea661

Please sign in to comment.