diff --git a/README.md b/README.md index 4f8126f..87f5a3d 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,12 @@ Features: - check if the assigned enemy has been hit after 1 minute, if not reassign - match targets up with members that have the appropriate stats - dashboard to see who is supposed to hit who -- maybe also enemy stats \ No newline at end of file +- maybe also enemy stats + + +ToDo: +- move interval button to a neutral spot +- sections to list faction memebers + - needs to be movable objects +- Assignment pools depending on stats + - players will be round-robin queued their targets from here \ No newline at end of file diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc index 583d2c2..21493d8 100644 Binary files a/__pycache__/main.cpython-311.pyc and b/__pycache__/main.cpython-311.pyc differ diff --git a/main.py b/main.py index 1d3e4fc..32e34f9 100644 --- a/main.py +++ b/main.py @@ -7,21 +7,22 @@ from cogs.commands import HitCommands import asyncio import uvicorn -from fastapi import FastAPI, Request, Form +from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates +from pydantic import BaseModel from services.torn_api import update_enemy_faction, update_friendly_faction - - +# ----------------------------- +# FastAPI setup +# ----------------------------- app = FastAPI() templates = Jinja2Templates(directory="templates") app.mount("/static", StaticFiles(directory="static"), name="static") - # ----------------------------- # Dashboard page # ----------------------------- @@ -30,28 +31,32 @@ async def dashboard(request: Request): print(">>> DASHBOARD ROUTE LOADED") return templates.TemplateResponse("dashboard.html", {"request": request}) - +# ----------------------------- +# Pydantic model for JSON payloads +# ----------------------------- +class FactionRequest(BaseModel): + faction_id: int + interval: int # ----------------------------- # API Endpoints # ----------------------------- -@app.post("/api/enemy") -async def api_enemy(faction_id: int, interval: int): - await update_enemy_faction(faction_id, interval) - return {"status": "enemy loop running", "id": faction_id, "interval": interval} +@app.post("/api/update_enemy_faction") +async def api_enemy(data: FactionRequest): + await update_enemy_faction(data.faction_id, data.interval) + return {"status": "enemy loop running", "id": data.faction_id, "interval": data.interval} +@app.post("/api/update_friendly_faction") +async def api_friendly(data: FactionRequest): + await update_friendly_faction(data.faction_id, data.interval) + return {"status": "friendly loop running", "id": data.faction_id, "interval": data.interval} -@app.post("/api/friendly") -async def api_friendly(faction_id: int, interval: int): - await update_friendly_faction(faction_id, interval) - return {"status": "friendly loop running", "id": faction_id, "interval": interval} - - -# Discord +# ----------------------------- +# Discord bot setup +# ----------------------------- intents = discord.Intents.default() intents.message_content = True - enrolled_attackers = [] enemy_queue = [] active_assignments = {} @@ -92,6 +97,9 @@ TOKEN = "YOUR_DISCORD_TOKEN" async def start_bot(): await bot.start(TOKEN) +# ----------------------------- +# Main entry +# ----------------------------- if __name__ == "__main__": loop = asyncio.get_event_loop() diff --git a/routes/faction.py b/routes/faction.py deleted file mode 100644 index 25268f8..0000000 --- a/routes/faction.py +++ /dev/null @@ -1,31 +0,0 @@ -from fastapi import APIRouter -from pydantic import BaseModel -import asyncio - -router = APIRouter() - -class FactionRequest(BaseModel): - faction_id: int - refresh_interval: int - -async def update_friendly_faction_loop(faction_id: int, interval: int): - while True: - print(f"Refreshing friendly faction {faction_id}") - # call your update_friendly_faction() here - await asyncio.sleep(interval) - -async def update_enemy_faction_loop(faction_id: int, interval: int): - while True: - print(f"Refreshing enemy faction {faction_id}") - # call your update_enemy_faction() here - await asyncio.sleep(interval) - -@router.post("/refresh/friendly") -async def refresh_friendly(data: FactionRequest): - asyncio.create_task(update_friendly_faction_loop(data.faction_id, data.refresh_interval)) - return {"status": "friendly loop started"} - -@router.post("/refresh/enemy") -async def refresh_enemy(data: FactionRequest): - asyncio.create_task(update_enemy_faction_loop(data.faction_id, data.refresh_interval)) - return {"status": "enemy loop started"} diff --git a/static/dashboard.js b/static/dashboard.js index e69de29..48fb613 100644 --- a/static/dashboard.js +++ b/static/dashboard.js @@ -0,0 +1,36 @@ +async function updateEnemy() { + const factionId = parseInt(document.getElementById("enemyId").value); + const interval = parseInt(document.getElementById("refreshInterval").value); + + if (!factionId || !interval) { + alert("Please enter Enemy Faction ID and Refresh Interval!"); + return; + } + + await fetch(`/api/update_enemy_faction`, { + method: "POST", + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({ faction_id: factionId, interval: interval }) + }); +} + +async function updateFriendly() { + const factionId = parseInt(document.getElementById("friendlyId").value); + + if (!factionId) { + alert("Please enter Friendly Faction ID!"); + return; + } + + const interval = parseInt(document.getElementById("refreshInterval").value); + if (!interval) { + alert("Please enter Refresh Interval!"); + return; + } + + await fetch(`/api/update_friendly_faction`, { + method: "POST", + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({ faction_id: factionId, interval: interval }) + }); +} diff --git a/static/styles.css b/static/styles.css index e69de29..edf5e25 100644 --- a/static/styles.css +++ b/static/styles.css @@ -0,0 +1,55 @@ +body { + font-family: Arial, sans-serif; + background-color: #1e1e2f; + color: #f0f0f0; + margin: 0; + padding: 0; +} + +.container { + max-width: 800px; + margin: 2rem auto; + padding: 2rem; + background-color: #2c2c3e; + border-radius: 12px; + box-shadow: 0 0 20px rgba(0,0,0,0.5); +} + +h1 { + text-align: center; + color: #ffcc00; +} + +.faction-section { + background-color: #3a3a4d; + margin: 1.5rem 0; + padding: 1rem 1.5rem; + border-radius: 8px; +} + +.faction-section h2 { + color: #66ccff; +} + +input[type="number"] { + padding: 0.5rem; + margin-right: 0.5rem; + border-radius: 6px; + border: none; + width: 150px; +} + +button { + padding: 0.5rem 1rem; + border-radius: 6px; + border: none; + background-color: #66ccff; + color: #1e1e2f; + font-weight: bold; + cursor: pointer; + transition: background-color 0.2s; +} + +button:hover { + background-color: #3399ff; +} diff --git a/templates/dashboard.html b/templates/dashboard.html index 667d65a..b254326 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -1,24 +1,28 @@ - +
+