Browse Source

webui

master
Hendrik Langer 1 year ago
parent
commit
24dc3060f6
  1. 20
      matrix_pygmalion_bot/connections/webui.py
  2. 1
      matrix_pygmalion_bot/main.py

20
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/<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:
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

1
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):

Loading…
Cancel
Save