- 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>
203 lines
No EOL
6 KiB
Bash
Executable file
203 lines
No EOL
6 KiB
Bash
Executable file
#!/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 |