more adjustments

This commit is contained in:
Believethehype
2024-06-07 23:45:26 +02:00
parent 8d1ab44b24
commit 8daaba0f7e
17 changed files with 269 additions and 224 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import json
import time
from datetime import timedelta
@@ -6,14 +7,14 @@ from threading import Thread
import dotenv
from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \
NostrSigner, Options
NostrSigner, Options, Event
from nostr_dvm.utils.dvmconfig import DVMConfig
from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key
from nostr_dvm.utils.definitions import EventDefinitions
def nostr_client_test(prompt):
async def nostr_client_test(prompt):
keys = Keys.parse(check_and_set_private_key("test_client"))
iTag = Tag.parse(["i", prompt, "text"])
@@ -32,13 +33,13 @@ def nostr_client_test(prompt):
signer = NostrSigner.keys(keys)
client = Client.with_opts(signer,opts)
for relay in relay_list:
client.add_relay(relay)
client.connect()
await client.add_relay(relay)
await client.connect()
config = DVMConfig
send_event(event, client=client, dvm_config=config)
await send_event(event, client=client, dvm_config=config)
return event.as_json()
def nostr_client():
async def nostr_client():
keys = Keys.parse(check_and_set_private_key("test_client"))
sk = keys.secret_key()
pk = keys.public_key()
@@ -48,28 +49,28 @@ def nostr_client():
dvmconfig = DVMConfig()
for relay in dvmconfig.RELAY_LIST:
client.add_relay(relay)
client.connect()
await client.add_relay(relay)
await client.connect()
dm_zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_DM,
EventDefinitions.KIND_ZAP]).since(
Timestamp.now()) # events to us specific
dvm_filter = (Filter().kinds([EventDefinitions.KIND_NIP90_RESULT_GENERATE_TEXT,
EventDefinitions.KIND_FEEDBACK]).since(Timestamp.now())) # public events
client.subscribe([dm_zap_filter, dvm_filter])
await client.subscribe([dm_zap_filter, dvm_filter])
#nostr_client_test("What has Pablo been up to?")
nostr_client_test("What is Gigi talking about recently?")
await nostr_client_test("What is Gigi talking about recently?")
print("Sending Job Request")
class NotificationHandler(HandleNotification):
def handle(self, relay_url, event):
def handle(self, relay_url, subscription_id, event: Event):
print(f"Received new event from {relay_url}: {event.as_json()}")
if event.kind() == 7000:
print("[Nostr Client]: " + event.as_json())
elif 6000 < event.kind() < 6999:
elif 6000 < event.kind().as_u64() < 6999:
print("[Nostr Client " + event.author().to_bech32() + "]: " + event.as_json())
print("[Nostr Client " + event.author().to_bech32() + "]: " + event.content())
@@ -85,9 +86,10 @@ def nostr_client():
def handle_msg(self, relay_url, msg):
return
client.handle_notifications(NotificationHandler())
asyncio.create_task(client.handle_notifications(NotificationHandler()))
while True:
time.sleep(1)
await asyncio.sleep(1)
if __name__ == '__main__':
@@ -99,5 +101,4 @@ if __name__ == '__main__':
else:
raise FileNotFoundError(f'.env file not found at {env_path} ')
nostr_dvm_thread = Thread(target=nostr_client())
nostr_dvm_thread.start()
asyncio.run(nostr_client())