Some checks failed
Release / release (push) Has been cancelled
Full-stack dashboard for controlling, automating, and analyzing Artifacts MMO characters via the game's HTTP API. Backend (FastAPI): - Async Artifacts API client with rate limiting and retry - 6 automation strategies (combat, gathering, crafting, trading, task, leveling) - Automation engine with runner, manager, cooldown tracker, pathfinder - WebSocket relay (game server -> frontend) - Game data cache, character snapshots, price history, analytics - 9 API routers, 7 database tables, 3 Alembic migrations - 108 unit tests Frontend (Next.js 15 + shadcn/ui): - Live character dashboard with HP/XP bars and cooldowns - Character detail with stats, equipment, inventory, skills, manual actions - Automation management with live log streaming - Interactive canvas map with content-type coloring and zoom/pan - Bank management, Grand Exchange with price charts - Events, logs, analytics pages with Recharts - WebSocket auto-reconnect with query cache invalidation - Settings page, error boundaries, dark theme Infrastructure: - Docker Compose (dev + prod) - GitHub Actions CI/CD - Documentation (Architecture, Automation, Deployment, API)
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
"""Game events API router."""
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from fastapi import APIRouter, HTTPException, Query, Request
|
|
from httpx import HTTPStatusError
|
|
from sqlalchemy import select
|
|
|
|
from app.database import async_session_factory
|
|
from app.models.event_log import EventLog
|
|
from app.services.artifacts_client import ArtifactsClient
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter(prefix="/api/events", tags=["events"])
|
|
|
|
|
|
def _get_client(request: Request) -> ArtifactsClient:
|
|
return request.app.state.artifacts_client
|
|
|
|
|
|
@router.get("/")
|
|
async def get_active_events(request: Request) -> dict[str, Any]:
|
|
"""Get currently active game events from the Artifacts API."""
|
|
client = _get_client(request)
|
|
|
|
try:
|
|
events = await client.get_events()
|
|
except HTTPStatusError as exc:
|
|
raise HTTPException(
|
|
status_code=exc.response.status_code,
|
|
detail=f"Artifacts API error: {exc.response.text}",
|
|
) from exc
|
|
|
|
return {"events": events}
|
|
|
|
|
|
@router.get("/history")
|
|
async def get_event_history(
|
|
request: Request,
|
|
event_type: str | None = Query(default=None, description="Filter by event type"),
|
|
character_name: str | None = Query(default=None, description="Filter by character"),
|
|
limit: int = Query(default=100, ge=1, le=500, description="Max entries to return"),
|
|
offset: int = Query(default=0, ge=0, description="Offset for pagination"),
|
|
) -> dict[str, Any]:
|
|
"""Get historical events from the event log database."""
|
|
async with async_session_factory() as db:
|
|
stmt = select(EventLog).order_by(EventLog.created_at.desc())
|
|
|
|
if event_type:
|
|
stmt = stmt.where(EventLog.event_type == event_type)
|
|
if character_name:
|
|
stmt = stmt.where(EventLog.character_name == character_name)
|
|
|
|
stmt = stmt.offset(offset).limit(limit)
|
|
|
|
result = await db.execute(stmt)
|
|
logs = result.scalars().all()
|
|
|
|
return {
|
|
"events": [
|
|
{
|
|
"id": log.id,
|
|
"event_type": log.event_type,
|
|
"event_data": log.event_data,
|
|
"character_name": log.character_name,
|
|
"map_x": log.map_x,
|
|
"map_y": log.map_y,
|
|
"created_at": log.created_at.isoformat() if log.created_at else None,
|
|
}
|
|
for log in logs
|
|
],
|
|
"limit": limit,
|
|
"offset": offset,
|
|
}
|