Fix team builder issues, Added startup import checks for consistency
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
08f7aa8ea8
commit
39ba55832d
5 changed files with 192 additions and 60 deletions
|
|
@ -53,6 +53,14 @@ class PetBotDebug:
|
|||
self.load_modules()
|
||||
print("✅ Modules loaded")
|
||||
|
||||
print("🔄 Validating player data and achievements...")
|
||||
loop.run_until_complete(self.validate_all_player_data())
|
||||
print("✅ Player data validation complete")
|
||||
|
||||
print("🔄 Starting background validation task...")
|
||||
self.start_background_validation(loop)
|
||||
print("✅ Background validation started")
|
||||
|
||||
print("🔄 Starting web server...")
|
||||
self.web_server = PetBotWebServer(self.database, port=8080)
|
||||
self.web_server.start_in_thread()
|
||||
|
|
@ -92,6 +100,64 @@ class PetBotDebug:
|
|||
|
||||
print(f"✅ Loaded {len(self.modules)} modules with {len(self.command_map)} commands")
|
||||
|
||||
async def validate_all_player_data(self):
|
||||
"""Validate and refresh all player data on startup to prevent state loss"""
|
||||
try:
|
||||
# Get all players from database
|
||||
import aiosqlite
|
||||
async with aiosqlite.connect(self.database.db_path) as db:
|
||||
cursor = await db.execute("SELECT id, nickname FROM players")
|
||||
players = await cursor.fetchall()
|
||||
|
||||
print(f"🔄 Found {len(players)} players to validate...")
|
||||
|
||||
for player_id, nickname in players:
|
||||
try:
|
||||
# Check and award any missing achievements for each player
|
||||
new_achievements = await self.game_engine.check_all_achievements(player_id)
|
||||
|
||||
if new_achievements:
|
||||
print(f" 🏆 {nickname}: Restored {len(new_achievements)} missing achievements")
|
||||
for achievement in new_achievements:
|
||||
print(f" - {achievement['name']}")
|
||||
else:
|
||||
print(f" ✅ {nickname}: All achievements up to date")
|
||||
|
||||
# Validate team composition
|
||||
team_composition = await self.database.get_team_composition(player_id)
|
||||
if team_composition["active_pets"] == 0 and team_composition["total_pets"] > 0:
|
||||
# Player has pets but none active - activate the first one
|
||||
pets = await self.database.get_player_pets(player_id)
|
||||
if pets:
|
||||
first_pet = pets[0]
|
||||
await self.database.activate_pet(player_id, str(first_pet["id"]))
|
||||
print(f" 🔧 {nickname}: Auto-activated pet {first_pet['nickname'] or first_pet['species_name']} (no active pets)")
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ Error validating {nickname}: {e}")
|
||||
|
||||
print("✅ All player data validated and updated")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error during player data validation: {e}")
|
||||
# Don't fail startup if validation fails
|
||||
|
||||
def start_background_validation(self, loop):
|
||||
"""Start background task to periodically validate player data"""
|
||||
import asyncio
|
||||
|
||||
async def periodic_validation():
|
||||
while True:
|
||||
try:
|
||||
await asyncio.sleep(1800) # Run every 30 minutes
|
||||
print("🔄 Running periodic player data validation...")
|
||||
await self.validate_all_player_data()
|
||||
except Exception as e:
|
||||
print(f"❌ Error in background validation: {e}")
|
||||
|
||||
# Create background task
|
||||
loop.create_task(periodic_validation())
|
||||
|
||||
async def reload_modules(self):
|
||||
"""Reload all modules (for admin use)"""
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue