Implement reserved colors logic for user_colors.json

This commit is contained in:
2025-10-30 20:03:58 +01:00
parent d86aad9d82
commit 566d26791e

View File

@@ -57,10 +57,20 @@ def save_user_colors():
def get_user_color(author_id):
global user_color_map
if author_id not in user_color_map:
# Assign a new color from the palette
# Cycle through colors, or pick randomly if palette is exhausted
# Determine which colors are already in use by existing users
used_colors = set(user_color_map.values())
# Find available colors from the palette that are not yet used
available_colors = [color for color in COLOR_PALETTE if color not in used_colors]
if available_colors: # If there are unused colors in the palette
next_color_index = len(user_color_map) % len(available_colors)
user_color_map[author_id] = available_colors[next_color_index]
else: # If all colors in the palette are already used, cycle through the palette
next_color_index = len(user_color_map) % len(COLOR_PALETTE)
user_color_map[author_id] = COLOR_PALETTE[next_color_index]
console.print("[yellow]Warning: All colors in palette are reserved. Cycling through existing colors.[/yellow]")
save_user_colors() # Save immediately after assigning a new color
return user_color_map[author_id]