From f5c98d2c12399829fdebd35232208c5c75220572 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Thu, 23 Nov 2023 12:32:44 +0100 Subject: [PATCH] adjustments for updating nostr sdk to 0.0.5 (but some delays appear) --- main.py | 2 +- requirements.txt | 2 +- utils/database_utils.py | 3 ++- utils/nostr_utils.py | 10 +++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index d01efd1..dc999a3 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ from utils.dvmconfig import DVMConfig def run_nostr_dvm_with_local_config(): # We extract the Publickey from our bot, so the DVMs know who they should listen and react to. - bot_publickey = Keys.from_sk_str(os.getenv("BOT_PRIVATE_KEY")).public_key().to_hex() + bot_publickey = Keys.from_sk_str(os.getenv("BOT_PRIVATE_KEY")).public_key() # Spawn some DVMs in the playground and run them # You can add arbitrary DVMs there and instantiate them here diff --git a/requirements.txt b/requirements.txt index a1df8ea..82a7a88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ ffmpegio-core==0.8.5 idna==3.4 inquirer==3.1.3 install==1.3.5 -nostr-sdk==0.0.4 +nostr-sdk==0.0.5 numpy==1.26.2 packaging==23.2 pandas==2.1.3 diff --git a/utils/database_utils.py b/utils/database_utils.py index 01f7c68..ebbc58d 100644 --- a/utils/database_utils.py +++ b/utils/database_utils.py @@ -212,7 +212,8 @@ def fetch_user_metadata(sender, client) -> (str, str, str): nip05 = "" lud16 = "" try: - profile_filter = Filter().kind(0).author(sender).limit(1) + pk = PublicKey.from_hex(sender) + profile_filter = Filter().kind(0).author(pk).limit(1) events = client.get_events_of([profile_filter], timedelta(seconds=3)) if len(events) > 0: ev = events[0] diff --git a/utils/nostr_utils.py b/utils/nostr_utils.py index adf5e2a..b30ee6e 100644 --- a/utils/nostr_utils.py +++ b/utils/nostr_utils.py @@ -1,15 +1,19 @@ from datetime import timedelta -from nostr_sdk import Keys, Filter, Client, Alphabet, EventId, Options, Event +from nostr_sdk import Keys, Filter, Client, Alphabet, EventId, Options, Event, PublicKey def get_event_by_id(event_id: str, client: Client, config=None) -> Event | None: split = event_id.split(":") if len(split) == 3: - id_filter = Filter().author(split[1]).custom_tag(Alphabet.D, [split[2]]) + pk = PublicKey.from_hex(split[1]) + id_filter = Filter().author(pk).custom_tag(Alphabet.D, [split[2]]) events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) else: if str(event_id).startswith('note'): - event_id = EventId.from_bech32(event_id).to_hex() + event_id = EventId.from_bech32(event_id) + else: + event_id = EventId.from_hex(event_id) + id_filter = Filter().id(event_id).limit(1) events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT)) if len(events) > 0: