From 24dc3060f640cf8a929afb31f0cf7e770c9cc356 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 30 Jun 2023 14:38:03 +0200 Subject: [PATCH] webui --- matrix_pygmalion_bot/connections/webui.py | 20 ++++++++++++++++++-- matrix_pygmalion_bot/main.py | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/matrix_pygmalion_bot/connections/webui.py b/matrix_pygmalion_bot/connections/webui.py index b7f6af9..2c3e653 100644 --- a/matrix_pygmalion_bot/connections/webui.py +++ b/matrix_pygmalion_bot/connections/webui.py @@ -1,6 +1,6 @@ import asyncio from typing import AsyncGenerator -from quart import Quart, render_template, websocket +from quart import Quart, render_template, websocket, g import logging logger = logging.getLogger(__name__) @@ -8,6 +8,7 @@ logger = logging.getLogger(__name__) app = Quart(__name__) connections = set() +webui = None @app.route("/") async def index(): @@ -17,6 +18,17 @@ async def index(): async def json(): return {"hello": "world"} +@app.route("/bots") +async def bots(): + return await render_template("bots.html", bots=webui.bots) + +@app.route("/bot/") +async def bot(bot_id): + return await render_template("bot.html", bot=webui.bots[bot_id], bot_id=bot_id) + +@app.route("/bot//room/") +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: connection = asyncio.Queue() @@ -51,8 +63,10 @@ class WebUI(object): def __init__(self): self.shutdown_event = asyncio.Event() self.task = None + self.bots = [] app.config["PROPAGATE_EXCEPTIONS"] = True - pass + global webui + webui = self def run_task(self): 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.task.cancel() # or close? + async def connect(self, bots): + self.bots = bots diff --git a/matrix_pygmalion_bot/main.py b/matrix_pygmalion_bot/main.py index fc897cd..7114b7e 100644 --- a/matrix_pygmalion_bot/main.py +++ b/matrix_pygmalion_bot/main.py @@ -68,6 +68,7 @@ async def main() -> None: bots.append(bot) webui = WebUI() + await webui.connect(bots) async def shutdown(signal, loop):