Skip to content

Commit

Permalink
DVM: custom processing message Option
Browse files Browse the repository at this point in the history
  • Loading branch information
believethehype committed May 16, 2024
1 parent 85dac0f commit d7c0c91
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 13 deletions.
3 changes: 3 additions & 0 deletions nostr_dvm/dvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down
12 changes: 10 additions & 2 deletions nostr_dvm/tasks/content_discovery_currently_popular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -233,14 +237,18 @@ 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
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
# 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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -251,14 +254,15 @@ 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
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
# 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 = {
Expand Down
10 changes: 8 additions & 2 deletions nostr_dvm/tasks/content_discovery_currently_popular_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion nostr_dvm/tasks/discovery_trending_notes_nostrband.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions nostr_dvm/utils/dvmconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
21 changes: 16 additions & 5 deletions tests/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()


Expand All @@ -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()


Expand Down

0 comments on commit d7c0c91

Please sign in to comment.