|
@ -1,6 +1,6 @@ |
|
|
import asyncio |
|
|
import asyncio |
|
|
from typing import AsyncGenerator |
|
|
from typing import AsyncGenerator |
|
|
from quart import Quart, render_template, websocket |
|
|
from quart import Quart, render_template, websocket, g |
|
|
import logging |
|
|
import logging |
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
logger = logging.getLogger(__name__) |
|
@ -8,6 +8,7 @@ logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
app = Quart(__name__) |
|
|
app = Quart(__name__) |
|
|
connections = set() |
|
|
connections = set() |
|
|
|
|
|
webui = None |
|
|
|
|
|
|
|
|
@app.route("/") |
|
|
@app.route("/") |
|
|
async def index(): |
|
|
async def index(): |
|
@ -17,6 +18,17 @@ async def index(): |
|
|
async def json(): |
|
|
async def json(): |
|
|
return {"hello": "world"} |
|
|
return {"hello": "world"} |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/bots") |
|
|
|
|
|
async def bots(): |
|
|
|
|
|
return await render_template("bots.html", bots=webui.bots) |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/bot/<int:bot_id>") |
|
|
|
|
|
async def bot(bot_id): |
|
|
|
|
|
return await render_template("bot.html", bot=webui.bots[bot_id], bot_id=bot_id) |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/bot/<int:bot_id>/room/<room_id>") |
|
|
|
|
|
async def room(bot_id, room_id): |
|
|
|
|
|
return await render_template("room.html", room=webui.bots[bot_id].rooms[room_id], room_id=room_id) |
|
|
|
|
|
|
|
|
async def _send() -> None: |
|
|
async def _send() -> None: |
|
|
connection = asyncio.Queue() |
|
|
connection = asyncio.Queue() |
|
@ -51,8 +63,10 @@ class WebUI(object): |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
self.shutdown_event = asyncio.Event() |
|
|
self.shutdown_event = asyncio.Event() |
|
|
self.task = None |
|
|
self.task = None |
|
|
|
|
|
self.bots = [] |
|
|
app.config["PROPAGATE_EXCEPTIONS"] = True |
|
|
app.config["PROPAGATE_EXCEPTIONS"] = True |
|
|
pass |
|
|
global webui |
|
|
|
|
|
webui = self |
|
|
|
|
|
|
|
|
def run_task(self): |
|
|
def run_task(self): |
|
|
return app.run_task(port=5000, debug=True, shutdown_trigger=self.shutdown_event.wait) |
|
|
return app.run_task(port=5000, debug=True, shutdown_trigger=self.shutdown_event.wait) |
|
@ -61,4 +75,6 @@ class WebUI(object): |
|
|
self.shutdown_event.set() |
|
|
self.shutdown_event.set() |
|
|
self.task.cancel() # or close? |
|
|
self.task.cancel() # or close? |
|
|
|
|
|
|
|
|
|
|
|
async def connect(self, bots): |
|
|
|
|
|
self.bots = bots |
|
|
|
|
|
|
|
|