From 131cbea6f3f040699af6030dee9b2828ec87406d Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:25:51 +0200 Subject: [PATCH] print npub --- nostr_dvm/dvm.py | 10 +-- ...iscovery_currently_popular_nonfollowers.py | 13 ++- ...ntent_discovery_currently_popular_topic.py | 11 ++- .../tasks/content_discovery_update_db_only.py | 8 +- nostr_dvm/utils/dvmconfig.py | 30 +++++-- nostr_dvm/utils/nostr_utils.py | 15 ++-- setup.py | 2 +- tests/discovery.py | 90 +++++++++++-------- tests/test_dvm_client.py | 34 ++++++- 9 files changed, 142 insertions(+), 71 deletions(-) diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index bef4c29..7ce48a5 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -139,7 +139,7 @@ class DVM: return if self.dvm_config.LOGLEVEL.value >= LogLevel.INFO.value: print( - bcolors.MAGENTA + "[" + self.dvm_config.NIP89.NAME + "] Received new Request: " + task + " from " + user.name + bcolors.ENDC) + bcolors.MAGENTA + "[" + self.dvm_config.NIP89.NAME + "] Received new Request: " + task + " from " + user.name + " (" + user.npub + ")" + bcolors.ENDC) duration = await input_data_file_duration(nip90_event, dvm_config=self.dvm_config, client=self.client) amount = get_amount_per_task(task, self.dvm_config, duration) if amount is None: @@ -347,7 +347,7 @@ class DVM: config=self.dvm_config) if job_event is not None and task_supported: print("NutZap received for NIP90 task: " + str(received_amount) + " Sats from " + str( - user.name)) + user.name + " (" + user.npub + ")" )) if amount <= received_amount: print("[" + self.dvm_config.NIP89.NAME + "] Payment-request fulfilled...") await send_job_status_reaction(job_event, "processing", client=self.client, @@ -436,7 +436,7 @@ class DVM: config=self.dvm_config) if job_event is not None and task_supported: print("Zap received for NIP90 task: " + str(invoice_amount) + " Sats from " + str( - user.name)) + user.name + " (" + user.npub + ")" )) if amount <= invoice_amount: print("[" + self.dvm_config.NIP89.NAME + "] Payment-request fulfilled...") await send_job_status_reaction(job_event, "processing", client=self.client, @@ -473,14 +473,14 @@ class DVM: "Someone zapped the result of an exisiting Task. Nice") elif not anon: print("[" + self.dvm_config.NIP89.NAME + "] Note Zap received for DVM balance: " + - str(invoice_amount) + " Sats from " + str(user.name)) + str(invoice_amount) + " Sats from " + str(user.name + " (" + user.npub + ")" )) # update_user_balance(self.dvm_config.DB, sender, invoice_amount, client=self.client, # config=self.dvm_config) # a regular note elif not anon and dvm_config.NIP88 is None: print("[" + self.dvm_config.NIP89.NAME + "] Profile Zap received for DVM balance: " + - str(invoice_amount) + " Sats from " + str(user.name)) + str(invoice_amount) + " Sats from " + str(user.name + " (" + user.npub + ")")) # update_user_balance(self.dvm_config.DB, sender, invoice_amount, client=self.client, # config=self.dvm_config) diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py b/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py index c52b369..0bbb975 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_nonfollowers.py @@ -38,10 +38,14 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface): must_list = [] personalized = True result = "" + database = None async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None, admin_config: AdminConfig = None, options=None): + if dvm_config.DATABASE is not None: + self.database = dvm_config.DATABASE + self.request_form = {"jobID": "generic"} opts = { "max_results": 200, @@ -141,9 +145,10 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface): sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) signer = NostrSigner.keys(keys) - database = await NostrDatabase.sqlite(self.db_name) + if self.database is None: + self.database = await NostrDatabase.sqlite(self.db_name) - cli = ClientBuilder().database(database).signer(signer).opts(opts).build() + cli = ClientBuilder().database(self.database).signer(signer).opts(opts).build() for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST: await cli.add_relay(relay) @@ -179,7 +184,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface): filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since) - events = await database.query([filter1]) + events = await self.database.query([filter1]) print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events") ns.finallist = {} @@ -192,7 +197,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface): [definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_REPOST, definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since) - reactions = await database.query([filt]) + reactions = await self.database.query([filt]) if len(reactions) >= self.min_reactions: ns.finallist[event.id().to_hex()] = len(reactions) diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py index c59c924..1043a4b 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_topic.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_topic.py @@ -37,10 +37,14 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface): must_list = [] personalized = False result = "" + database = None + async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None, admin_config: AdminConfig = None, options=None): + if dvm_config.DATABASE is not None: + self.database = dvm_config.DATABASE self.request_form = {"jobID": "generic"} opts = { "max_results": 200, @@ -139,14 +143,15 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface): ns = SimpleNamespace() options = self.set_options(request_form) - database = await NostrDatabase.sqlite(self.db_name) + if self.database is None: + self.database = await NostrDatabase.sqlite(self.db_name) timestamp_since = Timestamp.now().as_secs() - self.db_since since = Timestamp.from_secs(timestamp_since) filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since) - events = await database.query([filter1]) + events = await self.database.query([filter1]) if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events") ns.finallist = {} @@ -159,7 +164,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface): [definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_REPOST, definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since) - reactions = await database.query([filt]) + reactions = await self.database.query([filt]) if len(reactions) >= self.min_reactions: ns.finallist[event.id().to_hex()] = len(reactions) diff --git a/nostr_dvm/tasks/content_discovery_update_db_only.py b/nostr_dvm/tasks/content_discovery_update_db_only.py index fec6f64..53c9191 100644 --- a/nostr_dvm/tasks/content_discovery_update_db_only.py +++ b/nostr_dvm/tasks/content_discovery_update_db_only.py @@ -39,6 +39,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): must_list = [] personalized = False result = "" + database = None async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None, admin_config: AdminConfig = None, options=None): @@ -46,6 +47,8 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): # Generate Generic request form for dvms that provide generic results (e.g only a calculation per update, # not per call) self.request_form = {"jobID": "generic"} + if dvm_config.DATABASE is not None: + self.database = dvm_config.DATABASE opts = { "max_results": 200, } @@ -128,8 +131,9 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) signer = NostrSigner.keys(keys) - database = await NostrDatabase.sqlite(self.db_name) - cli = ClientBuilder().signer(signer).database(database).opts(opts).build() + if self.database is None: + self.database = await NostrDatabase.sqlite(self.db_name) + cli = ClientBuilder().signer(signer).database(self.database).opts(opts).build() for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST: await cli.add_relay(relay) diff --git a/nostr_dvm/utils/dvmconfig.py b/nostr_dvm/utils/dvmconfig.py index f68abdf..e2c88b2 100644 --- a/nostr_dvm/utils/dvmconfig.py +++ b/nostr_dvm/utils/dvmconfig.py @@ -1,6 +1,6 @@ import os -from nostr_sdk import Keys, LogLevel +from nostr_sdk import Keys, LogLevel, PublicKey from nostr_dvm.utils.nip88_utils import NIP88Config from nostr_dvm.utils.nip89_utils import NIP89Config @@ -24,12 +24,27 @@ class DVMConfig: "wss://nostr.oxtr.dev", "wss://relay.nostr.net" , "wss://relay.primal.net"] #, "wss://relay.snort.social"] - MUTE = ["npub1x5vhtx7j2prvueeenwf7tmesrzmuzc50zs0aakgd75v5c30ekj3s5zjckj", - "npub1l03urys27uet2u6wq6u90rnzf7kv5c3wfu3cyndqz9lq75g46c5q0wkpsj", - "npub17g7qhlu4caefd88vateedm9wau9ys6xt6jhjcfu2kqyw9xmnucxs5d6crj", - "npub1epwccahqndqhseh6q02seu40cqa2ghk3u9tvu92yh4hd6lmxg33spwzujc", - "npub1v0kgu3hymtd4fw9zrlem6l74c3cwl8jdqentt4qsxrrzan6paxaqkkf6dr", - ] + # Straight Censorship (reply guy spam) + MUTE = [PublicKey.parse("npub1x5vhtx7j2prvueeenwf7tmesrzmuzc50zs0aakgd75v5c30ekj3s5zjckj"), + PublicKey.parse("npub1l03urys27uet2u6wq6u90rnzf7kv5c3wfu3cyndqz9lq75g46c5q0wkpsj"), + PublicKey.parse("npub17g7qhlu4caefd88vateedm9wau9ys6xt6jhjcfu2kqyw9xmnucxs5d6crj"), + PublicKey.parse("npub1epwccahqndqhseh6q02seu40cqa2ghk3u9tvu92yh4hd6lmxg33spwzujc"), + PublicKey.parse("npub1v0kgu3hymtd4fw9zrlem6l74c3cwl8jdqentt4qsxrrzan6paxaqkkf6dr"), + PublicKey.parse("npub1y8teqt2jay2ulww87wlmpe97gxhjqvhva60jv3ghp8emgk2da3psc2x7lt"), + PublicKey.parse("npub1drz9ts6esv22vplg9vunajwhts4ecaxvusmpxwy8yy683ejnzfnqvfvtk9"), + PublicKey.parse("npub1af5hgjkjpdqavpu3xqz092xjrvrpr3nzfftp4pgh4nez635hznas7m0vvn"), + PublicKey.parse("npub1rwxfxn33mmt9fe66qwg25lm9pm3nwtj5za5qm5cpqjsxlhk3dtsqkmunfe"), + PublicKey.parse("npub1l6y4l424ggvstc8a40n5c4rf8wwt5hlt5vuhn4dzvx9xf0eff9uqnc2fuw"), + PublicKey.parse("npub1q57y985vcazhx87naj5qhdyxxmtrrqakfq7lmvhxppvduqpfkesq3n46e8"), + PublicKey.parse("npub1dryv50m3rl6cx6ajeakmh3ygz83vjcdf6cga99yllmfx9ugqa04st0nk3w"), + PublicKey.parse("npub1xh3n3q2cp2wf9r66mmzmkyunyj8cf5r8aszsvwtdld6upqjmkxcsxgejsd"), + PublicKey.parse("npub1cek65lcyks0jjwx4y47c0zxmx8y22zn7zmhxktfjr32h2z5wtgeqn70vjc"), + PublicKey.parse("npub1y2v5mqw32m7n8mz4wpypcy7wt0t4hg93g67qw0fuyspjdspk0etqm0xx9y"), + PublicKey.parse("npub1cfgr520quxl8p74f5r3u5snt05dxyshfk88tcm5tuj78ypkdhgyqcpxkx2"), + PublicKey.parse("npub1620alhm0dyn063wlrlp6r8xzxlzdk9pp94xfag99gghj92wentlq23t6rz"), + + ] + AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST #If a DVM has a paid subscription, overwrite list without the paid one. @@ -46,6 +61,7 @@ class DVMConfig: IDENTIFIER = '' USE_OWN_VENV = False # Make an own venv for each dvm's process function.Disable if you want to install packages into main venv. Only recommended if you dont want to run dvms with different dependency versions DB: str + DATABASE = None NEW_USER_BALANCE: int = 0 # Free credits for new users SUBSCRIPTION_MANAGEMENT = 'https://noogle.lol/discovery' NIP88: NIP88Config = NIP88Config() diff --git a/nostr_dvm/utils/nostr_utils.py b/nostr_dvm/utils/nostr_utils.py index 8ba7efe..646ae79 100644 --- a/nostr_dvm/utils/nostr_utils.py +++ b/nostr_dvm/utils/nostr_utils.py @@ -204,23 +204,19 @@ async def send_event_outbox(event: Event, client, dvm_config) -> EventId: relaylimits = RelayLimits.disable() connection = Connection().embedded_tor().target(ConnectionTarget.ONION) #connection = Connection().addr("127.0.0.1:9050").target(ConnectionTarget.ONION) - opts = ( - Options().wait_for_send(False).send_timeout(timedelta(seconds=20)).relay_limits( - relaylimits)).connection(connection).connection_timeout(timedelta(seconds=120)) + opts = (( + Options().wait_for_send(False).send_timeout(timedelta(seconds=5)).relay_limits( + relaylimits)).connection(connection).connection_timeout(timedelta(seconds=30))) sk = SecretKey.from_hex(dvm_config.PRIVATE_KEY) keys = Keys.parse(sk.to_hex()) signer = NostrSigner.keys(keys) - client = Client.with_opts(signer, opts) - - - outboxclient = Client.with_opts(signer, opts) print("[" + dvm_config.NIP89.NAME + "] Receiver Inbox relays: " + str(relays)) - for relay in relays: + for relay in relays[:5]: try: await outboxclient.add_relay(relay) except: @@ -290,7 +286,8 @@ async def send_event(event: Event, client: Client, dvm_config, blastr=False): for relay in relays: if relay not in dvm_config.RELAY_LIST: - await client.remove_relay(relay) + if relay not in dvm_config.RELAY_LIST: + await client.remove_relay(relay) #if blastr: # client.remove_relay("wss://nostr.mutinywallet.com") return event_id diff --git a/setup.py b/setup.py index 7a7de9f..a9c411f 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.8.19' +VERSION = '0.8.20' 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 a7007e1..fc6c595 100644 --- a/tests/discovery.py +++ b/tests/discovery.py @@ -1,10 +1,11 @@ +import asyncio import json import os import threading from pathlib import Path import dotenv -from nostr_sdk import init_logger, LogLevel, Keys, NostrLibrary +from nostr_sdk import init_logger, LogLevel, Keys, NostrDatabase from nostr_dvm.tasks.content_discovery_currently_latest_longform import DicoverContentLatestLongForm from nostr_dvm.tasks.content_discovery_currently_latest_wiki import DicoverContentLatestWiki @@ -35,13 +36,13 @@ rebroadcast_NIP89 = False # Announce NIP89 on startup Only do this if you know rebroadcast_NIP65_Relay_List = True update_profile = False -global_update_rate = 120 # set this high on first sync so db can fully sync before another process trys to. -use_logger = True -log_level = LogLevel.ERROR +global_update_rate = 180 # set this high on first sync so db can fully sync before another process trys to. +use_logger = False +log_level = LogLevel.INFO -RECONCILE_DB_RELAY_LIST = [ "wss://relay.nostr.net", "wss://relay.nostr.bg", "wss://relay.damus.io", "wss://nostr.oxtr.dev"] +RECONCILE_DB_RELAY_LIST = [ "wss://relay.nostr.net", "wss://relay.damus.io", "wss://nostr.oxtr.dev"] RELAY_LIST = ["wss://relay.primal.net", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.net" @@ -52,7 +53,7 @@ if use_logger: def build_db_scheduler(name, identifier, admin_config, options, image, description, update_rate=600, cost=0, - processing_msg=None, update_db=True): + processing_msg=None, update_db=True, database=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -61,6 +62,7 @@ def build_db_scheduler(name, identifier, admin_config, options, image, descripti dvm_config.LOGLEVEL = LogLevel.INFO dvm_config.RECONCILE_DB_RELAY_LIST = RECONCILE_DB_RELAY_LIST dvm_config.RELAY_LIST = RELAY_LIST + dvm_config.DATABASE = database # Activate these to use a subscription based model instead # dvm_config.SUBSCRIPTION_REQUIRED = True @@ -276,7 +278,7 @@ def build_wiki(name, identifier, admin_config, options, cost=0, update_rate=180, def build_example_topic(name, identifier, admin_config, options, image, description, update_rate=600, cost=0, - processing_msg=None, update_db=True): + processing_msg=None, update_db=True, database=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -287,6 +289,7 @@ def build_example_topic(name, identifier, admin_config, options, image, descript dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg dvm_config.AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST dvm_config.RELAY_LIST = RELAY_LIST + dvm_config.DATABASE = database #dvm_config.RELAY_LIST = ["wss://dvms.f7z.io", # "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg" # ] @@ -321,7 +324,7 @@ def build_example_topic(name, identifier, admin_config, options, image, descript def build_example_popular(name, identifier, admin_config, options, image, cost=0, update_rate=180, processing_msg=None, - update_db=True): + update_db=True, database=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.LOGLEVEL = LogLevel.INFO @@ -334,6 +337,7 @@ def build_example_popular(name, identifier, admin_config, options, image, cost=0 dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg dvm_config.AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST dvm_config.RELAY_LIST = RELAY_LIST + dvm_config.DATABASE = database #dvm_config.RELAY_LIST = ["wss://dvms.f7z.io", # "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg" # ] @@ -412,7 +416,7 @@ def build_example_popular_followers(name, identifier, admin_config, options, ima admin_config=admin_config) def build_example_popular_non_followers(name, identifier, admin_config, options, image, cost=0, update_rate=300, - processing_msg=None, update_db=True): + processing_msg=None, update_db=True, database=None): dvm_config = build_default_config(identifier) @@ -421,6 +425,7 @@ def build_example_popular_non_followers(name, identifier, admin_config, options, dvm_config.LOGLEVEL = LogLevel.DEBUG dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every 10 minutes dvm_config.UPDATE_DATABASE = update_db + dvm_config.DATABASE = database # Activate these to use a subscription based model instead dvm_config.FIX_COST = cost dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg @@ -481,7 +486,7 @@ def build_example_popular_non_followers(name, identifier, admin_config, options, def build_example_top_zapped(name, identifier, admin_config, options, image, cost=0, update_rate=180, processing_msg=None, - update_db=True): + update_db=True, database=None): dvm_config = build_default_config(identifier) dvm_config.USE_OWN_VENV = False dvm_config.SHOWLOG = True @@ -493,6 +498,7 @@ def build_example_top_zapped(name, identifier, admin_config, options, image, cos dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg dvm_config.AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST dvm_config.RELAY_LIST = RELAY_LIST + dvm_config.DATABASE = database #dvm_config.RELAY_LIST = ["wss://dvms.f7z.io", # "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg" # ] @@ -623,15 +629,18 @@ def build_example_oneperfollow(name, identifier, admin_config, options, image, c admin_config=admin_config, options=options) +async def init_db(database): + return await NostrDatabase.sqlite(database) def playground(): - + main_db = "db/nostr_recent_notes.db" + DATABASE = asyncio.run(init_db(main_db)) #DB Scheduler, do not announce, just use it to update the DB for the other DVMs. admin_config_db_scheduler= AdminConfig() options_animal = { - "db_name": "db/nostr_recent_notes.db", - "db_since": 24 * 60 * 60, # 48h since gmt, + "db_name": main_db, + "db_since": 12 * 60 * 60, # 48h since gmt, "personalized": False, "logger": False} image = "" @@ -643,7 +652,8 @@ def playground(): description=about, update_rate=global_update_rate, cost=0, - update_db=True) + update_db=True, + database=DATABASE) db_scheduler.run() @@ -665,19 +675,19 @@ def playground(): "db_since": 60 * 60 * 24 * 30, # 1h since gmt, } - cost = 0 - image = "https://i.nostr.build/4Rw6lrsH5O0P5zjT.jpg" - discover_gallery = build_example_gallery("Gallery entries", - "discovery_gallery_entries", - admin_config=admin_config_gallery, - options=options_gallery, - image=image, - cost=cost, - update_rate=global_update_rate, - processing_msg=custom_processing_msg, - update_db=update_db) - discover_gallery.run() - + # cost = 0 + # image = "https://i.nostr.build/4Rw6lrsH5O0P5zjT.jpg" + # discover_gallery = build_example_gallery("Gallery entries", + # "discovery_gallery_entries", + # admin_config=admin_config_gallery, + # options=options_gallery, + # image=image, + # cost=cost, + # update_rate=global_update_rate, + # processing_msg=custom_processing_msg, + # update_db=update_db) + # discover_gallery.run() + # # Latest Longform @@ -755,7 +765,7 @@ def playground(): options_top_zapped = { "db_name": "db/nostr_recent_notes.db", - "db_since": 60 * 60 * 6, # 8h since gmt, + "db_since": 60 * 60 * 2, # 8h since gmt, } cost = 0 #image = "https://image.nostr.build/c6879f458252641d04d0aa65fd7f1e005a4f7362fd407467306edc2f4acdb113.jpg" @@ -768,7 +778,8 @@ def playground(): cost=cost, update_rate=global_update_rate, processing_msg=custom_processing_msg, - update_db=update_db) + update_db=update_db, + database=DATABASE) discovery_topzaps.run() @@ -856,7 +867,7 @@ def playground(): "must_list": ["http"], "db_name": "db/nostr_recent_notes.db", - "db_since": 24 * 60 * 60, # 48h since gmt, + "db_since": 12 * 60 * 60, # 48h since gmt, "personalized": False, "logger": False} @@ -875,7 +886,8 @@ def playground(): update_rate=global_update_rate, cost=cost, processing_msg=custom_processing_msg, - update_db=update_db) + update_db=update_db, + database = DATABASE) discovery_animals.run() @@ -923,7 +935,8 @@ def playground(): update_rate=global_update_rate, cost=cost, processing_msg=custom_processing_msg, - update_db=update_db) + update_db=update_db, + database=DATABASE) discovery_garden.run() # Popular Followers @@ -943,6 +956,7 @@ def playground(): "db_name": "db/nostr_recent_notes.db", "db_since": 2 * 60 * 60, # 2h since gmt, } + cost = 0 #image = "https://image.nostr.build/d92652a6a07677e051d647dcf9f0f59e265299b3335a939d008183a911513f4a.jpg" image = "https://i.nostr.build/ZJqko0W9ApEVZAPt.png" @@ -987,7 +1001,8 @@ def playground(): image=image, update_rate=global_update_rate, processing_msg=custom_processing_msg, - update_db=update_db) + update_db=update_db, + database=DATABASE) discovery_non_followers.run() admin_config_opf = AdminConfig() @@ -1047,7 +1062,8 @@ def playground(): cost=cost, update_rate=global_update_rate, processing_msg=custom_processing_msg, - update_db=update_db) + update_db=update_db, + database=DATABASE) discovery_global.run() # discovery_test_sub = content_discovery_currently_popular.build_example_subscription("Currently Popular Notes DVM (with Subscriptions)", "discovery_content_test", admin_config) @@ -1059,9 +1075,9 @@ def playground(): admin_config_nostriga.REBROADCAST_NIP65_RELAY_LIST = False #rebroadcast_NIP65_Relay_List admin_config_nostriga.UPDATE_PROFILE = update_profile admin_config_nostriga.DELETE_NIP89 = True - admin_config_nostriga.PRIVKEY = "6221e31813df07037dd90a608fc4cf29222c59da130f76c7f8d0d19c3a876d8e" - admin_config_nostriga.EVENTID = "24ac21fb32993744232356bafcabd821e4afed4b18aac8d7e670d1071f6ad77a" - admin_config_nostriga.POW = True + #admin_config_nostriga.PRIVKEY = "6221e31813df07037dd90a608fc4cf29222c59da130f76c7f8d0d19c3a876d8e" + #admin_config_nostriga.EVENTID = "24ac21fb32993744232356bafcabd821e4afed4b18aac8d7e670d1071f6ad77a" + #admin_config_nostriga.POW = True options_nostriga = { "search_list": ["nostriga", "#nostriga", "#noobday" ], "avoid_list": ["porn", "smoke", "nsfw", diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index 015d3c3..50a728a 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -221,6 +221,7 @@ async def nostr_client_custom_discovery(user, ptag): paramTagSearch = Tag.parse(["param", "search_list", search]) paramTagAvoid = Tag.parse(["param", "avoid_list", avoid]) paramTagMust = Tag.parse(["param", "must_list", must]) + pTag = Tag.parse(["p", ptag]) tags = [relaysTag, alttag, paramTag, pTag, paramTagSearch, paramTagMust, paramTagAvoid] @@ -293,6 +294,32 @@ async def nostr_client_duckduck_test(ptag, query): config = DVMConfig await send_event(event, client=client, dvm_config=config) return event.as_json() +async def nostr_client_flux_schnell(ptag, query): + keys = Keys.parse(check_and_set_private_key("test_client")) + + relay_list = ["wss://nostr.oxtr.dev", "wss://relay.primal.net", + ] + + relaysTag = Tag.parse(relay_list) + alttag = Tag.parse(["alt", "This is a NIP90 DVM AI task"]) + + pTag = Tag.parse(["p", ptag]) + iTag = Tag.parse(["i", query, "text"]) + + tags = [relaysTag, alttag, pTag, iTag] + + event = EventBuilder(Kind(5100), str("Give me image"), + tags).to_event(keys) + + signer = NostrSigner.keys(keys) + client = Client(signer) + for relay in relay_list: + await client.add_relay(relay) + ropts = RelayOptions().ping(False) + await client.connect() + config = DVMConfig + await send_event(event, client=client, dvm_config=config) + return event.as_json() @@ -417,9 +444,10 @@ 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", "8e998d62eb20ec892acf9d5e8efa58050ccd951cae15a64eabbc5c0a7c74d185") - - await nostr_client_duckduck_test("a018ba05af400b52772e33162d8326fca4a167fe7b6d3cd2382e14cac2af6841", "Write me a poem about purple ostriches") + #await nostr_client_custom_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "7a63849b684d90c0de983492578b12e147e56f5d79ed6585cc64e5aa8a122744") + #"a018ba05af400b52772e33162d8326fca4a167fe7b6d3cd2382e14cac2af6841" + #await nostr_client_duckduck_test(PublicKey.parse("aa8ab5b774d47e7b29a985dd739cfdcccf93451678bf7977ba1b2e094ecd8b30").to_hex() , "How do i create a dockerfile for python 3.12") + await nostr_client_flux_schnell("d57f1efb7582f58cade6f482d53eefa998d8082711b996aae3dc5f5527cbdd6e" , "topics") # await nostr_client_test_search_profile("dontbelieve") #wot = ["99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64"]