From b500a02f024328f02bf08160414d5b68709a851e Mon Sep 17 00:00:00 2001 From: Ben Arc Date: Fri, 16 Apr 2021 22:22:36 +0100 Subject: [PATCH] black --- lnbits/extensions/copilot/lnurl.py | 24 ++++++++++++++++++---- lnbits/extensions/copilot/views.py | 28 +++++++++++--------------- lnbits/extensions/copilot/views_api.py | 2 +- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py index e2655134..db19f5c8 100644 --- a/lnbits/extensions/copilot/lnurl.py +++ b/lnbits/extensions/copilot/lnurl.py @@ -67,8 +67,17 @@ async def lnurl_callback(cp_id): wallet_id=cp.wallet, amount=int(amount_received / 1000), memo=cp.lnurl_title, - webhook=url_for("copilot.api_copilot_hooker", copilot_id=cp_id, amount=int(amount_received / 1000), _external=True), - description_hash=hashlib.sha256((LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]]))).encode("utf-8")).digest(), + webhook=url_for( + "copilot.api_copilot_hooker", + copilot_id=cp_id, + amount=int(amount_received / 1000), + _external=True, + ), + description_hash=hashlib.sha256( + ( + LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])) + ).encode("utf-8") + ).digest(), extra={"tag": "copilot", "comment": comment}, ) resp = LnurlPayActionResponse( @@ -77,5 +86,12 @@ async def lnurl_callback(cp_id): disposable=False, routes=[], ) - print(url_for("copilot.api_copilot_hooker", copilot_id=cp_id, amount=int(amount_received / 1000), _external=True)) - return jsonify(resp.dict()) \ No newline at end of file + print( + url_for( + "copilot.api_copilot_hooker", + copilot_id=cp_id, + amount=int(amount_received / 1000), + _external=True, + ) + ) + return jsonify(resp.dict()) diff --git a/lnbits/extensions/copilot/views.py b/lnbits/extensions/copilot/views.py index b4378883..6b313ebe 100644 --- a/lnbits/extensions/copilot/views.py +++ b/lnbits/extensions/copilot/views.py @@ -22,12 +22,13 @@ async def ws_panel(copilot_id): data = await websocket.receive() connected_websockets[copilot_id] = shortuuid.uuid() + "-" + data + @copilot_ext.websocket("/ws/compose/") async def ws_compose(copilot_id): global connected_websockets - print("poo") + while True: - print("poo") + data = await websocket.receive() await websocket.send(connected_websockets[copilot_id]) @@ -66,25 +67,19 @@ async def panel(copilot_id): @copilot_ext.route("/api/v1/copilot/hook///", methods=["GET"]) async def api_copilot_hooker(copilot_id, amount): - print("amount") + data = "" copilot = await get_copilot(copilot_id) - print("amount") + if not copilot: return ( jsonify({"message": "Copilot link link does not exist."}), HTTPStatus.NOT_FOUND, ) - print(amount) - if ( - copilot.animation1threshold - and int(amount) > copilot.animation1threshold - ): + + if copilot.animation1threshold and int(amount) > copilot.animation1threshold: data = copilot.animation1 - if ( - copilot.animation2threshold - and int(amount) > copilot.animation2threshold - ): + if copilot.animation2threshold and int(amount) > copilot.animation2threshold: data = copilot.animation2 if ( copilot.animation3threshold @@ -92,6 +87,7 @@ async def api_copilot_hooker(copilot_id, amount): ): data = copilot.animation3 global connected_websockets - connected_websockets[copilot_id.id] = shortuuid.uuid() + "-" + data - - return "", HTTPStatus.OK \ No newline at end of file + print(connected_websockets) + connected_websockets[copilot.id] = shortuuid.uuid() + "-" + data + + return "", HTTPStatus.OK diff --git a/lnbits/extensions/copilot/views_api.py b/lnbits/extensions/copilot/views_api.py index ce3d40ca..4834f6d0 100644 --- a/lnbits/extensions/copilot/views_api.py +++ b/lnbits/extensions/copilot/views_api.py @@ -90,4 +90,4 @@ async def api_copilot_delete(copilot_id): await delete_copilot(copilot_id) - return "", HTTPStatus.NO_CONTENT \ No newline at end of file + return "", HTTPStatus.NO_CONTENT