skeleton webpage
This commit is contained in:
60
main.py
60
main.py
@@ -4,10 +4,54 @@ from config import ALLOWED_CHANNEL_ID, HIT_CHECK_INTERVAL, REASSIGN_DELAY
|
||||
from cogs.assignments import Assignments
|
||||
from cogs.commands import HitCommands
|
||||
|
||||
import asyncio
|
||||
import uvicorn
|
||||
|
||||
from fastapi import FastAPI, Request, Form
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from services.torn_api import update_enemy_faction, update_friendly_faction
|
||||
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Dashboard page
|
||||
# -----------------------------
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def dashboard(request: Request):
|
||||
print(">>> DASHBOARD ROUTE LOADED")
|
||||
return templates.TemplateResponse("dashboard.html", {"request": request})
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# 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/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
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
# Global state
|
||||
|
||||
enrolled_attackers = []
|
||||
enemy_queue = []
|
||||
active_assignments = {}
|
||||
@@ -43,4 +87,16 @@ bot = HitDispatchBot(command_prefix="!", intents=intents)
|
||||
async def on_ready():
|
||||
print(f"Logged in as {bot.user.name}")
|
||||
|
||||
bot.run("MTQ0Mjg3NjU3NTUzMDg3NzAxMQ.GNuHPr.UreuYD1B7YYjfsbfRcEbhFyjyqvhQDepRCN4kk")
|
||||
TOKEN = "YOUR_DISCORD_TOKEN"
|
||||
|
||||
async def start_bot():
|
||||
await bot.start(TOKEN)
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
# Start Discord bot in background
|
||||
loop.create_task(start_bot())
|
||||
|
||||
# Run FastAPI (this will keep the loop alive)
|
||||
uvicorn.run(app, host="127.0.0.1", port=8000)
|
||||
|
||||
Reference in New Issue
Block a user