From 17d2bfca3cc9fde084e4184020ae897fe0f095e6 Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Sun, 21 Apr 2024 11:03:52 +0200 Subject: [PATCH] add test functions, minor fix --- nostr_dvm/bot.py | 6 ++--- tests/{censor.py => filter.py} | 7 ++++-- tests/test_dvm_client.py | 40 ++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 9 deletions(-) rename tests/{censor.py => filter.py} (82%) diff --git a/nostr_dvm/bot.py b/nostr_dvm/bot.py index 0e870f7..89dcc0f 100644 --- a/nostr_dvm/bot.py +++ b/nostr_dvm/bot.py @@ -156,7 +156,7 @@ class Bot: else: # Parse inputs to params - tags = build_params(decrypted_text, nostr_event, index) + tags = build_params(decrypted_text, sender, index) p_tag = Tag.parse(['p', self.dvm_config.SUPPORTED_DVMS[index].PUBLIC_KEY]) if self.dvm_config.SUPPORTED_DVMS[index].SUPPORTS_ENCRYPTION: @@ -534,7 +534,7 @@ class Bot: info, None).to_event(self.keys) send_event(evt, client=self.client, dvm_config=dvm_config) - def build_params(decrypted_text, nostr_event, index): + def build_params(decrypted_text, author, index): tags = [] splitzero = decrypted_text.split(' -') split = splitzero[0].split(' ') @@ -542,7 +542,7 @@ class Bot: if len(split) == 1: remaining_text = decrypted_text.replace(split[0], "") params = remaining_text.split(" -") - tag = Tag.parse(["param", "user", nostr_event.author().to_hex()]) + tag = Tag.parse(["param", "user", author]) tags.append(tag) for i in params: print(i) diff --git a/tests/censor.py b/tests/filter.py similarity index 82% rename from tests/censor.py rename to tests/filter.py index 7f7c18e..97ed15e 100644 --- a/tests/censor.py +++ b/tests/filter.py @@ -6,7 +6,7 @@ import dotenv from nostr_sdk import Keys from nostr_dvm.subscription import Subscription -from nostr_dvm.tasks import content_discovery_currently_popular, discovery_censor_wot +from nostr_dvm.tasks import content_discovery_currently_popular, discovery_censor_wot, discovery_inactive_follows from nostr_dvm.utils.admin_utils import AdminConfig from nostr_dvm.utils.backend_utils import keep_alive from nostr_dvm.utils.dvmconfig import DVMConfig @@ -24,7 +24,10 @@ def playground(): admin_config.REBROADCAST_NIP89 = False admin_config.UPDATE_PROFILE = False - discovery_test_sub = discovery_censor_wot.build_example("Censorship", "discovery_censor", admin_config) + #discovery_test_sub = discovery_censor_wot.build_example("Censorship", "discovery_censor", admin_config) + #discovery_test_sub.run() + + discovery_test_sub = discovery_inactive_follows.build_example("Inactive Followings", "discovery_inactive", admin_config) discovery_test_sub.run() diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index 7f7eaa7..4c64f65 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -5,7 +5,7 @@ from threading import Thread import dotenv from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \ - nip04_encrypt, NostrSigner, PublicKey, Event + nip04_encrypt, NostrSigner, PublicKey, Event, Kind from nostr_dvm.utils.dvmconfig import DVMConfig from nostr_dvm.utils.nostr_utils import send_event, check_and_set_private_key @@ -122,6 +122,32 @@ def nostr_client_test_censor_filter(users): return event.as_json() +def nostr_client_test_inactive_filter(user): + keys = Keys.parse(check_and_set_private_key("test_client")) + + relay_list = ["wss://relay.damus.io", "wss://blastr.f7z.xyz", "wss://relayable.org", + ] + + relaysTag = Tag.parse(relay_list) + alttag = Tag.parse(["alt", "This is a NIP90 DVM AI task to find people that are inactive"]) + paramTag = Tag.parse(["param", "user", user]) + paramTag2 = Tag.parse(["param", "since_days", "120"]) + + tags = [relaysTag, alttag, paramTag, paramTag2] + + + event = EventBuilder(EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY, str("Give me inactive users"), + tags).to_event(keys) + + signer = NostrSigner.keys(keys) + client = Client(signer) + for relay in relay_list: + client.add_relay(relay) + client.connect() + config = DVMConfig + send_event(event, client=client, dvm_config=config) + return event.as_json() + def nostr_client_test_tts(prompt): keys = Keys.parse(check_and_set_private_key("test_client")) @@ -201,8 +227,13 @@ def nostr_client(): 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_TRANSLATE_TEXT, - EventDefinitions.KIND_FEEDBACK]).since(Timestamp.now())) # public events + kinds = [EventDefinitions.KIND_NIP90_GENERIC] + SUPPORTED_KINDS = [Kind(6301)] + + for kind in SUPPORTED_KINDS: + if kind not in kinds: + kinds.append(kind) + dvm_filter = (Filter().kinds(kinds).since(Timestamp.now())) client.subscribe([dm_zap_filter, dvm_filter], None) # nostr_client_test_translation("This is the result of the DVM in spanish", "text", "es", 20, 20) @@ -211,7 +242,8 @@ def nostr_client(): # nostr_client_test_image("a beautiful purple ostrich watching the sunset") # nostr_client_test_search_profile("dontbelieve") wot = ["99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64"] - nostr_client_test_censor_filter(wot) + #nostr_client_test_censor_filter(wot) + nostr_client_test_inactive_filter("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64") # nostr_client_test_tts("Hello, this is a test. Mic check one, two.")