From b553c9aa96a0485a06a355401d88c4e552106641 Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:27:09 +0100 Subject: [PATCH] add support for nip68 events --- ...ent_discovery_currently_popular_gallery.py | 46 ++++++------------- nostr_dvm/utils/definitions.py | 1 + nostr_dvm/utils/nip89_utils.py | 2 +- tests/discovery_gallery.py | 40 ++++++++-------- tests/test_dvm_client.py | 8 ++-- ui/noogle/src/components/NoteTable.vue | 3 +- .../components/RecommendationGeneration.vue | 22 ++++++++- ui/noogle/src/components/helper/string.ts | 2 + 8 files changed, 62 insertions(+), 62 deletions(-) diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py b/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py index 4cdf990..0241eec 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_gallery.py @@ -25,7 +25,7 @@ Params: None class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): - KIND: Kind = EventDefinitions.KIND_NIP90_VISUAL_DISCOVERY + KIND: Kind = EventDefinitions.KIND_NIP90_CONTENT_DISCOVERY TASK: str = "discover-visuals" FIX_COST: float = 0 dvm_config: DVMConfig @@ -33,7 +33,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): last_schedule: int db_since = 3600 db_name = "db/nostr_recent_gallery.db" - generic_db_name = "db/nostr_recent_notes.db" min_reactions = 2 personalized = False result = "" @@ -52,8 +51,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): if self.options.get("db_name"): self.db_name = self.options.get("db_name") - if self.options.get("generic_db_name"): - self.generic_db_name = self.options.get("generic_db_name") if self.options.get("db_since"): self.db_since = int(self.options.get("db_since")) @@ -117,33 +114,22 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): timestamp_since = Timestamp.now().as_secs() - self.db_since since = Timestamp.from_secs(timestamp_since) - filter1 = Filter().kind(definitions.EventDefinitions.KIND_NIP93_GALLERYENTRY).since(since) + filter1 = Filter().kind(definitions.EventDefinitions.KIND_NIP68_IMAGEEVENT).since(since) ge_events = await databasegallery.query([filter1]) + if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(ge_events.to_vec())) + " Events") ns.finallist = {} ids = [] relays = [] - if len(ge_events.to_vec()) == 0: return [] for ge_event in ge_events.to_vec(): - - id = None - for tag in ge_event.tags().to_vec(): - if tag.as_vec()[0] == "e": - id = EventId.from_hex(tag.as_vec()[1]) - ids.append(id) - # if len(tag.as_vec()) > 2: - # if (tag.as_vec()[2]) not in relays: - # relays.append(tag.as_vec()[2]) - - if id is None: - print("No event id found") - continue + ids.append(ge_event.id()) + relaylimits = RelayLimits.disable() opts = (Options().relay_limits(relaylimits)) @@ -169,8 +155,8 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): filter2 = Filter().ids(ids) events = await cli.fetch_events([filter2], relay_timeout) + - print(len(events.to_vec())) for event in events.to_vec(): if event.created_at().as_secs() > timestamp_since: @@ -184,32 +170,28 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since) reactions = await databasegallery.query([filt]) - + + #print("Reactions:" + str(len(reactions.to_vec()))) if len(reactions.to_vec()) >= self.min_reactions: - found = False for ge_event in ge_events.to_vec(): - for tag in ge_event.tags().to_vec(): - if tag.as_vec()[0] == "e": - if event.id().to_hex() == tag.as_vec()[1]: - ns.finallist[ge_event.id().to_hex()] = len(reactions.to_vec()) - found = True - break - if found: + if event.id().to_hex() == ge_event.id().to_hex(): + ns.finallist[ge_event.id().to_hex()] = len(reactions.to_vec()) break - + if len(ns.finallist) == 0: return self.result result_list = [] finallist_sorted = sorted(ns.finallist.items(), key=lambda x: x[1], reverse=True)[:int(options["max_results"])] for entry in finallist_sorted: - # print(EventId.parse(entry[0]).to_bech32() + "/" + EventId.parse(entry[0]).to_hex() + ": " + str(entry[1])) + #print(EventId.parse(entry[0]).to_bech32() + "/" + EventId.parse(entry[0]).to_hex() + ": " + str(entry[1])) e_tag = Tag.parse(["e", entry[0]]) result_list.append(e_tag.as_vec()) if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str( len(result_list)) + " fitting events.") # await cli.shutdown() + return json.dumps(result_list) async def post_process(self, result, event): @@ -251,7 +233,7 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface): timestamp_since = Timestamp.now().as_secs() - self.db_since since = Timestamp.from_secs(timestamp_since) - filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NIP93_GALLERYENTRY]).since( + filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NIP68_IMAGEEVENT]).since( since) # Notes, reactions, zaps # filter = Filter().author(keys.public_key()) diff --git a/nostr_dvm/utils/definitions.py b/nostr_dvm/utils/definitions.py index 388ba61..b79b7da 100644 --- a/nostr_dvm/utils/definitions.py +++ b/nostr_dvm/utils/definitions.py @@ -12,6 +12,7 @@ class EventDefinitions: KIND_DELETION = Kind(5) KIND_REPOST = Kind(6) KIND_REACTION = Kind(7) + KIND_NIP68_IMAGEEVENT = Kind(20) KIND_NIP94_METADATA = Kind(1063) KIND_NIP93_GALLERYENTRY = Kind(1163) KIND_NIP90_EXTRACT_TEXT = Kind(5000) diff --git a/nostr_dvm/utils/nip89_utils.py b/nostr_dvm/utils/nip89_utils.py index 329d077..082e38d 100644 --- a/nostr_dvm/utils/nip89_utils.py +++ b/nostr_dvm/utils/nip89_utils.py @@ -54,9 +54,9 @@ async def fetch_nip89_parameters_for_deletion(keys, eventid, client, dvmconfig, if event.author().to_hex() == keys.public_key().to_hex(): if pow: + print("Delete with POW, this might take a while, please wait until finished") await nip89_delete_announcement_pow(event.id().to_hex(), keys, d_tag, client, dvmconfig) else: - print("Delete with POW, this might take a while, please wait until finished") await nip89_delete_announcement(event.id().to_hex(), keys, d_tag, client, dvmconfig) print("NIP89 announcement deleted from known relays!") diff --git a/tests/discovery_gallery.py b/tests/discovery_gallery.py index ec71c22..3b007a8 100644 --- a/tests/discovery_gallery.py +++ b/tests/discovery_gallery.py @@ -9,26 +9,22 @@ from nostr_dvm.utils.admin_utils import AdminConfig from nostr_dvm.utils.dvmconfig import build_default_config from nostr_dvm.utils.nip89_utils import create_amount_tag, NIP89Config, check_and_set_d_tag -rebroadcast_NIP89 = False # Announce NIP89 on startup +rebroadcast_NIP89 = True # Announce NIP89 on startup rebroadcast_NIP65_Relay_List = False update_profile = False -global_update_rate = 1200 # set this high on first sync so db can fully sync before another process trys to. +global_update_rate = 500 # set this high on first sync so db can fully sync before another process trys to. use_logger = True if use_logger: - init_logger(LogLevel.INFO) + init_logger(LogLevel.ERROR) def build_example_gallery(name, identifier, admin_config, options, image, cost=0, update_rate=180, processing_msg=None, update_db=True): dvm_config = build_default_config(identifier) - dvm_config.USE_OWN_VENV = False - dvm_config.LOGLEVEL = LogLevel.INFO - # dvm_config.SHOWLOG = True dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every 10 minutes dvm_config.UPDATE_DATABASE = update_db - dvm_config.LOGLEVEL = LogLevel.DEBUG dvm_config.FIX_COST = cost dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg admin_config.LUD16 = dvm_config.LN_ADDRESS @@ -37,11 +33,12 @@ def build_example_gallery(name, identifier, admin_config, options, image, cost=0 nip89info = { "name": name, "picture": image, - "about": "I show popular gallery entries", + "image": image, + "about": "I show popular notes people put in their galleries", "lud16": dvm_config.LN_ADDRESS, "supportsEncryption": True, "acceptsNutZaps": dvm_config.ENABLE_NUTZAP, - "personalized": True, + "personalized": False, "amount": create_amount_tag(cost), "nip90Params": { "max_results": { @@ -61,29 +58,28 @@ def build_example_gallery(name, identifier, admin_config, options, image, cost=0 def playground(): # Popular Global - admin_config_global_wot = AdminConfig() - admin_config_global_wot.REBROADCAST_NIP89 = rebroadcast_NIP89 - admin_config_global_wot.REBROADCAST_NIP65_RELAY_LIST = rebroadcast_NIP65_Relay_List - admin_config_global_wot.UPDATE_PROFILE = update_profile - # admin_config_global_popular.DELETE_NIP89 = True - # admin_config_global_popular.PRIVKEY = "" - # admin_config_global_popular.EVENTID = "2fea4ee2ccf0fa11db171113ffd7a676f800f34121478b7c9a4e73c2f1990028" - # admin_config_global_popular.POW = True + admin_config_global_gallery = AdminConfig() + admin_config_global_gallery.REBROADCAST_NIP89 = rebroadcast_NIP89 + admin_config_global_gallery.REBROADCAST_NIP65_RELAY_LIST = rebroadcast_NIP65_Relay_List + admin_config_global_gallery.UPDATE_PROFILE = update_profile + admin_config_global_gallery.DELETE_NIP89 = False + admin_config_global_gallery.PRIVKEY = "" + admin_config_global_gallery.EVENTID = "" + admin_config_global_gallery.POW = False custom_processing_msg = ["Looking for popular Gallery entries"] update_db = True options_gallery = { "db_name": "db/nostr_gallery.db", - "generic_db_name": "db/nostr_recent_notes.db", - "db_since": 60 * 60 * 24 * 30, # 1h since gmt, + "db_since": 60 * 60 * 24 * 3, # 1h since gmt, } cost = 0 - image = "https://i.nostr.build/4Rw6lrsH5O0P5zjT.jpg" - discover_gallery = build_example_gallery("Gallery entries", + image = "https://image.nostr.build/f5901156825ef1d9dad557890020ce9c5d917f52bc31863226b980fa232a9c23.png" + discover_gallery = build_example_gallery("Popular Gallery Entries", "discovery_gallery_entries", - admin_config=admin_config_global_wot, + admin_config=admin_config_global_gallery, options=options_gallery, image=image, cost=cost, diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index 87f742a..fb077ca 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -343,7 +343,7 @@ async def nostr_client_test_discovery_gallery(user, ptag): tags = [relaysTag, alttag, paramTag, pTag] - event = EventBuilder(EventDefinitions.KIND_NIP90_VISUAL_DISCOVERY, str("Give me visuals")).tags( + event = EventBuilder(EventDefinitions.KIND_NIP90_CONTENT_DISCOVERY, str("Give me visuals")).tags( tags).sign_with_keys(keys) client = Client(NostrSigner.keys(keys)) @@ -352,7 +352,7 @@ async def nostr_client_test_discovery_gallery(user, ptag): await client.connect() config = DVMConfig eventid = await send_event(event, client=client, dvm_config=config) - print(eventid.to_hex()) + return event.as_json() @@ -421,7 +421,7 @@ async def nostr_client(): # await nostr_client_test_translation("44a0a8b395ade39d46b9d20038b3f0c8a11168e67c442e3ece95e4a1703e2beb", "event", "zh", 20, 20) #await nostr_client_test_image("a beautiful purple ostrich watching the sunset, eating a cashew nut") - await nostr_client_custom_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "7240284b84951cfedbc20fce26f0e3f0a36da3e9c1be85d7a06965f0d4fe25fb") + #await nostr_client_custom_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "7240284b84951cfedbc20fce26f0e3f0a36da3e9c1be85d7a06965f0d4fe25fb") #"a018ba05af400b52772e33162d8326fca4a167fe7b6d3cd2382e14cac2af6841" # await nostr_client_duckduck_test(PublicKey.parse("7a63849b684d90c0de983492578b12e147e56f5d79ed6585cc64e5aa8a122744").to_hex() , "How do i create a dockerfile for python 3.12") #await nostr_client_flux_schnell("d57f1efb7582f58cade6f482d53eefa998d8082711b996aae3dc5f5527cbdd6e" , "topics") @@ -429,7 +429,7 @@ async def nostr_client(): # await nostr_client_test_search_profile("dontbelieve") #wot = ["99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64"] #await nostr_client_test_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "ab6cdf12ca3ae5109416295b8cd8a53fdec3a9d54beb7a9aee0ebfb67cb4edf7") - # await nostr_client_test_discovery_gallery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "4add3944eb596a27a650f9b954f5ed8dfefeec6ca50473605b0fbb058dd11306") + await nostr_client_test_discovery_gallery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "4add3944eb596a27a650f9b954f5ed8dfefeec6ca50473605b0fbb058dd11306") #await nostr_client_test_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", # "7a63849b684d90c0de983492578b12e147e56f5d79ed6585cc64e5aa8a122744") diff --git a/ui/noogle/src/components/NoteTable.vue b/ui/noogle/src/components/NoteTable.vue index 847c131..f18bcae 100644 --- a/ui/noogle/src/components/NoteTable.vue +++ b/ui/noogle/src/components/NoteTable.vue @@ -14,7 +14,7 @@ -->