proper functoin calls for faction data
This commit is contained in:
@@ -7,3 +7,11 @@ Features:
|
|||||||
- match targets up with members that have the appropriate stats
|
- match targets up with members that have the appropriate stats
|
||||||
- dashboard to see who is supposed to hit who
|
- dashboard to see who is supposed to hit who
|
||||||
- maybe also enemy stats
|
- 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
|
||||||
Binary file not shown.
42
main.py
42
main.py
@@ -7,21 +7,22 @@ from cogs.commands import HitCommands
|
|||||||
import asyncio
|
import asyncio
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
from fastapi import FastAPI, Request, Form
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from services.torn_api import update_enemy_faction, update_friendly_faction
|
from services.torn_api import update_enemy_faction, update_friendly_faction
|
||||||
|
|
||||||
|
# -----------------------------
|
||||||
|
# FastAPI setup
|
||||||
|
# -----------------------------
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
templates = Jinja2Templates(directory="templates")
|
||||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# Dashboard page
|
# Dashboard page
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
@@ -30,28 +31,32 @@ async def dashboard(request: Request):
|
|||||||
print(">>> DASHBOARD ROUTE LOADED")
|
print(">>> DASHBOARD ROUTE LOADED")
|
||||||
return templates.TemplateResponse("dashboard.html", {"request": request})
|
return templates.TemplateResponse("dashboard.html", {"request": request})
|
||||||
|
|
||||||
|
# -----------------------------
|
||||||
|
# Pydantic model for JSON payloads
|
||||||
|
# -----------------------------
|
||||||
|
class FactionRequest(BaseModel):
|
||||||
|
faction_id: int
|
||||||
|
interval: int
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# API Endpoints
|
# API Endpoints
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
@app.post("/api/enemy")
|
@app.post("/api/update_enemy_faction")
|
||||||
async def api_enemy(faction_id: int, interval: int):
|
async def api_enemy(data: FactionRequest):
|
||||||
await update_enemy_faction(faction_id, interval)
|
await update_enemy_faction(data.faction_id, data.interval)
|
||||||
return {"status": "enemy loop running", "id": faction_id, "interval": 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):
|
# Discord bot setup
|
||||||
await update_friendly_faction(faction_id, interval)
|
# -----------------------------
|
||||||
return {"status": "friendly loop running", "id": faction_id, "interval": interval}
|
|
||||||
|
|
||||||
|
|
||||||
# Discord
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
|
|
||||||
|
|
||||||
enrolled_attackers = []
|
enrolled_attackers = []
|
||||||
enemy_queue = []
|
enemy_queue = []
|
||||||
active_assignments = {}
|
active_assignments = {}
|
||||||
@@ -92,6 +97,9 @@ TOKEN = "YOUR_DISCORD_TOKEN"
|
|||||||
async def start_bot():
|
async def start_bot():
|
||||||
await bot.start(TOKEN)
|
await bot.start(TOKEN)
|
||||||
|
|
||||||
|
# -----------------------------
|
||||||
|
# Main entry
|
||||||
|
# -----------------------------
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
|||||||
@@ -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"}
|
|
||||||
@@ -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 })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
<title>War Dashboard</title>
|
<title>War Dashboard</title>
|
||||||
<link rel="stylesheet" href="/static/styles.css">
|
<link rel="stylesheet" href="/static/styles.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div class="container">
|
||||||
<h1>War Dashboard</h1>
|
<h1>War Dashboard</h1>
|
||||||
|
|
||||||
<div>
|
<div class="faction-section">
|
||||||
<h2>Enemy Faction</h2>
|
<h2>Enemy Faction</h2>
|
||||||
|
<input type="number" id="enemyId" placeholder="Enemy Faction ID">
|
||||||
|
<input type="number" id="refreshInterval" placeholder="Refresh Interval (sec)">
|
||||||
<button onclick="updateEnemy()">Refresh Enemy</button>
|
<button onclick="updateEnemy()">Refresh Enemy</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="faction-section">
|
||||||
<h2>Friendly Faction</h2>
|
<h2>Friendly Faction</h2>
|
||||||
|
<input type="number" id="friendlyId" placeholder="Friendly Faction ID">
|
||||||
<button onclick="updateFriendly()">Refresh Friendly</button>
|
<button onclick="updateFriendly()">Refresh Friendly</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="/static/dashboard.js"></script>
|
<script src="/static/dashboard.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user