Prepare for other events

This commit is contained in:
koalasat 2024-07-01 18:43:35 +02:00 committed by koalasat
parent 3e460bb255
commit 97bb2dc777
No known key found for this signature in database
GPG Key ID: 2F7F61C6146AB157
2 changed files with 10 additions and 10 deletions

View File

@ -1,6 +1,5 @@
import time
import pygeohash
from nostr_sdk import Keys, Client, EventBuilder, NostrSigner, Filter
from nostr_sdk import Keys, Client, EventBuilder, NostrSigner
from api.models import Order
from decouple import config
@ -19,9 +18,8 @@ class Nostr:
await client.add_relays(["ws://localhost:888"])
await client.connect()
event = EventBuilder(38383, "", generate_tags(order)).to_event(keys)
event = EventBuilder(38383, "", self.generate_tags(order)).to_event(keys)
output = await client.send_event(event)
print(f"Nostr event sent: {output}")
def generate_tags(self, order):
@ -35,13 +33,15 @@ class Nostr:
["fa", order.amount],
["pm", order.payment_method.split(" ")],
["premium", order.premium_percentile],
["source", f"{config("HOST_NAME")}/{config("COORDINATOR_ALIAS")}/order/{order.id}"],
[
"source",
f"{config("HOST_NAME")}/{config("COORDINATOR_ALIAS")}/order/{order.id}",
],
["expiration", order.expires_at.timestamp()],
["y", "robosats"],
["coordinator", config("COORDINATOR_ALIAS", cast=str)]
["z", "order"],
["coordinator", config("COORDINATOR_ALIAS", cast=str)]["z", "order"],
["n", order.network],
["layer", "lightning"],
["g", pygeohash.encode(order.latitude, order.longitude)],
["bond", order.bond]
["bond", order.bond],
]

View File

@ -263,13 +263,13 @@ def send_order_nostr_event(order_id=None, message=None):
nostr = Nostr()
if message == "new":
coroutine = nostr.send_new_order_event(order)
if coroutine:
loop = asyncio.get_event_loop()
loop.run_until_complete(coroutine)
return
@shared_task(name="send_notification", ignore_result=True, time_limit=120)
def send_notification(order_id=None, chat_message_id=None, message=None):
if order_id: