Major Features Added: - Complete token bucket rate limiting for IRC commands and web interface - Per-user rate tracking with category-based limits (Basic, Gameplay, Management, Admin, Web) - Admin commands for rate limit management (\!rate_stats, \!rate_user, \!rate_unban, \!rate_reset) - Automatic violation tracking and temporary bans with cleanup - Global item spawn multiplier system with 75% spawn rate reduction - Central admin configuration system (config.py) - One-command bot startup script (start_petbot.sh) Rate Limiting: - Token bucket algorithm with burst capacity and refill rates - Category limits: Basic (20/min), Gameplay (10/min), Management (5/min), Web (60/min) - Graceful violation handling with user-friendly error messages - Admin exemption and override capabilities - Background cleanup of old violations and expired bans Item Spawn System: - Added global_spawn_multiplier to config/items.json for easy adjustment - Reduced all individual spawn rates by 75% (multiplied by 0.25) - Admins can fine-tune both global multiplier and individual item rates - Game engine integration applies multiplier to all spawn calculations Infrastructure: - Single admin user configuration in config.py - Enhanced startup script with dependency management and verification - Updated documentation and help system with rate limiting guide - Comprehensive test suite for rate limiting functionality Security: - Rate limiting protects against command spam and abuse - IP-based tracking for web interface requests - Proper error handling and status codes (429 for rate limits) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
103 lines
No EOL
2.7 KiB
Bash
Executable file
103 lines
No EOL
2.7 KiB
Bash
Executable file
#!/bin/bash
|
||
#
|
||
# PetBot Startup Script
|
||
# Complete one-command startup for PetBot with all dependencies
|
||
#
|
||
# Usage: ./start_petbot.sh
|
||
#
|
||
|
||
set -e # Exit on any error
|
||
|
||
echo "🐾 Starting PetBot..."
|
||
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
|
||
|
||
# Check if requirements are installed
|
||
echo "🔄 Checking dependencies..."
|
||
if ! python -c "import aiosqlite, irc, dotenv" 2>/dev/null; then
|
||
echo "📦 Installing/updating dependencies..."
|
||
|
||
# Create requirements.txt if it doesn't exist
|
||
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
|
||
fi
|
||
|
||
pip install --upgrade pip
|
||
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}')
|
||
except ImportError as e:
|
||
print(f'❌ Module import error: {e}')
|
||
sys.exit(1)
|
||
"
|
||
|
||
# Create data directory if it doesn't exist
|
||
if [ ! -d "data" ]; then
|
||
echo "📁 Creating data directory..."
|
||
mkdir -p data
|
||
fi
|
||
|
||
# Create backups directory if it doesn't exist
|
||
if [ ! -d "backups" ]; then
|
||
echo "📁 Creating backups directory..."
|
||
mkdir -p backups
|
||
fi
|
||
|
||
# Check if database exists, if not mention first-time setup
|
||
if [ ! -f "data/petbot.db" ]; then
|
||
echo "ℹ️ First-time setup detected - database will be created automatically"
|
||
fi
|
||
|
||
# Display 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 ""
|
||
echo "Press Ctrl+C to stop the bot"
|
||
echo "===================="
|
||
echo ""
|
||
|
||
# Launch the bot
|
||
exec python run_bot_with_reconnect.py |