From 1d6ee33aa4669b786bedb086451f690e54f9df58 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 1 Feb 2023 14:37:22 +0100 Subject: [PATCH] subscribe global --- main.py | 15 ++++++++++----- nostr/client/client.py | 8 +++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 4a17436..4b6b75f 100644 --- a/main.py +++ b/main.py @@ -53,11 +53,16 @@ async def post(): await asyncio.sleep(1) to_pubk_hex = ( - input("Enter other pubkey (enter nothing to read your own posts): ") + input( + "Enter other pubkey (enter nothing to read your own posts, enter * for all): " + ) or sender_client.public_key.hex() ) - print(f"Subscribing to posts by {to_pubk_hex}") - to_pubk = PublicKey(bytes.fromhex(to_pubk_hex)) + if to_pubk_hex == "*": + to_pubk = None + else: + print(f"Subscribing to posts by {to_pubk_hex}") + to_pubk = PublicKey(bytes.fromhex(to_pubk_hex)) t = threading.Thread( target=sender_client.get_post, @@ -74,7 +79,7 @@ async def post(): # write a DM and receive DMs -asyncio.run(dm()) +# asyncio.run(dm()) # make a post and subscribe to posts -# asyncio.run(post()) +asyncio.run(post()) diff --git a/nostr/client/client.py b/nostr/client/client.py index 11119ed..e27bc04 100644 --- a/nostr/client/client.py +++ b/nostr/client/client.py @@ -62,10 +62,12 @@ class NostrClient: # print(message) self.relay_manager.publish_message(message) - def get_post(self, sender_publickey: PublicKey, callback_func=None): - filters = Filters( - [Filter(authors=[sender_publickey.hex()], kinds=[EventKind.TEXT_NOTE])] + def get_post(self, sender_publickey: PublicKey = None, callback_func=None): + filter = Filter( + authors=[sender_publickey.hex()] if sender_publickey else None, + kinds=[EventKind.TEXT_NOTE], ) + filters = Filters([filter]) subscription_id = os.urandom(4).hex() self.relay_manager.add_subscription(subscription_id, filters)