Add comprehensive startup script validation and enhanced pet system
- Enhanced start_petbot.sh with extensive validation and error checking - Added emoji support to pet species system with database migration - Expanded pet species from 9 to 33 unique pets with balanced spawn rates - Improved database integrity validation and orphaned pet detection - Added comprehensive pre-startup testing and configuration validation - Enhanced locations with diverse species spawning across all areas - Added dual-type pets and rarity-based spawn distribution - Improved startup information display with feature overview - Added background monitoring and validation systems 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
add7731d80
commit
fca0423c84
8 changed files with 640 additions and 81 deletions
|
|
@ -57,6 +57,10 @@ class PetBotDebug:
|
|||
loop.run_until_complete(self.validate_all_player_data())
|
||||
print("✅ Player data validation complete")
|
||||
|
||||
print("🔄 Validating database integrity...")
|
||||
loop.run_until_complete(self.validate_database_integrity())
|
||||
print("✅ Database integrity validation complete")
|
||||
|
||||
print("🔄 Starting background validation task...")
|
||||
self.start_background_validation(loop)
|
||||
print("✅ Background validation started")
|
||||
|
|
@ -142,6 +146,79 @@ class PetBotDebug:
|
|||
print(f"❌ Error during player data validation: {e}")
|
||||
# Don't fail startup if validation fails
|
||||
|
||||
async def validate_database_integrity(self):
|
||||
"""Validate database integrity and fix common issues"""
|
||||
try:
|
||||
import aiosqlite
|
||||
async with aiosqlite.connect(self.database.db_path) as db:
|
||||
# Check for orphaned pets
|
||||
cursor = await db.execute("""
|
||||
SELECT COUNT(*) FROM pets
|
||||
WHERE species_id NOT IN (SELECT id FROM pet_species)
|
||||
""")
|
||||
orphaned_pets = (await cursor.fetchone())[0]
|
||||
|
||||
if orphaned_pets > 0:
|
||||
print(f"⚠️ Found {orphaned_pets} orphaned pets - fixing references...")
|
||||
# This should not happen with the new startup logic, but just in case
|
||||
await self.fix_orphaned_pets(db)
|
||||
|
||||
# Check player data accessibility
|
||||
cursor = await db.execute("SELECT id, nickname FROM players")
|
||||
players = await cursor.fetchall()
|
||||
|
||||
total_accessible_pets = 0
|
||||
for player_id, nickname in players:
|
||||
cursor = await db.execute("""
|
||||
SELECT COUNT(*) FROM pets p
|
||||
JOIN pet_species ps ON p.species_id = ps.id
|
||||
WHERE p.player_id = ?
|
||||
""", (player_id,))
|
||||
accessible_pets = (await cursor.fetchone())[0]
|
||||
total_accessible_pets += accessible_pets
|
||||
|
||||
if accessible_pets > 0:
|
||||
print(f" ✅ {nickname}: {accessible_pets} pets accessible")
|
||||
else:
|
||||
# Get total pets for this player
|
||||
cursor = await db.execute("SELECT COUNT(*) FROM pets WHERE player_id = ?", (player_id,))
|
||||
total_pets = (await cursor.fetchone())[0]
|
||||
if total_pets > 0:
|
||||
print(f" ⚠️ {nickname}: {total_pets} pets but 0 accessible (orphaned)")
|
||||
|
||||
print(f"✅ Database integrity check: {total_accessible_pets} total accessible pets")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Database integrity validation failed: {e}")
|
||||
|
||||
async def fix_orphaned_pets(self, db):
|
||||
"""Fix orphaned pet references (emergency fallback)"""
|
||||
try:
|
||||
# This is a simplified fix - map common species names to current IDs
|
||||
common_species = ['Flamey', 'Aqua', 'Leafy', 'Vinewrap', 'Bloomtail', 'Furry']
|
||||
|
||||
for species_name in common_species:
|
||||
cursor = await db.execute("SELECT id FROM pet_species WHERE name = ?", (species_name,))
|
||||
species_row = await cursor.fetchone()
|
||||
if species_row:
|
||||
current_id = species_row[0]
|
||||
# Update any pets that might be referencing old IDs for this species
|
||||
await db.execute("""
|
||||
UPDATE pets SET species_id = ?
|
||||
WHERE species_id NOT IN (SELECT id FROM pet_species)
|
||||
AND species_id IN (
|
||||
SELECT DISTINCT p.species_id FROM pets p
|
||||
WHERE p.species_id NOT IN (SELECT id FROM pet_species)
|
||||
LIMIT 1
|
||||
)
|
||||
""", (current_id,))
|
||||
|
||||
await db.commit()
|
||||
print(" ✅ Orphaned pets fixed")
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ Failed to fix orphaned pets: {e}")
|
||||
|
||||
def start_background_validation(self, loop):
|
||||
"""Start background task to periodically validate player data"""
|
||||
import asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue