black
This commit is contained in:
parent
f8745cadf0
commit
d083b29d79
6 changed files with 58 additions and 42 deletions
|
|
@ -80,7 +80,7 @@ async def create_copilot(
|
||||||
show_ack,
|
show_ack,
|
||||||
show_price,
|
show_price,
|
||||||
lnurl_title,
|
lnurl_title,
|
||||||
0
|
0,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return await get_copilot(copilot_id)
|
return await get_copilot(copilot_id)
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,10 @@ async def lnurl_response(cp_id):
|
||||||
return jsonify({"status": "ERROR", "reason": "Copilot not found."})
|
return jsonify({"status": "ERROR", "reason": "Copilot not found."})
|
||||||
|
|
||||||
resp = LnurlPayResponse(
|
resp = LnurlPayResponse(
|
||||||
callback=url_for(
|
callback=url_for("copilot.lnurl_callback", cp_id=cp_id, _external=True),
|
||||||
"copilot.lnurl_callback", cp_id=cp_id, _external=True
|
|
||||||
),
|
|
||||||
min_sendable=10000,
|
min_sendable=10000,
|
||||||
max_sendable=50000000,
|
max_sendable=50000000,
|
||||||
metadata=LnurlPayMetadata(json.dumps([["text/plain", cp.lnurl_title]]))
|
metadata=LnurlPayMetadata(json.dumps([["text/plain", cp.lnurl_title]])),
|
||||||
)
|
)
|
||||||
|
|
||||||
params = resp.dict()
|
params = resp.dict()
|
||||||
|
|
@ -69,18 +67,16 @@ async def lnurl_callback(cp_id):
|
||||||
amount=int(amount_received / 1000),
|
amount=int(amount_received / 1000),
|
||||||
memo=cp.lnurl_title,
|
memo=cp.lnurl_title,
|
||||||
webhook="/copilot/api/v1/copilot/hook/" + cp_id,
|
webhook="/copilot/api/v1/copilot/hook/" + cp_id,
|
||||||
description_hash=hashlib.sha256(
|
description_hash=hashlib.sha256((cp.lnurl_title).encode("utf-8")).digest(),
|
||||||
(cp.lnurl_title).encode("utf-8")
|
|
||||||
).digest(),
|
|
||||||
extra={"tag": "copilot", "comment": comment},
|
extra={"tag": "copilot", "comment": comment},
|
||||||
)
|
)
|
||||||
|
|
||||||
resp = LnurlPayActionResponse(
|
resp = LnurlPayActionResponse(
|
||||||
pr=payment_request,
|
pr=payment_request,
|
||||||
success_action=None,
|
success_action=jsonify({tag: "message", message: "Thank you!"}),
|
||||||
routes=[],
|
routes=[],
|
||||||
)
|
)
|
||||||
print(payment_request)
|
print(payment_request)
|
||||||
print(jsonify(resp.dict()))
|
print(resp)
|
||||||
|
|
||||||
return jsonify(resp.dict())
|
return jsonify(resp.dict())
|
||||||
|
|
@ -6,6 +6,7 @@ from lnurl import Lnurl, encode as lnurl_encode # type: ignore
|
||||||
from lnurl.types import LnurlPayMetadata # type: ignore
|
from lnurl.types import LnurlPayMetadata # type: ignore
|
||||||
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
|
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class Copilots(NamedTuple):
|
class Copilots(NamedTuple):
|
||||||
id: str
|
id: str
|
||||||
user: str
|
user: str
|
||||||
|
|
|
||||||
|
|
@ -14,20 +14,23 @@ from . import copilot_ext
|
||||||
|
|
||||||
connected_websockets = {}
|
connected_websockets = {}
|
||||||
|
|
||||||
@copilot_ext.websocket('/ws/panel/<copilot_id>')
|
|
||||||
|
@copilot_ext.websocket("/ws/panel/<copilot_id>")
|
||||||
async def ws_panel(copilot_id):
|
async def ws_panel(copilot_id):
|
||||||
global connected_websockets
|
global connected_websockets
|
||||||
while True:
|
while True:
|
||||||
data = await websocket.receive()
|
data = await websocket.receive()
|
||||||
connected_websockets[copilot_id] = shortuuid.uuid() + '-' + data
|
connected_websockets[copilot_id] = shortuuid.uuid() + "-" + data
|
||||||
|
|
||||||
@copilot_ext.websocket('/ws/compose/<copilot_id>')
|
|
||||||
|
@copilot_ext.websocket("/ws/compose/<copilot_id>")
|
||||||
async def ws_compose(copilot_id):
|
async def ws_compose(copilot_id):
|
||||||
global connected_websockets
|
global connected_websockets
|
||||||
while True:
|
while True:
|
||||||
data = await websocket.receive()
|
data = await websocket.receive()
|
||||||
await websocket.send(connected_websockets[copilot_id])
|
await websocket.send(connected_websockets[copilot_id])
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/")
|
@copilot_ext.route("/")
|
||||||
@validate_uuids(["usr"], required=True)
|
@validate_uuids(["usr"], required=True)
|
||||||
@check_user_exists()
|
@check_user_exists()
|
||||||
|
|
@ -41,8 +44,16 @@ async def compose(copilot_id):
|
||||||
HTTPStatus.NOT_FOUND, "Copilot link does not exist."
|
HTTPStatus.NOT_FOUND, "Copilot link does not exist."
|
||||||
)
|
)
|
||||||
if copilot.lnurl_toggle:
|
if copilot.lnurl_toggle:
|
||||||
return await render_template("copilot/compose.html", copilot=copilot, lnurl=copilot.lnurl, lnurl_toggle=copilot.lnurl_toggle)
|
return await render_template(
|
||||||
return await render_template("copilot/compose.html", copilot=copilot, lnurl_toggle=copilot.lnurl_toggle)
|
"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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/<copilot_id>")
|
@copilot_ext.route("/<copilot_id>")
|
||||||
async def panel(copilot_id):
|
async def panel(copilot_id):
|
||||||
|
|
|
||||||
|
|
@ -58,18 +58,14 @@ async def api_copilots_retrieve():
|
||||||
try:
|
try:
|
||||||
return (
|
return (
|
||||||
jsonify(
|
jsonify(
|
||||||
[
|
[{**copilot._asdict()} for copilot in await get_copilots(g.wallet.user)]
|
||||||
{
|
|
||||||
**copilot._asdict()
|
|
||||||
}
|
|
||||||
for copilot in await get_copilots(g.wallet.user)
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot/<copilot_id>", methods=["GET"])
|
@copilot_ext.route("/api/v1/copilot/<copilot_id>", methods=["GET"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_copilot_retrieve(copilot_id):
|
async def api_copilot_retrieve(copilot_id):
|
||||||
|
|
@ -79,11 +75,7 @@ async def api_copilot_retrieve(copilot_id):
|
||||||
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
return (
|
return (
|
||||||
jsonify(
|
jsonify({copilot._asdict()}),
|
||||||
{
|
|
||||||
copilot._asdict()
|
|
||||||
}
|
|
||||||
),
|
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -100,23 +92,39 @@ async def api_copilot_delete(copilot_id):
|
||||||
|
|
||||||
return "", HTTPStatus.NO_CONTENT
|
return "", HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
#############################PAYMENTHOOKER##########################
|
#############################PAYMENTHOOKER##########################
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot/hook/<copilot_id>", methods=["POST"])
|
@copilot_ext.route("/api/v1/copilot/hook/<copilot_id>", methods=["POST"])
|
||||||
async def api_copilot_hooker(copilot_id, trigger):
|
async def api_copilot_hooker(copilot_id, trigger):
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
|
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return jsonify({"message": "Copilot link link does not exist."}), HTTPStatus.NOT_FOUND
|
return (
|
||||||
|
jsonify({"message": "Copilot link link does not exist."}),
|
||||||
|
HTTPStatus.NOT_FOUND,
|
||||||
|
)
|
||||||
|
|
||||||
socket_sendererer = app.socket_sendererer()
|
socket_sendererer = app.socket_sendererer()
|
||||||
if copilot.animation1threshold and int(g.data['amount']) > copilot.animation1threshold:
|
if (
|
||||||
|
copilot.animation1threshold
|
||||||
|
and int(g.data["amount"]) > copilot.animation1threshold
|
||||||
|
):
|
||||||
data = copilot.animation1
|
data = copilot.animation1
|
||||||
if copilot.animation2threshold and int(g.data['amount']) > copilot.animation2threshold:
|
if (
|
||||||
|
copilot.animation2threshold
|
||||||
|
and int(g.data["amount"]) > copilot.animation2threshold
|
||||||
|
):
|
||||||
data = copilot.animation2
|
data = copilot.animation2
|
||||||
if copilot.animation3threshold and int(g.data['amount']) > copilot.animation3threshold:
|
if (
|
||||||
|
copilot.animation3threshold
|
||||||
|
and int(g.data["amount"]) > copilot.animation3threshold
|
||||||
|
):
|
||||||
data = copilot.animation3
|
data = copilot.animation3
|
||||||
async with socket_sendererer.websocket('/ws/compose/' + copilot_id) as the_websocket:
|
async with socket_sendererer.websocket(
|
||||||
|
"/ws/compose/" + copilot_id
|
||||||
|
) as the_websocket:
|
||||||
await the_websocket.send(data)
|
await the_websocket.send(data)
|
||||||
|
|
||||||
return "", HTTPStatus.OK
|
return "", HTTPStatus.OK
|
||||||
Loading…
Add table
Add a link
Reference in a new issue