mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-04-12 21:59:15 +02:00
0.8.2: update nostr-sdk to 0.3.4
(update venvs)
This commit is contained in:
parent
8ccd902e60
commit
caf099d142
@ -338,7 +338,7 @@ class DVM:
|
||||
return
|
||||
elif tag.as_vec()[0] == 'status':
|
||||
status = tag.as_vec()[1]
|
||||
print(status)
|
||||
|
||||
|
||||
# if a reaction by us got zapped
|
||||
print(status)
|
||||
|
@ -7,7 +7,8 @@ import time
|
||||
from datetime import timedelta
|
||||
|
||||
from nostr_sdk import (Keys, Client, Timestamp, Filter, nip04_decrypt, HandleNotification, EventBuilder, PublicKey,
|
||||
Options, Tag, Event, nip04_encrypt, NostrSigner, EventId, Nip19Event, nip44_decrypt, Kind)
|
||||
Options, Tag, Event, nip04_encrypt, NostrSigner, EventId, Nip19Event, nip44_decrypt, Kind,
|
||||
EventSource)
|
||||
|
||||
from nostr_dvm.utils.database_utils import fetch_user_metadata
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
@ -248,7 +249,8 @@ class Subscription:
|
||||
|
||||
subscriptionfilter = Filter().kind(EventDefinitions.KIND_NIP88_SUBSCRIBE_EVENT).author(
|
||||
PublicKey.parse(subscriber)).limit(1)
|
||||
evts = await self.client.get_events_of([subscriptionfilter], timedelta(seconds=3))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
evts = await self.client.get_events_of([subscriptionfilter], source)
|
||||
if len(evts) > 0:
|
||||
event7001id = evts[0].id().to_hex()
|
||||
print(evts[0].as_json())
|
||||
@ -285,7 +287,8 @@ class Subscription:
|
||||
|
||||
if tier_dtag == "" or len(zaps) == 0:
|
||||
tierfilter = Filter().id(EventId.parse(subscription_event_id))
|
||||
evts = await self.client.get_events_of([tierfilter], timedelta(seconds=3))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
evts = await self.client.get_events_of([tierfilter], source)
|
||||
if len(evts) > 0:
|
||||
for tag in evts[0].tags():
|
||||
if tag.as_vec()[0] == "d":
|
||||
|
@ -1,7 +1,8 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@ -131,8 +132,8 @@ class AdvancedSearch(DVMTaskInterface):
|
||||
else:
|
||||
notes_filter = Filter().kind(Kind(1)).authors(userkeys).search(options["search"]).since(
|
||||
search_since).until(search_until).limit(options["max_results"])
|
||||
|
||||
events = await cli.get_events_of([notes_filter], timedelta(seconds=5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
events = await cli.get_events_of([notes_filter], timedelta(seconds=source))
|
||||
|
||||
result_list = []
|
||||
if len(events) > 0:
|
||||
|
@ -4,7 +4,7 @@ import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions, RelayLimits
|
||||
RelayOptions, RelayLimits, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -113,7 +113,8 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
|
||||
user = PublicKey.parse(options["user"])
|
||||
followers_filter = Filter().author(user).kinds([Kind(3)])
|
||||
followers = await cli.get_events_of([followers_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
followers = await cli.get_events_of([followers_filter], source)
|
||||
#print(followers)
|
||||
|
||||
# Negentropy reconciliation
|
||||
|
@ -4,7 +4,7 @@ import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions, RelayLimits
|
||||
RelayOptions, RelayLimits, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -172,7 +172,8 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
|
||||
|
||||
filter2 = Filter().ids(ids)
|
||||
events = await cli.get_events_of([filter2], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
events = await cli.get_events_of([filter2], source)
|
||||
|
||||
print(len(events))
|
||||
|
||||
|
@ -4,7 +4,7 @@ import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions
|
||||
RelayOptions, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -256,7 +256,8 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
||||
#await cli.reconcile(filter3, dbopts)
|
||||
|
||||
# RECONCOILE NOT POSSIBLE ON THESE RELAYS SO WE FETCH AB BUNCH (will be stored in db)
|
||||
events = await cli.get_events_of([filter1, filter2, filter3], None)
|
||||
source = EventSource.relays(None)
|
||||
events = await cli.get_events_of([filter1, filter2, filter3], source)
|
||||
|
||||
# Do not delete profiles
|
||||
await cli.database().delete(Filter().kinds([EventDefinitions.KIND_NOTE, EventDefinitions.KIND_ZAP, EventDefinitions.KIND_REPOST, EventDefinitions.KIND_REACTION]).until(Timestamp.from_secs(
|
||||
|
@ -4,7 +4,7 @@ import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayLimits
|
||||
RelayLimits, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -154,7 +154,8 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
||||
await cli.connect()
|
||||
user = PublicKey.parse(options["user"])
|
||||
followers_filter = Filter().author(user).kinds([Kind(3)])
|
||||
followers = await cli.get_events_of([followers_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
followers = await cli.get_events_of([followers_filter], source)
|
||||
if len(followers) > 0:
|
||||
newest = 0
|
||||
best_entry = followers[0]
|
||||
|
@ -5,7 +5,7 @@ from datetime import timedelta
|
||||
from threading import Thread
|
||||
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
RelayLimits, Event
|
||||
RelayLimits, Event, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@ -92,7 +92,8 @@ class Discoverlatestperfollower(DVMTaskInterface):
|
||||
step = 20
|
||||
|
||||
followers_filter = Filter().author(PublicKey.parse(options["user"])).kind(Kind(3))
|
||||
followers = await cli.get_events_of([followers_filter], timedelta(seconds=5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
followers = await cli.get_events_of([followers_filter], source)
|
||||
|
||||
if len(followers) > 0:
|
||||
result_list = []
|
||||
@ -140,7 +141,8 @@ class Discoverlatestperfollower(DVMTaskInterface):
|
||||
filter1 = (Filter().author(PublicKey.from_hex(users[i])).kind(Kind(1))
|
||||
.limit(1))
|
||||
filters.append(filter1)
|
||||
event_from_authors = await cli.get_events_of(filters, timedelta(seconds=10))
|
||||
source = EventSource.relays(timedelta(seconds=10))
|
||||
event_from_authors = await cli.get_events_of(filters, source)
|
||||
for author in event_from_authors:
|
||||
if instance.dic[author.author().to_hex()] is None:
|
||||
instance.dic[author.author().to_hex()] = author
|
||||
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
||||
from threading import Thread
|
||||
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
RelayLimits, Event
|
||||
RelayLimits, Event, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@ -97,7 +97,8 @@ class DiscoverReports(DVMTaskInterface):
|
||||
# if we don't add users, e.g. by a wot, we check all our followers.
|
||||
if len(pubkeys) == 0:
|
||||
followers_filter = Filter().author(PublicKey.parse(options["sender"])).kind(Kind(3))
|
||||
followers = await cli.get_events_of([followers_filter], timedelta(seconds=5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
followers = await cli.get_events_of([followers_filter], source)
|
||||
|
||||
if len(followers) > 0:
|
||||
result_list = []
|
||||
@ -118,7 +119,8 @@ class DiscoverReports(DVMTaskInterface):
|
||||
options["since_days"]) # TODO make this an option, 180 days for now
|
||||
since = Timestamp.from_secs(ago)
|
||||
kind1984_filter = Filter().authors(pubkeys).kind(Kind(1984)).since(since)
|
||||
reports = await cli.get_events_of([kind1984_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
reports = await cli.get_events_of([kind1984_filter], source)
|
||||
|
||||
bad_actors = []
|
||||
ns.dic = {}
|
||||
|
@ -5,7 +5,7 @@ from datetime import timedelta
|
||||
from threading import Thread
|
||||
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
RelayLimits
|
||||
RelayLimits, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@ -92,7 +92,8 @@ class DiscoverInactiveFollows(DVMTaskInterface):
|
||||
step = 20
|
||||
|
||||
followers_filter = Filter().author(PublicKey.parse(options["user"])).kind(Kind(3))
|
||||
followers = await cli.get_events_of([followers_filter], timedelta(seconds=5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
followers = await cli.get_events_of([followers_filter], source)
|
||||
|
||||
if len(followers) > 0:
|
||||
result_list = []
|
||||
@ -140,7 +141,8 @@ class DiscoverInactiveFollows(DVMTaskInterface):
|
||||
for i in range(i, i + st):
|
||||
filter1 = Filter().author(PublicKey.from_hex(users[i])).since(notactivesince).limit(1)
|
||||
filters.append(filter1)
|
||||
event_from_authors = await cli.get_events_of(filters, timedelta(seconds=10))
|
||||
source = EventSource.relays(timedelta(seconds=10))
|
||||
event_from_authors = await cli.get_events_of(filters, source)
|
||||
for author in event_from_authors:
|
||||
instance.dic[author.author().to_hex()] = "True"
|
||||
print(str(i) + "/" + str(len(users)))
|
||||
|
@ -5,7 +5,7 @@ from datetime import timedelta
|
||||
from threading import Thread
|
||||
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
RelayLimits
|
||||
RelayLimits, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@ -81,7 +81,8 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
||||
step = 20
|
||||
|
||||
followers_filter = Filter().author(PublicKey.from_hex(options["user"])).kind(Kind(3))
|
||||
followers = await cli.get_events_of([followers_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||
followers = await cli.get_events_of([followers_filter], source)
|
||||
|
||||
if len(followers) > 0:
|
||||
result_list = []
|
||||
@ -118,7 +119,8 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
||||
filters = []
|
||||
filter1 = Filter().author(PublicKey.from_hex(users[i])).kind(Kind(3))
|
||||
filters.append(filter1)
|
||||
followers = await cli.get_events_of(filters, timedelta(seconds=3))
|
||||
source = EventSource.relays(timedelta(seconds=3))
|
||||
followers = await cli.get_events_of(filters, source)
|
||||
|
||||
if len(followers) > 0:
|
||||
result_list = []
|
||||
|
@ -3,7 +3,7 @@ import os
|
||||
from datetime import timedelta
|
||||
|
||||
from nostr_sdk import Tag, Kind, init_logger, LogLevel, Filter, Timestamp, RelayOptions, Client, NostrSigner, Keys, \
|
||||
SecretKey, Options, SingleLetterTag, Alphabet, PublicKey
|
||||
SecretKey, Options, SingleLetterTag, Alphabet, PublicKey, EventSource
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@ -11,7 +11,6 @@ from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_events
|
||||
|
||||
"""
|
||||
@ -84,8 +83,9 @@ class TrendingNotesGleasonator(DVMTaskInterface):
|
||||
ltags = ["#e", "pub.ditto.trends"]
|
||||
authors = [PublicKey.parse("db0e60d10b9555a39050c258d460c5c461f6d18f467aa9f62de1a728b8a891a4")]
|
||||
notes_filter = Filter().authors(authors).kind(Kind(1985)).custom_tag(SingleLetterTag.lowercase(Alphabet.L), ltags)
|
||||
source = EventSource.relays(timedelta(seconds=10))
|
||||
|
||||
events = await cli.get_events_of([notes_filter], timedelta(seconds=10))
|
||||
events = await cli.get_events_of([notes_filter], source)
|
||||
|
||||
result_list = []
|
||||
if len(events) > 0:
|
||||
|
@ -7,7 +7,7 @@ from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
from logging import Filter
|
||||
|
||||
from nostr_sdk import Timestamp, Keys, PublicKey, EventBuilder, Filter, Kind
|
||||
from nostr_sdk import Timestamp, Keys, PublicKey, EventBuilder, Filter, Kind, EventSource
|
||||
from nostr_dvm.utils.nostr_utils import send_event
|
||||
|
||||
|
||||
@ -254,7 +254,8 @@ async def fetch_user_metadata(npub, client):
|
||||
pk = PublicKey.parse(npub)
|
||||
print(f"\nGetting profile metadata for {pk.to_bech32()}...")
|
||||
profile_filter = Filter().kind(Kind(0)).author(pk).limit(1)
|
||||
events = await client.get_events_of([profile_filter], timedelta(seconds=1))
|
||||
source = EventSource.relays(timedelta(seconds=1))
|
||||
events = await client.get_events_of([profile_filter], source)
|
||||
if len(events) > 0:
|
||||
latest_entry = events[0]
|
||||
latest_time = 0
|
||||
|
@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
from nostr_sdk import Filter, Tag, Keys, EventBuilder, Client, EventId, PublicKey, Event, Timestamp, SingleLetterTag, \
|
||||
Alphabet, Kind
|
||||
Alphabet, Kind, EventSource
|
||||
|
||||
from nostr_dvm.utils import definitions
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
@ -37,7 +37,8 @@ def nip88_create_d_tag(name, pubkey, image):
|
||||
|
||||
async def fetch_nip88_parameters_for_deletion(keys, eventid, client, dvmconfig):
|
||||
idfilter = Filter().id(EventId.from_hex(eventid)).limit(1)
|
||||
nip88events = await client.get_events_of([idfilter], timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
|
||||
nip88events = await client.get_events_of([idfilter], source)
|
||||
d_tag = ""
|
||||
if len(nip88events) == 0:
|
||||
print("Event not found. Potentially gone.")
|
||||
@ -60,7 +61,8 @@ async def fetch_nip88_parameters_for_deletion(keys, eventid, client, dvmconfig):
|
||||
|
||||
async def fetch_nip88_event(keys, eventid, client, dvmconfig):
|
||||
idfilter = Filter().id(EventId.parse(eventid)).limit(1)
|
||||
nip88events = await client.get_events_of([idfilter], timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
|
||||
nip88events = await client.get_events_of([idfilter], source)
|
||||
d_tag = ""
|
||||
if len(nip88events) == 0:
|
||||
print("Event not found. Potentially gone.")
|
||||
@ -99,7 +101,8 @@ async def nip88_has_active_subscription(user: PublicKey, tiereventdtag, client:
|
||||
subscriptionfilter = Filter().kind(definitions.EventDefinitions.KIND_NIP88_PAYMENT_RECIPE).pubkey(
|
||||
PublicKey.parse(receiver_public_key_hex)).custom_tag(SingleLetterTag.uppercase(Alphabet.P),
|
||||
[user.to_hex()]).limit(1)
|
||||
evts = await client.get_events_of([subscriptionfilter], timedelta(seconds=3))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
evts = await client.get_events_of([subscriptionfilter],source)
|
||||
if len(evts) > 0:
|
||||
print(evts[0].as_json())
|
||||
matchesdtag = False
|
||||
@ -120,7 +123,8 @@ async def nip88_has_active_subscription(user: PublicKey, tiereventdtag, client:
|
||||
cancel_filter = Filter().kind(EventDefinitions.KIND_NIP88_STOP_SUBSCRIPTION_EVENT).author(
|
||||
user).pubkey(PublicKey.parse(receiver_public_key_hex)).event(
|
||||
EventId.parse(subscription_status["subscriptionId"])).limit(1)
|
||||
cancel_events = await client.get_events_of([cancel_filter], timedelta(seconds=3))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
cancel_events = await client.get_events_of([cancel_filter], source)
|
||||
if len(cancel_events) > 0:
|
||||
if cancel_events[0].created_at().as_secs() > evts[0].created_at().as_secs():
|
||||
subscription_status["expires"] = True
|
||||
|
@ -4,7 +4,8 @@ from hashlib import sha256
|
||||
from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
from nostr_sdk import Tag, Keys, EventBuilder, Filter, Alphabet, PublicKey, Client, EventId, SingleLetterTag, Kind
|
||||
from nostr_sdk import Tag, Keys, EventBuilder, Filter, Alphabet, PublicKey, Client, EventId, SingleLetterTag, Kind, \
|
||||
EventSource
|
||||
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.nostr_utils import send_event
|
||||
@ -39,7 +40,8 @@ async def nip89_announce_tasks(dvm_config, client):
|
||||
|
||||
async def fetch_nip89_parameters_for_deletion(keys, eventid, client, dvmconfig, pow=False):
|
||||
idfilter = Filter().id(EventId.from_hex(eventid)).limit(1)
|
||||
nip89events = await client.get_events_of([idfilter], timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
|
||||
nip89events = await client.get_events_of([idfilter], source)
|
||||
d_tag = ""
|
||||
if len(nip89events) == 0:
|
||||
print("Event not found. Potentially gone.")
|
||||
@ -85,7 +87,8 @@ async def nip89_fetch_all_dvms(client):
|
||||
ktags.append(str(i))
|
||||
|
||||
filter = Filter().kind(EventDefinitions.KIND_ANNOUNCEMENT).custom_tag(SingleLetterTag.lowercase(Alphabet.K), ktags)
|
||||
events = await client.get_events_of([filter], timedelta(seconds=5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
events = await client.get_events_of([filter], source)
|
||||
for event in events:
|
||||
print(event.as_json())
|
||||
|
||||
@ -94,7 +97,8 @@ async def nip89_fetch_events_pubkey(client, pubkey, kind):
|
||||
ktags = [str(kind.as_u64())]
|
||||
nip89filter = (Filter().kind(EventDefinitions.KIND_ANNOUNCEMENT).author(PublicKey.parse(pubkey)).
|
||||
custom_tag(SingleLetterTag.lowercase(Alphabet.K), ktags))
|
||||
events = await client.get_events_of([nip89filter], timedelta(seconds=4))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
events = await client.get_events_of([nip89filter], source)
|
||||
|
||||
dvms = {}
|
||||
for event in events:
|
||||
|
@ -6,7 +6,7 @@ from typing import List
|
||||
|
||||
import dotenv
|
||||
from nostr_sdk import Filter, Client, Alphabet, EventId, Event, PublicKey, Tag, Keys, nip04_decrypt, Metadata, Options, \
|
||||
Nip19Event, SingleLetterTag, RelayOptions, RelayLimits, SecretKey, NostrSigner
|
||||
Nip19Event, SingleLetterTag, RelayOptions, RelayLimits, SecretKey, NostrSigner, EventSource
|
||||
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
@ -16,7 +16,8 @@ async def get_event_by_id(event_id: str, client: Client, config=None) -> Event |
|
||||
if len(split) == 3:
|
||||
pk = PublicKey.from_hex(split[1])
|
||||
id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]])
|
||||
events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([id_filter], source)
|
||||
else:
|
||||
if str(event_id).startswith('note'):
|
||||
event_id = EventId.from_bech32(event_id)
|
||||
@ -32,7 +33,9 @@ async def get_event_by_id(event_id: str, client: Client, config=None) -> Event |
|
||||
|
||||
id_filter = Filter().id(event_id).limit(1)
|
||||
#events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([id_filter], timedelta(seconds=5))
|
||||
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
events = await client.get_events_of([id_filter], source)
|
||||
|
||||
|
||||
if len(events) > 0:
|
||||
@ -43,7 +46,8 @@ async def get_event_by_id(event_id: str, client: Client, config=None) -> Event |
|
||||
return None
|
||||
|
||||
async def get_events_async(client, filter, timeout):
|
||||
events = await client.get_events_of([filter], timedelta(seconds=timeout))
|
||||
source = EventSource.relays(timedelta(seconds=timeout))
|
||||
events = await client.get_events_of([filter], source)
|
||||
return events
|
||||
|
||||
|
||||
@ -55,7 +59,8 @@ async def get_events_by_ids(event_ids, client: Client, config=None) -> List | No
|
||||
if len(split) == 3:
|
||||
pk = PublicKey.from_hex(split[1])
|
||||
id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]])
|
||||
events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([id_filter], source)
|
||||
#events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
else:
|
||||
if str(event_id).startswith('note'):
|
||||
@ -72,7 +77,8 @@ async def get_events_by_ids(event_ids, client: Client, config=None) -> List | No
|
||||
search_ids.append(event_id)
|
||||
|
||||
id_filter = Filter().ids(search_ids)
|
||||
events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([id_filter], source)
|
||||
|
||||
#events = client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
if len(events) > 0:
|
||||
@ -84,7 +90,8 @@ async def get_events_by_ids(event_ids, client: Client, config=None) -> List | No
|
||||
async def get_events_by_id(event_ids: list, client: Client, config=None) -> list[Event] | None:
|
||||
id_filter = Filter().ids(event_ids)
|
||||
#events = asyncio.run(get_events_async(client, id_filter, config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([id_filter], timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([id_filter], source)
|
||||
if len(events) > 0:
|
||||
return events
|
||||
else:
|
||||
@ -109,7 +116,8 @@ async def get_referenced_event_by_id(event_id, client, dvm_config, kinds) -> Eve
|
||||
job_id_filter = Filter().kinds(kinds).event(event_id).limit(1)
|
||||
else:
|
||||
job_id_filter = Filter().event(event_id).limit(1)
|
||||
events = await client.get_events_of([job_id_filter], timedelta(seconds=dvm_config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=dvm_config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([job_id_filter], source)
|
||||
#events = await get_events_async(client, job_id_filter, dvm_config.RELAY_TIMEOUT)
|
||||
#events = client.get_events_of([job_id_filter], timedelta(seconds=dvm_config.RELAY_TIMEOUT))
|
||||
|
||||
@ -127,7 +135,8 @@ async def get_inbox_relays(event_to_send: Event, client: Client, dvm_config):
|
||||
ptags.append(ptag)
|
||||
|
||||
filter = Filter().kinds([EventDefinitions.KIND_RELAY_ANNOUNCEMENT]).authors(ptags)
|
||||
events = await client.get_events_of([filter], timedelta(dvm_config.RELAY_TIMEOUT))
|
||||
source = EventSource.relays(timedelta(seconds=dvm_config.RELAY_TIMEOUT))
|
||||
events = await client.get_events_of([filter], source)
|
||||
if len(events) == 0:
|
||||
return []
|
||||
else:
|
||||
|
@ -11,7 +11,7 @@ from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
from nostr_dvm.utils.zap_utils import pay_bolt11_ln_bits, zaprequest
|
||||
from nostr_sdk import Tag, Keys, nip44_encrypt, nip44_decrypt, Nip44Version, EventBuilder, Client, Filter, Kind, \
|
||||
EventId, nip04_decrypt, nip04_encrypt, Options, NostrSigner, PublicKey, init_logger, LogLevel, Metadata
|
||||
EventId, nip04_decrypt, nip04_encrypt, Options, NostrSigner, PublicKey, init_logger, LogLevel, Metadata, EventSource
|
||||
from nostr_dvm.utils.print import bcolors
|
||||
|
||||
class NutWallet(object):
|
||||
@ -118,7 +118,8 @@ class NutZapWallet:
|
||||
nut_wallet = None
|
||||
|
||||
wallet_filter = Filter().kind(EventDefinitions.KIND_NUT_WALLET).author(keys.public_key())
|
||||
wallets = await client.get_events_of([wallet_filter], timedelta(10))
|
||||
source = EventSource.relays(timedelta(seconds=10))
|
||||
wallets = await client.get_events_of([wallet_filter], source)
|
||||
|
||||
if len(wallets) > 0:
|
||||
|
||||
@ -192,7 +193,8 @@ class NutZapWallet:
|
||||
|
||||
# Now all proof events
|
||||
proof_filter = Filter().kind(Kind(7375)).author(keys.public_key())
|
||||
proof_events = await client.get_events_of([proof_filter], timedelta(5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
proof_events = await client.get_events_of([proof_filter], source)
|
||||
|
||||
latest_proof_sec = 0
|
||||
latest_proof_event_id = EventId
|
||||
@ -445,7 +447,8 @@ class NutZapWallet:
|
||||
|
||||
async def fetch_mint_info_event(self, pubkey, client):
|
||||
mint_info_filter = Filter().kind(Kind(10019)).author(PublicKey.parse(pubkey))
|
||||
preferences = await client.get_events_of([mint_info_filter], timedelta(5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
preferences = await client.get_events_of([mint_info_filter], source)
|
||||
mints = []
|
||||
relays = []
|
||||
pubkey = ""
|
||||
|
@ -16,7 +16,8 @@ import random
|
||||
from scipy.sparse import lil_matrix, csr_matrix, isspmatrix_csr
|
||||
|
||||
|
||||
from nostr_sdk import Options, Keys, NostrSigner, NostrDatabase, ClientBuilder, SecretKey, Kind, PublicKey, Filter
|
||||
from nostr_sdk import Options, Keys, NostrSigner, NostrDatabase, ClientBuilder, SecretKey, Kind, PublicKey, Filter, \
|
||||
EventSource
|
||||
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
@ -60,7 +61,8 @@ async def get_following(pks, max_time_request=10, newer_than_time=None):
|
||||
|
||||
await cli.connect()
|
||||
|
||||
events = await cli.get_events_of([filter], datetime.timedelta(seconds=max_time_request))
|
||||
source = EventSource.relays(datetime.timedelta(seconds=100))
|
||||
events = await cli.get_events_of([filter], source)
|
||||
|
||||
# initializing the graph structure
|
||||
following = nx.DiGraph()
|
||||
@ -598,7 +600,8 @@ async def get_metadata(npub):
|
||||
await client.connect()
|
||||
|
||||
profile_filter = Filter().kind(Kind(0)).author(pk).limit(1)
|
||||
events = await client.get_events_of([profile_filter], datetime.timedelta(seconds=4))
|
||||
source = EventSource.relays(datetime.timedelta(seconds=4))
|
||||
events = await client.get_events_of([profile_filter], source)
|
||||
if len(events) > 0:
|
||||
try:
|
||||
profile = json.loads(events[0].content())
|
||||
|
4
setup.py
4
setup.py
@ -1,6 +1,6 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
VERSION = '0.8.1'
|
||||
VERSION = '0.8.2'
|
||||
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')
|
||||
|
||||
@ -14,7 +14,7 @@ setup(
|
||||
long_description=LONG_DESCRIPTION,
|
||||
packages=find_packages(include=['nostr_dvm', 'nostr_dvm.*']),
|
||||
|
||||
install_requires=["nostr-sdk==0.33.0",
|
||||
install_requires=["nostr-sdk==0.34.0",
|
||||
"bech32==1.2.0",
|
||||
"pycryptodome==3.20.0",
|
||||
"yt-dlp==2024.5.27",
|
||||
|
@ -3,7 +3,7 @@ import json
|
||||
from datetime import timedelta
|
||||
|
||||
from nostr_sdk import Options, SecretKey, NostrSigner, Keys, Client, RelayOptions, Alphabet, SingleLetterTag, Filter, \
|
||||
Kind, PublicKey, init_logger, LogLevel, Tag
|
||||
Kind, PublicKey, init_logger, LogLevel, Tag, EventSource
|
||||
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
|
||||
@ -29,7 +29,8 @@ async def main():
|
||||
authors = [PublicKey.parse("db0e60d10b9555a39050c258d460c5c461f6d18f467aa9f62de1a728b8a891a4")]
|
||||
notes_filter = Filter().authors(authors).custom_tag(SingleLetterTag.lowercase(Alphabet.L), ltags)
|
||||
|
||||
events = await cli.get_events_of([notes_filter], timedelta(seconds=10))
|
||||
source = EventSource.relays(timedelta(seconds=10))
|
||||
events = await cli.get_events_of([notes_filter], source)
|
||||
|
||||
result_list = []
|
||||
if len(events) > 0:
|
||||
|
@ -4,7 +4,7 @@ import time
|
||||
from datetime import timedelta
|
||||
from nicegui import run, ui
|
||||
from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, \
|
||||
Options, Timestamp, NostrSigner, EventId, Nip19Event, PublicKey
|
||||
Options, Timestamp, NostrSigner, EventId, Nip19Event, PublicKey, EventSource
|
||||
|
||||
from nostr_dvm.utils import dvmconfig
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||
@ -65,8 +65,9 @@ async def init():
|
||||
[EventDefinitions.KIND_FEEDBACK]).since(now).event(eventid)
|
||||
lastfeedback = ""
|
||||
while not response:
|
||||
events = await client.get_events_of([feedbackfilter], timedelta(seconds=3))
|
||||
fevents = await client.get_events_of([feedbackfilter2], timedelta(seconds=3))
|
||||
source = EventSource.relays(timedelta(seconds=3))
|
||||
events = await client.get_events_of([feedbackfilter], source)
|
||||
fevents = await client.get_events_of([feedbackfilter2], source)
|
||||
if len(fevents) > 0:
|
||||
if lastfeedback != fevents[0].content():
|
||||
for tag in fevents[0].tags():
|
||||
|
@ -203,6 +203,43 @@ async def nostr_client_test_discovery(user, ptag):
|
||||
return event.as_json()
|
||||
|
||||
|
||||
|
||||
async def nostr_client_custom_discovery(user, ptag):
|
||||
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 to find content"])
|
||||
paramTag = Tag.parse(["param", "user", user])
|
||||
|
||||
search = " art , photograph , photo , photography , painting ,#artstr, drawing "
|
||||
avoid = "sex"
|
||||
must = "http"
|
||||
|
||||
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]
|
||||
|
||||
event = EventBuilder(EventDefinitions.KIND_NIP90_CONTENT_DISCOVERY, str("Give me content"),
|
||||
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.add_relay_with_opts("wss://nostr.band", ropts)
|
||||
await client.connect()
|
||||
config = DVMConfig
|
||||
await send_event(event, client=client, dvm_config=config)
|
||||
return event.as_json()
|
||||
|
||||
|
||||
async def nostr_client_test_discovery_user(user, ptag):
|
||||
keys = Keys.parse(check_and_set_private_key("test_client"))
|
||||
|
||||
@ -310,11 +347,11 @@ async def nostr_client():
|
||||
EventDefinitions.KIND_ZAP]).since(
|
||||
Timestamp.now()) # events to us specific
|
||||
kinds = [EventDefinitions.KIND_NIP90_GENERIC]
|
||||
SUPPORTED_KINDS = [Kind(6100), Kind(7000)]
|
||||
#SUPPORTED_KINDS = [Kind(6100), Kind(7000)]
|
||||
|
||||
for kind in SUPPORTED_KINDS:
|
||||
for kind in range(6000, 7001):
|
||||
if kind not in kinds:
|
||||
kinds.append(kind)
|
||||
kinds.append(Kind(kind))
|
||||
dvm_filter = (Filter().kinds(kinds).since(Timestamp.now()).pubkey(pk))
|
||||
await client.subscribe([dm_zap_filter, dvm_filter], None)
|
||||
|
||||
@ -322,7 +359,10 @@ async def nostr_client():
|
||||
# await nostr_client_test_translation("note1p8cx2dz5ss5gnk7c59zjydcncx6a754c0hsyakjvnw8xwlm5hymsnc23rs", "event", "es", 20,20)
|
||||
# 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_test_image("a beautiful purple ostrich watching the sunset, eating a cashew nut")
|
||||
await nostr_client_custom_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "8e998d62eb20ec892acf9d5e8efa58050ccd951cae15a64eabbc5c0a7c74d185")
|
||||
|
||||
|
||||
# await nostr_client_test_search_profile("dontbelieve")
|
||||
#wot = ["99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64"]
|
||||
# await nostr_client_test_discovery("99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64", "ab6cdf12ca3ae5109416295b8cd8a53fdec3a9d54beb7a9aee0ebfb67cb4edf7")
|
||||
|
@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \
|
||||
nip04_encrypt, EventId, Options, PublicKey, Event, NostrSigner, Nip19Event, SecretKey, Kind
|
||||
nip04_encrypt, EventId, Options, PublicKey, Event, NostrSigner, Nip19Event, SecretKey, Kind, EventSource
|
||||
|
||||
from nostr_dvm.utils import definitions, dvmconfig
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||
@ -61,7 +61,8 @@ async def test_referred_events(client, event_id, kinds=None):
|
||||
else:
|
||||
job_id_filter = Filter().event(EventId.from_hex(event_id))
|
||||
|
||||
events = await client.get_events_of([job_id_filter], timedelta(seconds=5))
|
||||
source = EventSource.relays(timedelta(seconds=5))
|
||||
events = await client.get_events_of([job_id_filter], source)
|
||||
|
||||
if len(events) > 0:
|
||||
for event in events:
|
||||
@ -141,7 +142,8 @@ async def test_search_by_user_since_days(client, pubkey, days, prompt):
|
||||
since = Timestamp.from_secs(dif)
|
||||
|
||||
filterts = Filter().search(prompt).author(pubkey).kinds([Kind(1)]).since(since)
|
||||
events = await client.get_events_of([filterts], timedelta(seconds=5))
|
||||
source = EventSource.relays(timedelta(seconds=4))
|
||||
events = await client.get_events_of([filterts], source)
|
||||
|
||||
if len(events) > 0:
|
||||
for event in events:
|
||||
|
@ -13,7 +13,7 @@ warnings.filterwarnings('ignore')
|
||||
|
||||
from nostr_sdk import RelayLimits, PublicKey, Options, Client, SecretKey, Keys, NostrSigner, RelayOptions, Filter, \
|
||||
PublicKey, Kind, \
|
||||
NegentropyOptions, NegentropyDirection, ClientBuilder, NostrDatabase, init_logger, LogLevel
|
||||
NegentropyOptions, NegentropyDirection, ClientBuilder, NostrDatabase, init_logger, LogLevel, EventSource
|
||||
|
||||
|
||||
# init_logger(LogLevel.INFO)
|
||||
@ -35,7 +35,8 @@ async def getmetadata(npub):
|
||||
await client.connect()
|
||||
|
||||
profile_filter = Filter().kind(Kind(0)).author(pk).limit(1)
|
||||
events = await client.get_events_of([profile_filter], timedelta(seconds=4))
|
||||
source = EventSource.relays(timedelta(seconds=4))
|
||||
events = await client.get_events_of([profile_filter], source)
|
||||
if len(events) > 0:
|
||||
try:
|
||||
profile = json.loads(events[0].content())
|
||||
|
Loading…
x
Reference in New Issue
Block a user