2021-04-14 09:21:20 +01:00
|
|
|
from quart import g, abort, render_template, jsonify, websocket
|
2021-04-12 20:31:39 +01:00
|
|
|
from http import HTTPStatus
|
|
|
|
|
|
|
|
from lnbits.decorators import check_user_exists, validate_uuids
|
|
|
|
|
|
|
|
from . import copilot_ext
|
|
|
|
from .crud import get_copilot
|
|
|
|
|
2021-04-14 23:45:28 +01:00
|
|
|
from quart import g, abort, render_template, jsonify, websocket
|
|
|
|
from functools import wraps
|
2021-04-16 12:20:05 +01:00
|
|
|
import trio
|
2021-04-14 23:45:28 +01:00
|
|
|
import shortuuid
|
|
|
|
from . import copilot_ext
|
|
|
|
|
|
|
|
connected_websockets = {}
|
|
|
|
|
2021-04-16 12:20:05 +01:00
|
|
|
|
|
|
|
@copilot_ext.websocket("/ws/panel/<copilot_id>")
|
2021-04-14 23:45:28 +01:00
|
|
|
async def ws_panel(copilot_id):
|
|
|
|
global connected_websockets
|
|
|
|
while True:
|
|
|
|
data = await websocket.receive()
|
2021-04-16 12:20:05 +01:00
|
|
|
connected_websockets[copilot_id] = shortuuid.uuid() + "-" + data
|
|
|
|
|
|
|
|
@copilot_ext.websocket("/ws/compose/<copilot_id>")
|
2021-04-14 23:45:28 +01:00
|
|
|
async def ws_compose(copilot_id):
|
|
|
|
global connected_websockets
|
2021-04-16 20:50:50 +01:00
|
|
|
print("poo")
|
2021-04-14 09:29:25 +01:00
|
|
|
while True:
|
2021-04-16 20:50:50 +01:00
|
|
|
print("poo")
|
2021-04-14 09:29:25 +01:00
|
|
|
data = await websocket.receive()
|
2021-04-14 23:45:28 +01:00
|
|
|
await websocket.send(connected_websockets[copilot_id])
|
2021-04-16 12:20:05 +01:00
|
|
|
|
|
|
|
|
2021-04-12 20:31:39 +01:00
|
|
|
@copilot_ext.route("/")
|
|
|
|
@validate_uuids(["usr"], required=True)
|
|
|
|
@check_user_exists()
|
|
|
|
async def index():
|
|
|
|
return await render_template("copilot/index.html", user=g.user)
|
|
|
|
|
|
|
|
|
2021-04-13 19:20:12 +01:00
|
|
|
@copilot_ext.route("/cp/<copilot_id>")
|
|
|
|
async def compose(copilot_id):
|
|
|
|
copilot = await get_copilot(copilot_id) or abort(
|
|
|
|
HTTPStatus.NOT_FOUND, "Copilot link does not exist."
|
|
|
|
)
|
2021-04-15 09:39:27 +01:00
|
|
|
if copilot.lnurl_toggle:
|
2021-04-16 12:20:05 +01:00
|
|
|
return await render_template(
|
|
|
|
"copilot/compose.html",
|
|
|
|
copilot=copilot,
|
|
|
|
lnurl=copilot.lnurl,
|
|
|
|
lnurl_toggle=copilot.lnurl_toggle,
|
|
|
|
)
|
|
|
|
return await render_template(
|
|
|
|
"copilot/compose.html", copilot=copilot, lnurl_toggle=copilot.lnurl_toggle
|
|
|
|
)
|
|
|
|
|
2021-04-13 19:20:12 +01:00
|
|
|
|
2021-04-12 20:31:39 +01:00
|
|
|
@copilot_ext.route("/<copilot_id>")
|
2021-04-13 19:20:12 +01:00
|
|
|
async def panel(copilot_id):
|
2021-04-12 20:31:39 +01:00
|
|
|
copilot = await get_copilot(copilot_id) or abort(
|
2021-04-13 19:20:12 +01:00
|
|
|
HTTPStatus.NOT_FOUND, "Copilot link does not exist."
|
2021-04-12 20:31:39 +01:00
|
|
|
)
|
2021-04-16 12:20:05 +01:00
|
|
|
return await render_template("copilot/panel.html", copilot=copilot)
|
2021-04-16 20:42:37 +01:00
|
|
|
|
|
|
|
|
2021-04-16 22:07:06 +01:00
|
|
|
@copilot_ext.route("/api/v1/copilot/hook/<copilot_id>/<amount>/", methods=["GET"])
|
2021-04-16 22:02:22 +01:00
|
|
|
async def api_copilot_hooker(copilot_id, amount):
|
2021-04-16 22:07:06 +01:00
|
|
|
print("amount")
|
2021-04-16 22:09:56 +01:00
|
|
|
data = ""
|
2021-04-16 20:42:37 +01:00
|
|
|
copilot = await get_copilot(copilot_id)
|
2021-04-16 20:59:56 +01:00
|
|
|
print("amount")
|
2021-04-16 20:42:37 +01:00
|
|
|
if not copilot:
|
|
|
|
return (
|
|
|
|
jsonify({"message": "Copilot link link does not exist."}),
|
|
|
|
HTTPStatus.NOT_FOUND,
|
|
|
|
)
|
2021-04-16 20:55:47 +01:00
|
|
|
print(amount)
|
2021-04-16 20:42:37 +01:00
|
|
|
if (
|
|
|
|
copilot.animation1threshold
|
|
|
|
and int(amount) > copilot.animation1threshold
|
|
|
|
):
|
|
|
|
data = copilot.animation1
|
|
|
|
if (
|
|
|
|
copilot.animation2threshold
|
|
|
|
and int(amount) > copilot.animation2threshold
|
|
|
|
):
|
|
|
|
data = copilot.animation2
|
|
|
|
if (
|
|
|
|
copilot.animation3threshold
|
|
|
|
and int(amount) > copilot.animation3threshold
|
|
|
|
):
|
|
|
|
data = copilot.animation3
|
2021-04-16 22:13:00 +01:00
|
|
|
global connected_websockets
|
|
|
|
connected_websockets[copilot_id] = copilot_id + "-" + data
|
|
|
|
|
2021-04-16 20:42:37 +01:00
|
|
|
return "", HTTPStatus.OK
|