"""
- pets_by_rarity = {}
- for pet in petdex_data:
- rarity = pet['rarity']
- if rarity not in pets_by_rarity:
- pets_by_rarity[rarity] = []
- pets_by_rarity[rarity].append(pet)
-
+ # Sort and group pets based on sort_mode
petdex_html = ""
total_species = len(petdex_data)
- for rarity in sorted(pets_by_rarity.keys()):
- pets_in_rarity = pets_by_rarity[rarity]
- rarity_name = rarity_names.get(rarity, f"Rarity {rarity}")
- rarity_color = rarity_colors.get(rarity, "#ffffff")
+ if sort_mode == 'type':
+ # Group by type1
+ pets_by_type = {}
+ for pet in petdex_data:
+ pet_type = pet['type1']
+ if pet_type not in pets_by_type:
+ pets_by_type[pet_type] = []
+ # Check for duplicates within this type
+ if pet not in pets_by_type[pet_type]:
+ pets_by_type[pet_type].append(pet)
+
+ # Sort each type group by name and remove any remaining duplicates
+ for type_name in pets_by_type:
+ # Remove duplicates based on pet ID and sort by name
+ seen_ids = set()
+ unique_pets = []
+ for pet in pets_by_type[type_name]:
+ if pet['id'] not in seen_ids:
+ seen_ids.add(pet['id'])
+ unique_pets.append(pet)
+ pets_by_type[type_name] = sorted(unique_pets, key=lambda x: x['name'])
+
+ type_colors = {
+ 'Fire': '#F08030', 'Water': '#6890F0', 'Grass': '#78C850', 'Electric': '#F8D030',
+ 'Psychic': '#F85888', 'Ice': '#98D8D8', 'Dragon': '#7038F8', 'Dark': '#705848',
+ 'Fighting': '#C03028', 'Poison': '#A040A0', 'Ground': '#E0C068', 'Flying': '#A890F0',
+ 'Bug': '#A8B820', 'Rock': '#B8A038', 'Ghost': '#705898', 'Steel': '#B8B8D0',
+ 'Normal': '#A8A878', 'Fairy': '#EE99AC'
+ }
+
+ for type_name in sorted(pets_by_type.keys()):
+ pets_in_type = pets_by_type[type_name]
+ type_color = type_colors.get(type_name, '#A8A878')
+
+ petdex_html += f"""
+
+
+ {type_name} Type ({len(pets_in_type)} species)
+
+
"""
+
+ for pet in pets_in_type:
+ type_str = pet['type1']
+ if pet['type2']:
+ type_str += f" / {pet['type2']}"
+
+ petdex_html += f"""
+
"""
+
+ elif sort_mode == 'location':
+ # Group by spawn locations
+ pets_by_location = {}
+ pets_no_location = []
+
+ for pet in petdex_data:
+ if pet['spawn_locations']:
+ for location in pet['spawn_locations']:
+ loc_name = location['location_name']
+ if loc_name not in pets_by_location:
+ pets_by_location[loc_name] = []
+ # Check for duplicates within this location
+ if pet not in pets_by_location[loc_name]:
+ pets_by_location[loc_name].append(pet)
+ else:
+ pets_no_location.append(pet)
+
+ # Sort each location group by name and remove any remaining duplicates
+ for location_name in pets_by_location:
+ # Remove duplicates based on pet ID and sort by name
+ seen_ids = set()
+ unique_pets = []
+ for pet in pets_by_location[location_name]:
+ if pet['id'] not in seen_ids:
+ seen_ids.add(pet['id'])
+ unique_pets.append(pet)
+ pets_by_location[location_name] = sorted(unique_pets, key=lambda x: x['name'])
+
+ location_colors = {
+ 'Starter Town': '#4CAF50',
+ 'Whispering Woods': '#2E7D32',
+ 'Thunder Peaks': '#FF9800',
+ 'Stone Caverns': '#795548',
+ 'Frozen Lake': '#2196F3',
+ 'Volcanic Crater': '#F44336'
+ }
+
+ for location_name in sorted(pets_by_location.keys()):
+ pets_in_location = pets_by_location[location_name]
+ location_color = location_colors.get(location_name, '#A8A878')
+
+ petdex_html += f"""
+
"""
+
+ # Add pets with no location at the end (remove duplicates)
+ if pets_no_location:
+ seen_ids = set()
+ unique_no_location = []
+ for pet in pets_no_location:
+ if pet['id'] not in seen_ids:
+ seen_ids.add(pet['id'])
+ unique_no_location.append(pet)
+ pets_no_location = sorted(unique_no_location, key=lambda x: x['name'])
+
+ if pets_no_location:
+ petdex_html += f"""
+
"""
+
+ else: # Default to rarity sorting
+ pets_by_rarity = {}
+ for pet in petdex_data:
+ rarity = pet['rarity']
+ if rarity not in pets_by_rarity:
+ pets_by_rarity[rarity] = []
+ # Check for duplicates within this rarity
+ if pet not in pets_by_rarity[rarity]:
+ pets_by_rarity[rarity].append(pet)
+
+ # Sort each rarity group by name and remove any remaining duplicates
+ for rarity in pets_by_rarity:
+ # Remove duplicates based on pet ID and sort by name
+ seen_ids = set()
+ unique_pets = []
+ for pet in pets_by_rarity[rarity]:
+ if pet['id'] not in seen_ids:
+ seen_ids.add(pet['id'])
+ unique_pets.append(pet)
+ pets_by_rarity[rarity] = sorted(unique_pets, key=lambda x: x['name'])
+
+ for rarity in sorted(pets_by_rarity.keys()):
+ pets_in_rarity = pets_by_rarity[rarity]
+ rarity_name = rarity_names.get(rarity, f"Rarity {rarity}")
+ rarity_color = rarity_colors.get(rarity, "#ffffff")
petdex_html += f"""
@@ -2391,6 +3162,45 @@ class PetBotRequestHandler(BaseHTTPRequestHandler):
The petdex appears to be empty. Contact an administrator.
π Found {len(petdex_data)} pets matching "{search_query}"
' if search_query else ''}
+
+ """
+
+ # Determine header text based on sort mode
+ if sort_mode == 'type':
+ header_text = "π Pet Collection by Type"
+ description = "π· Pets are organized by their primary type. Each type has different strengths and weaknesses!"
+ elif sort_mode == 'name':
+ header_text = "π Pet Collection (A-Z)"
+ description = "π€ All pets sorted alphabetically by name. Perfect for finding specific species!"
+ elif sort_mode == 'location':
+ header_text = "π Pet Collection by Location"
+ description = "πΊοΈ Pets are organized by where they can be found. Use !travel <location> to visit these areas!"
+ elif sort_mode == 'all':
+ header_text = "π Complete Pet Collection"
+ description = "π All pets displayed in a comprehensive grid view with locations and stats!"
+ else:
+ header_text = "π Pet Collection by Rarity"
+ description = "π Pets are organized by rarity. Use !wild <location> in #petz to see what spawns where!"
+
# Combine all content
content = f"""
@@ -2400,9 +3210,11 @@ class PetBotRequestHandler(BaseHTTPRequestHandler):
{stats_content}
+ {search_interface}
+
-
π Pet Collection by Rarity
-
π― Pets are organized by rarity. Use !wild <location> in #petz to see what spawns where!