proper functoin calls for faction data
This commit is contained in:
42
main.py
42
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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user