Petbot/start_petbot.sh
megaproxy fca0423c84 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>
2025-07-16 00:17:54 +00:00

203 lines
No EOL
6 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#
# PetBot Startup Script
# Complete one-command startup for PetBot with all dependencies and validation
#
# Usage: ./start_petbot.sh
#
set -e # Exit on any error
echo "🐾 Starting PetBot..."
echo "===================="
echo "Version: $(date '+%Y-%m-%d %H:%M:%S') - Enhanced with startup validation"
echo ""
# Get script directory (works even if called from elsewhere)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "📁 Working directory: $SCRIPT_DIR"
# Check if virtual environment exists
if [ ! -d "venv" ]; then
echo "❌ Virtual environment not found!"
echo "🔧 Creating virtual environment..."
python3 -m venv venv
echo "✅ Virtual environment created"
fi
# Activate virtual environment
echo "🔄 Activating virtual environment..."
source venv/bin/activate
# Upgrade pip to latest version
echo "🔄 Ensuring pip is up to date..."
pip install --upgrade pip -q
# Check if requirements are installed
echo "🔄 Checking dependencies..."
if ! python -c "import aiosqlite, irc" 2>/dev/null; then
echo "📦 Installing/updating dependencies from requirements.txt..."
# Verify requirements.txt exists
if [ ! -f "requirements.txt" ]; then
echo "❌ requirements.txt not found!"
echo "🔧 Please run install_prerequisites.sh first"
exit 1
fi
pip install -r requirements.txt
echo "✅ Dependencies installed"
else
echo "✅ Dependencies already satisfied"
fi
# Verify core modules can be imported
echo "🔄 Verifying core modules..."
python3 -c "
import sys
sys.path.append('.')
try:
from src.database import Database
from src.game_engine import GameEngine
from src.rate_limiter import RateLimiter
from src.irc_connection_manager import IRCConnectionManager
from config import ADMIN_USER, IRC_CONFIG, RATE_LIMIT_CONFIG
print('✅ Core modules verified')
print(f' Admin user: {ADMIN_USER}')
print(f' IRC Channel: {IRC_CONFIG[\"channel\"]}')
print(f' Rate limiting: {\"Enabled\" if RATE_LIMIT_CONFIG[\"enabled\"] else \"Disabled\"}')
except ImportError as e:
print(f'❌ Module import error: {e}')
print('💡 Try running: ./install_prerequisites.sh')
sys.exit(1)
"
# Create required directories
echo "🔄 Creating required directories..."
mkdir -p data backups logs
# Check configuration files
echo "🔄 Verifying configuration files..."
config_files=("config/pets.json" "config/locations.json" "config/items.json" "config/achievements.json" "config/gyms.json")
missing_configs=()
for config_file in "${config_files[@]}"; do
if [ ! -f "$config_file" ]; then
missing_configs+=("$config_file")
fi
done
if [ ${#missing_configs[@]} -gt 0 ]; then
echo "❌ Missing configuration files:"
for missing in "${missing_configs[@]}"; do
echo " - $missing"
done
echo "💡 These files are required for proper bot operation"
exit 1
fi
echo "✅ All configuration files present"
# Database pre-flight check
if [ -f "data/petbot.db" ]; then
echo "🔄 Validating existing database..."
# Quick database validation
python3 -c "
import sqlite3
import sys
try:
conn = sqlite3.connect('data/petbot.db')
cursor = conn.cursor()
# Check essential tables exist
tables = ['players', 'pets', 'pet_species', 'locations']
for table in tables:
cursor.execute(f'SELECT COUNT(*) FROM {table}')
count = cursor.fetchone()[0]
print(f' ✅ {table}: {count} records')
conn.close()
print('✅ Database validation passed')
except Exception as e:
print(f'❌ Database validation failed: {e}')
print('💡 Database may be corrupted - backup and recreate if needed')
sys.exit(1)
"
else
echo " First-time setup detected - database will be created automatically"
fi
# Pre-startup system test
echo "🔄 Running pre-startup system test..."
python3 -c "
import sys
sys.path.append('.')
try:
# Test basic imports and initialization
from run_bot_debug import PetBotDebug
# Create a test bot instance to verify everything loads
print(' 🔧 Testing bot initialization...')
bot = PetBotDebug()
print(' ✅ Bot instance created successfully')
print('✅ Pre-startup test passed')
except Exception as e:
print(f'❌ Pre-startup test failed: {e}')
import traceback
traceback.print_exc()
sys.exit(1)
"
# Display comprehensive startup information
echo ""
echo "🚀 Launching PetBot with Enhanced Features..."
echo "============================================="
echo "🌐 Web interface: http://localhost:8080"
echo "📱 Public access: http://petz.rdx4.com/"
echo "💬 IRC Server: irc.libera.chat"
echo "📢 IRC Channel: #petz"
echo "👤 Admin User: $(python3 -c 'from config import ADMIN_USER; print(ADMIN_USER)')"
echo ""
echo "🎮 Features Available:"
echo " ✅ 33 Pet Species with Emojis"
echo " ✅ 6 Exploration Locations"
echo " ✅ Team Builder with PIN Verification"
echo " ✅ Achievement System"
echo " ✅ Gym Battles"
echo " ✅ Weather System"
echo " ✅ Rate Limiting & Anti-Abuse"
echo " ✅ Auto-Reconnection"
echo " ✅ Startup Data Validation"
echo " ✅ Background Monitoring"
echo ""
echo "🔧 Technical Details:"
echo " 📊 Database: SQLite with validation"
echo " 🌐 Webserver: Integrated with bot instance"
echo " 🛡️ Security: Rate limiting enabled"
echo " 🔄 Reliability: Auto-reconnect on failure"
echo " 📈 Monitoring: Background validation every 30min"
echo ""
echo "Press Ctrl+C to stop the bot"
echo "============================================="
echo ""
# Launch the appropriate bot based on what's available
if [ -f "run_bot_with_reconnect.py" ]; then
echo "🚀 Starting with auto-reconnect support..."
exec python run_bot_with_reconnect.py
elif [ -f "run_bot_debug.py" ]; then
echo "🚀 Starting in debug mode..."
exec python run_bot_debug.py
else
echo "❌ No bot startup file found!"
echo "💡 Expected: run_bot_with_reconnect.py or run_bot_debug.py"
exit 1
fi