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
164
start_petbot.sh
164
start_petbot.sh
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# PetBot Startup Script
|
||||
# Complete one-command startup for PetBot with all dependencies
|
||||
# Complete one-command startup for PetBot with all dependencies and validation
|
||||
#
|
||||
# Usage: ./start_petbot.sh
|
||||
#
|
||||
|
|
@ -10,6 +10,8 @@ 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)"
|
||||
|
|
@ -29,23 +31,22 @@ fi
|
|||
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, dotenv" 2>/dev/null; then
|
||||
echo "📦 Installing/updating dependencies..."
|
||||
if ! python -c "import aiosqlite, irc" 2>/dev/null; then
|
||||
echo "📦 Installing/updating dependencies from requirements.txt..."
|
||||
|
||||
# Create requirements.txt if it doesn't exist
|
||||
# Verify requirements.txt exists
|
||||
if [ ! -f "requirements.txt" ]; then
|
||||
echo "📝 Creating requirements.txt..."
|
||||
cat > requirements.txt << EOF
|
||||
aiosqlite>=0.17.0
|
||||
irc>=20.3.0
|
||||
python-dotenv>=0.19.0
|
||||
aiohttp>=3.8.0
|
||||
EOF
|
||||
echo "❌ requirements.txt not found!"
|
||||
echo "🔧 Please run install_prerequisites.sh first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
echo "✅ Dependencies installed"
|
||||
else
|
||||
|
|
@ -60,44 +61,143 @@ sys.path.append('.')
|
|||
|
||||
try:
|
||||
from src.database import Database
|
||||
from src.game_engine import GameEngine
|
||||
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 data directory if it doesn't exist
|
||||
if [ ! -d "data" ]; then
|
||||
echo "📁 Creating data directory..."
|
||||
mkdir -p data
|
||||
# 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
|
||||
|
||||
# Create backups directory if it doesn't exist
|
||||
if [ ! -d "backups" ]; then
|
||||
echo "📁 Creating backups directory..."
|
||||
mkdir -p backups
|
||||
fi
|
||||
echo "✅ All configuration files present"
|
||||
|
||||
# Check if database exists, if not mention first-time setup
|
||||
if [ ! -f "data/petbot.db" ]; then
|
||||
# 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
|
||||
|
||||
# Display startup information
|
||||
# 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 Auto-Reconnect..."
|
||||
echo "🌐 Web interface will be available at: http://localhost:8080"
|
||||
echo "💬 IRC: Connecting to irc.libera.chat #petz"
|
||||
echo "📊 Features: Rate limiting, auto-reconnect, web interface, team builder"
|
||||
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 "============================================="
|
||||
echo ""
|
||||
|
||||
# Launch the bot
|
||||
exec python run_bot_with_reconnect.py
|
||||
# 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue