mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-17 21:31:52 +01:00
add support for nip68 events
This commit is contained in:
parent
fa40e31853
commit
b553c9aa96
@ -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())
|
||||
|
@ -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)
|
||||
|
@ -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!")
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
|
@ -14,7 +14,7 @@
|
||||
</div>
|
||||
</template> -->
|
||||
<template
|
||||
#item-content="{content, author, authorurl, avatar, indicator, links, lud16, id, authorid, zapped, zapAmount, reacted, reactions, boosts, boosted, event, replied}">
|
||||
#item-content="{content, author, authorurl, avatar, indicator, links, lud16, id, authorid, zapped, zapAmount, reacted, reactions, boosts, boosted, event, replied, kind20_image}">
|
||||
|
||||
<div class="playeauthor-wrapper">
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
<!--.substr(0, 320) + "\u2026"}} -->
|
||||
|
||||
<h3 v-html="StringUtil.parseImages(content)"></h3>
|
||||
<h3 v-html="StringUtil.parseImages_save(kind20_image)"></h3>
|
||||
<!-- <h3>{{StringUtil.parseImages(content)}}</h3> -->
|
||||
<!--<p>{{content.substr(0, 320) + "\u2026"}}</p> -->
|
||||
<div style="padding: 2px; text-align: left;">
|
||||
|
@ -34,6 +34,7 @@ import {webln} from "@getalby/sdk";
|
||||
|
||||
|
||||
import StringUtil from "@/components/helper/string.ts";
|
||||
import {tag_single_letter_tag} from "@rust-nostr/nostr-sdk/pkg/nostr_sdk_js_bg.wasm.js";
|
||||
|
||||
|
||||
let dvms = []
|
||||
@ -362,8 +363,24 @@ async function listen() {
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
let kind20image = ""
|
||||
let p = profiles.find(record => record.author === evt.author.toHex())
|
||||
//olas
|
||||
|
||||
if (evt.kind === 20) {
|
||||
for (let tag of evt.tags) {
|
||||
if (tag.asVec()[0] === "imeta") {
|
||||
for (let subtag of tag.asVec()) {
|
||||
if (subtag.startsWith("url")) {
|
||||
kind20image = subtag.slice(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let bech32id = evt.id.toBech32()
|
||||
let nip19 = new Nip19Event(evt.id, evt.author, store.state.relays)
|
||||
let nip19bech32 = nip19.toBech32()
|
||||
@ -406,7 +423,8 @@ async function listen() {
|
||||
boosts: react.reposts,
|
||||
boosted: react.repostedbyUser,
|
||||
replied: false,
|
||||
response: ref("")
|
||||
response: ref(""),
|
||||
kind20_image: kind20image
|
||||
|
||||
})
|
||||
index = index + 1
|
||||
|
@ -11,6 +11,8 @@ const StringUtil = {
|
||||
isValidUrl: (str: string): boolean => new RegExp(Regex_Url_Str, "i").test(str),
|
||||
parseHyperlinks: (str: string): string => str.replace(new RegExp(Regex_Urlw_Str, "gim"), "<a class='purple' target=\"_blank\" rel=\"noreferrer\" href=\"$&\">$&</a>").replace(new RegExp(Regex_Nip05_Str, "gim"), "<a class='purple' target=\"_blank\" rel=\"noreferrer\" href=\"https://njump.me/$&\">$&</a> "),
|
||||
parseImages: (str: string): string => str.toLowerCase().includes('nsfw') || str.toLowerCase().includes('lingerie') || str.toLowerCase().includes('sex') || str.toLowerCase().includes('porn') ? str.replace(" http", "\nhttp").replace(new RegExp(Regex_Url_Img, "gim"), "<details><summary class=\"collapse-title \"><div class=\"btn\">NSFW Show/Hide Results</div></summary><img src='$&'/></div></details> ").replace(new RegExp(Regex_Url_Video, "gim"), "<details><summary class=\"collapse-title \"><div class=\"btn\">NSFW Show/Hide Results</div><video controls muted autoplay src=\"$&\"></video></summary></details>").replace(new RegExp(Regex_Url_Str, "gim"), "<a class='purple' target=\"_blank\" rel=\"noreferrer\" href=\"$&\">$&</a> ") : str.replace(" http", "\nhttp").replace(new RegExp(Regex_Url_Img, "gim"), "<img src='$&'/> ").replace(new RegExp(Regex_Url_Video, "gim"), "<video controls muted autoplay src=\"$&\"></video> ").replace(new RegExp(Regex_Url_Str, "gim"), "<a class='purple' target=\"_blank\" rel=\"noreferrer\" href=\"$&\">$&</a> "),
|
||||
parseImages_save: (str: string): string => str.replace(" http", "\nhttp").replace(str, "<img src='$&'/> ").replace(new RegExp(Regex_Url_Video, "gim"), "<video controls muted autoplay src=\"$&\"></video> ").replace(new RegExp(Regex_Url_Str, "gim"), "<a class='purple' target=\"_blank\" rel=\"noreferrer\" href=\"$&\">$&</a> "),
|
||||
|
||||
|
||||
//parseImages: (str: string): string => str.replace(" http", "<br>http") //.replace("\n", " ").replace(new RegExp(Regex_Url_Img, "gim"), "<img src='$&'/> ")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user