Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""
Main entry point for Project Chimera Discord Bot.
"""

import asyncio
import logging
import sys
from pathlib import Path

# Add src to path for imports
sys.path.insert(0, str(Path(__file__).parent))

from src.adapters.discord_adapter import DiscordAdapter
from src.config import get_settings


def setup_logging() -> None:
"""Set up logging configuration."""
settings = get_settings()

# Configure logging format
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logging.basicConfig(
level=getattr(logging, settings.log_level.upper()),
format=log_format,
handlers=[
logging.StreamHandler(),
logging.FileHandler("chimera_bot.log", encoding="utf-8")
]
)

# Reduce discord.py logging verbosity unless in debug mode
if not settings.debug_mode:
logging.getLogger("discord").setLevel(logging.INFO)
logging.getLogger("discord.http").setLevel(logging.WARNING)


async def health_check() -> None:
"""Perform basic health checks before starting the bot."""
logger = logging.getLogger(__name__)
settings = get_settings()

logger.info("Performing health checks...")

# Check Discord token is present
if not settings.discord_bot_token:
logger.error("Discord bot token not found in environment variables!")
sys.exit(1)

# Validate token format (basic check)
if not settings.discord_bot_token.strip():
logger.error("Discord bot token is empty!")
sys.exit(1)

logger.info("Health checks passed ✓")


def print_startup_banner() -> None:
"""Print a nice startup banner."""
banner = """
╔══════════════════════════════════════════╗
║ Project Chimera - LoL Bot ║
║ AI-Powered Match Analysis ║
╚══════════════════════════════════════════╝
"""
print(banner)


async def main() -> None:
"""Main async entry point."""
logger = logging.getLogger(__name__)

try:
# Print banner
print_startup_banner()

# Setup logging
setup_logging()

logger.info("Starting Project Chimera Discord Bot...")

# Perform health checks
await health_check()

# Create and start the Discord adapter
adapter = DiscordAdapter()

logger.info("Bot initialization complete. Connecting to Discord...")

# Run the bot (this blocks)
adapter.run()

except KeyboardInterrupt:
logger.info("Shutdown requested by user (Ctrl+C)")
except Exception as e:
logger.error(f"Fatal error: {e}", exc_info=True)
sys.exit(1)


if __name__ == "__main__":
# Run the main function
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nBot stopped by user.")
except Exception as e:
print(f"Failed to start bot: {e}")
sys.exit(1)
43 changes: 43 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Core Dependencies
discord.py>=2.3.2 # Discord bot framework
pydantic>=2.5.0 # Data validation and settings
pydantic-settings>=2.1.0 # Settings management
python-dotenv>=1.0.0 # Environment variable loading

# Async Support
aiohttp>=3.9.0 # Async HTTP client (required by discord.py)

# Database (for future integration)
asyncpg>=0.29.0 # PostgreSQL async driver
redis>=5.0.0 # Redis client for caching and task queue
SQLAlchemy>=2.0.0 # ORM for database operations

# Task Queue (for future integration with CLI 2)
celery>=5.3.0 # Distributed task queue
flower>=2.0.0 # Celery monitoring tool (optional)

# Riot API (for future integration)
# cassiopeia>=5.0.0 # Riot API wrapper with rate limiting
# OR
# riot-watcher>=3.3.0 # Alternative Riot API wrapper

# Development & Testing
pytest>=7.4.0 # Testing framework
pytest-asyncio>=0.21.0 # Async test support
pytest-cov>=4.1.0 # Code coverage
black>=23.0.0 # Code formatter
ruff>=0.1.0 # Linter
mypy>=1.7.0 # Type checker
pre-commit>=3.5.0 # Git hooks

# Logging & Monitoring
structlog>=23.2.0 # Structured logging
python-json-logger>=2.0.7 # JSON logging

# Utilities
python-dateutil>=2.8.2 # Date/time utilities
pytz>=2023.3 # Timezone support
httpx>=0.25.0 # Modern HTTP client with async support

# Hot Reload Development (for Vibe Coding)
watchdog>=3.0.0 # File system monitoring for hot reload
50 changes: 50 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Project Chimera Setup Script
echo "=================================================="
echo " Project Chimera - Discord Bot Setup"
echo "=================================================="

# Check Python version
echo -n "Checking Python version... "
python_version=$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1)
required_version="3.11"

if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" = "$required_version" ]; then
echo "✓ Python $python_version"
else
echo "✗ Python $python_version (requires 3.11+)"
exit 1
fi

# Create virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then
echo "Creating virtual environment..."
python3 -m venv .venv
echo "✓ Virtual environment created"
else
echo "✓ Virtual environment exists"
fi

# Activate virtual environment
echo "Activating virtual environment..."
source .venv/bin/activate

# Install/upgrade pip
echo "Upgrading pip..."
pip install --upgrade pip > /dev/null 2>&1

# Install requirements
echo "Installing dependencies..."
pip install -r requirements.txt

echo ""
echo "✅ Setup complete!"
echo ""
echo "Next steps:"
echo "1. Edit .env file and add your Discord bot token"
echo "2. Activate the virtual environment: source .venv/bin/activate"
echo "3. Run the bot: python main.py"
echo ""
echo "For development with hot reload:"
echo " watchmedo auto-restart -d src -p '*.py' -- python main.py"
8 changes: 6 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Project Chimera - LoL Discord Bot with AI-powered analysis."""
"""
Project Chimera - AI-Powered LoL Discord Bot
==============================================

__version__ = "0.1.0"
A hexagonal architecture implementation for a Discord bot that integrates
with Riot Games API to provide AI-driven match analysis and insights.
"""
10 changes: 4 additions & 6 deletions src/adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Adapter implementations for external services."""

from .database import DatabaseAdapter
from .riot_api import RiotAPIAdapter

__all__ = ["RiotAPIAdapter", "DatabaseAdapter"]
"""
External adapters package.
This package contains all integrations with external systems (Discord, Riot API, Database, etc.)
"""
Loading
Loading