diff --git a/pytchat_listener.py b/pytchat_listener.py index 39aee65..1e2bd10 100644 --- a/pytchat_listener.py +++ b/pytchat_listener.py @@ -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 - next_color_index = len(user_color_map) % len(COLOR_PALETTE) - user_color_map[author_id] = COLOR_PALETTE[next_color_index] + # 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] @@ -146,4 +156,4 @@ def main(): console.print(f"[green]Chat log saved to {log_filename}[/green]") if __name__ == '__main__': - main() + main() \ No newline at end of file