Implement reserved colors logic for user_colors.json
This commit is contained in:
@@ -57,10 +57,20 @@ def save_user_colors():
|
|||||||
def get_user_color(author_id):
|
def get_user_color(author_id):
|
||||||
global user_color_map
|
global user_color_map
|
||||||
if author_id not in user_color_map:
|
if author_id not in user_color_map:
|
||||||
# Assign a new color from the palette
|
# Determine which colors are already in use by existing users
|
||||||
# Cycle through colors, or pick randomly if palette is exhausted
|
used_colors = set(user_color_map.values())
|
||||||
next_color_index = len(user_color_map) % len(COLOR_PALETTE)
|
|
||||||
user_color_map[author_id] = COLOR_PALETTE[next_color_index]
|
# 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
|
save_user_colors() # Save immediately after assigning a new color
|
||||||
return user_color_map[author_id]
|
return user_color_map[author_id]
|
||||||
|
|
||||||
@@ -146,4 +156,4 @@ def main():
|
|||||||
console.print(f"[green]Chat log saved to {log_filename}[/green]")
|
console.print(f"[green]Chat log saved to {log_filename}[/green]")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user