From d7c0c918a59802885870f61a15b0de1f2ed9d363 Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Thu, 16 May 2024 11:51:27 +0200 Subject: [PATCH] DVM: custom processing message Option --- nostr_dvm/dvm.py | 3 +++ .../content_discovery_currently_popular.py | 12 +++++++++-- ...t_discovery_currently_popular_followers.py | 8 +++++-- ...ntent_discovery_currently_popular_topic.py | 10 +++++++-- .../discovery_trending_notes_nostrband.py | 3 ++- nostr_dvm/utils/dvmconfig.py | 1 + setup.py | 2 +- tests/discovery.py | 21 ++++++++++++++----- 8 files changed, 47 insertions(+), 13 deletions(-) diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index 405a626..2649439 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -191,6 +191,7 @@ def handle_nip90_job_event(nip90_event): if dvm_config.SEND_FEEDBACK_EVENTS: send_job_status_reaction(nip90_event, "processing", True, 0, + content=dvm_config.CUSTOM_PROCESSING_MESSAGE, client=self.client, dvm_config=self.dvm_config, user=user) # when we reimburse users on error make sure to not send anything if it was free @@ -218,6 +219,7 @@ def handle_nip90_job_event(nip90_event): ". Starting processing.. Balance remains at: " + str(user.balance)) send_job_status_reaction(nip90_event, "processing", True, 0, + content=dvm_config.CUSTOM_PROCESSING_MESSAGE, client=self.client, dvm_config=self.dvm_config) do_work(nip90_event, amount) @@ -310,6 +312,7 @@ def handle_zap(zap_event): if amount <= invoice_amount: print("[" + self.dvm_config.NIP89.NAME + "] Payment-request fulfilled...") send_job_status_reaction(job_event, "processing", client=self.client, + content=dvm_config.CUSTOM_PROCESSING_MESSAGE, dvm_config=self.dvm_config, user=user) indices = [i for i, x in enumerate(self.job_list) if x.event == job_event] diff --git a/nostr_dvm/tasks/content_discovery_currently_popular.py b/nostr_dvm/tasks/content_discovery_currently_popular.py index 5ed264d..9e55dfc 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular.py @@ -193,7 +193,7 @@ def sync_db(self): # We build an example here that we can call by either calling this file directly from the main directory, # or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the # playground or elsewhere -def build_example(name, identifier, admin_config): +def build_example(name, identifier, admin_config, processing_msg=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -202,6 +202,10 @@ def build_example(name, identifier, admin_config): # dvm_config.SUBSCRIPTION_REQUIRED = True # dvm_config.SUBSCRIPTION_DAILY_COST = 1 dvm_config.FIX_COST = 0 + dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg + admin_config.LUD16 = dvm_config.LN_ADDRESS + + # Add NIP89 nip89info = { @@ -233,7 +237,7 @@ def build_example(name, identifier, admin_config): admin_config=admin_config) -def build_example_subscription(name, identifier, admin_config): +def build_example_subscription(name, identifier, admin_config, processing_msg=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -241,6 +245,10 @@ def build_example_subscription(name, identifier, admin_config): # Activate these to use a subscription based model instead # dvm_config.SUBSCRIPTION_DAILY_COST = 1 dvm_config.FIX_COST = 0 + dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg + admin_config.LUD16 = dvm_config.LN_ADDRESS + + # Add NIP89 nip89info = { diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_followers.py b/nostr_dvm/tasks/content_discovery_currently_popular_followers.py index ba32163..3d8b605 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_followers.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_followers.py @@ -211,7 +211,7 @@ def sync_db(self): # We build an example here that we can call by either calling this file directly from the main directory, # or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the # playground or elsewhere -def build_example(name, identifier, admin_config): +def build_example(name, identifier, admin_config, processing_msg=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -220,6 +220,9 @@ def build_example(name, identifier, admin_config): # dvm_config.SUBSCRIPTION_REQUIRED = True # dvm_config.SUBSCRIPTION_DAILY_COST = 1 dvm_config.FIX_COST = 0 + dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg + admin_config.LUD16 = dvm_config.LN_ADDRESS + # Add NIP89 nip89info = { @@ -251,7 +254,7 @@ def build_example(name, identifier, admin_config): admin_config=admin_config) -def build_example_subscription(name, identifier, admin_config): +def build_example_subscription(name, identifier, admin_config, processing_msg=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -259,6 +262,7 @@ def build_example_subscription(name, identifier, admin_config): # Activate these to use a subscription based model instead # dvm_config.SUBSCRIPTION_DAILY_COST = 1 dvm_config.FIX_COST = 0 + dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg # Add NIP89 nip89info = { diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py index 719e174..c1160f8 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py @@ -218,7 +218,7 @@ def sync_db(self): # We build an example here that we can call by either calling this file directly from the main directory, # or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the # playground or elsewhere -def build_example(name, identifier, admin_config, options, image, description): +def build_example(name, identifier, admin_config, options, image, description, processing_msg=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -227,6 +227,9 @@ def build_example(name, identifier, admin_config, options, image, description): # dvm_config.SUBSCRIPTION_REQUIRED = True # dvm_config.SUBSCRIPTION_DAILY_COST = 1 dvm_config.FIX_COST = 0 + dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg + admin_config.LUD16 = dvm_config.LN_ADDRESS + # Add NIP89 nip89info = { @@ -255,13 +258,16 @@ def build_example(name, identifier, admin_config, options, image, description): admin_config=admin_config, options=options) -def build_example_subscription(name, identifier, admin_config, options, image, description): +def build_example_subscription(name, identifier, admin_config, options, image, description, processing_msg=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes # Activate these to use a subscription based model instead dvm_config.FIX_COST = 0 + dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg + admin_config.LUD16 = dvm_config.LN_ADDRESS + # Add NIP89 nip89info = { diff --git a/nostr_dvm/tasks/discovery_trending_notes_nostrband.py b/nostr_dvm/tasks/discovery_trending_notes_nostrband.py index 794de8b..60feb8c 100644 --- a/nostr_dvm/tasks/discovery_trending_notes_nostrband.py +++ b/nostr_dvm/tasks/discovery_trending_notes_nostrband.py @@ -97,9 +97,10 @@ def post_process(self, result, event): # We build an example here that we can call by either calling this file directly from the main directory, # or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the # playground or elsewhere -def build_example(name, identifier, admin_config): +def build_example(name, identifier, admin_config, custom_processing_msg): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False + dvm_config.CUSTOM_PROCESSING_MESSAGE = custom_processing_msg admin_config.LUD16 = dvm_config.LN_ADDRESS # Add NIP89 diff --git a/nostr_dvm/utils/dvmconfig.py b/nostr_dvm/utils/dvmconfig.py index f926225..76a347f 100644 --- a/nostr_dvm/utils/dvmconfig.py +++ b/nostr_dvm/utils/dvmconfig.py @@ -38,6 +38,7 @@ class DVMConfig: SEND_FEEDBACK_EVENTS = True SHOW_RESULT_BEFORE_PAYMENT: bool = False # if this is true show results even when not paid right after autoprocess SCHEDULE_UPDATES_SECONDS = 0 + CUSTOM_PROCESSING_MESSAGE = None def build_default_config(identifier): diff --git a/setup.py b/setup.py index 668505b..328624d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.3.7' +VERSION = '0.3.8' DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines' LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information') diff --git a/tests/discovery.py b/tests/discovery.py index 3581fc7..1ebfa50 100644 --- a/tests/discovery.py +++ b/tests/discovery.py @@ -51,10 +51,11 @@ def playground(): image = "https://image.nostr.build/a816f3f5e98e91e8a47d50f4cd7a2c17545f556d9bb0a6086a659b9abdf7ab68.jpg" description = "I show recent notes about plants and gardening" + custom_processing_msg = "Finding the best notes for you. #blooming" discovery_test_sub = content_discovery_currently_popular_topic.build_example("Garden & Growth", "discovery_content_garden", admin_config_plants, options_plants, image, - description) + description, custom_processing_msg) discovery_test_sub.run() # Popular Animals (Fluffy frens) @@ -83,29 +84,38 @@ def playground(): image = "https://image.nostr.build/f609311532c470f663e129510a76c9a1912ae9bc4aaaf058e5ba21cfb512c88e.jpg" description = "I show recent notes about animals" + + custom_processing_msg = "Looking for fluffy frens..." + discovery_animals = content_discovery_currently_popular_topic.build_example("Fluffy Frens", "discovery_content_fluffy", admin_config_animals, options_animal, image, - description) + description, custom_processing_msg) discovery_animals.run() # Popular Followers admin_config_followers = AdminConfig() admin_config_followers.REBROADCAST_NIP89 = False admin_config_followers.UPDATE_PROFILE = False + custom_processing_msg = "Looking for popular notes from your followers.." + discovery_followers = content_discovery_currently_popular_followers.build_example("Currently Popular Notes from npubs you follow", "discovery_content_followers", - admin_config_followers) + admin_config_followers, + custom_processing_msg) discovery_followers.run() #Popular Global admin_config_global_popular = AdminConfig() admin_config_global_popular.REBROADCAST_NIP89 = False admin_config_global_popular.UPDATE_PROFILE = False + custom_processing_msg = "Looking for popular notes on the Nostr.." + discovery_global = content_discovery_currently_popular.build_example("Currently Popular Notes DVM", "discovery_content_test", - admin_config_global_popular) + admin_config_global_popular, + custom_processing_msg) discovery_global.run() @@ -115,8 +125,9 @@ def playground(): #Popular NOSTR.band admin_config_trending_nostr_band = AdminConfig() + custom_processing_msg = "Looking for trending notes on nostr.band.." trending_nb = discovery_trending_notes_nostrband.build_example("Trending Notes on nostr.band", - "trending_notes_nostrband", admin_config_trending_nostr_band) + "trending_notes_nostrband", admin_config_trending_nostr_band, custom_processing_msg) trending_nb.run()