mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-06-06 04:39:13 +02:00
make nip89 events deleteable
This commit is contained in:
parent
d912a49ecd
commit
e51d8c7de3
@ -1,12 +1,14 @@
|
|||||||
# ADMINISTRARIVE DB MANAGEMENT
|
# ADMINISTRARIVE DB MANAGEMENT
|
||||||
import time
|
import time
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from nostr_sdk import Keys, EventBuilder, PublicKey
|
from nostr_sdk import Keys, EventBuilder, PublicKey, Client, Filter, EventId
|
||||||
|
|
||||||
from utils.database_utils import get_from_sql_table, list_db, delete_from_sql_table, update_sql_table, \
|
from utils.database_utils import get_from_sql_table, list_db, delete_from_sql_table, update_sql_table, \
|
||||||
get_or_add_user, clean_db
|
get_or_add_user, clean_db
|
||||||
from utils.dvmconfig import DVMConfig
|
from utils.dvmconfig import DVMConfig
|
||||||
from utils.nip89_utils import nip89_announce_tasks, NIP89Config, nip89_delete_announcement
|
from utils.nip89_utils import nip89_announce_tasks, NIP89Config, nip89_delete_announcement, \
|
||||||
|
fetch_nip89_paramters_for_deletion
|
||||||
from utils.nostr_utils import send_event, update_profile
|
from utils.nostr_utils import send_event, update_profile
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +26,7 @@ class AdminConfig:
|
|||||||
LUD16: str = ""
|
LUD16: str = ""
|
||||||
|
|
||||||
|
|
||||||
def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMConfig = None, client=None):
|
def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMConfig = None, client: Client = None):
|
||||||
# This is called on start of Server, Admin function to manually whitelist/blacklist/add balance/delete users
|
# This is called on start of Server, Admin function to manually whitelist/blacklist/add balance/delete users
|
||||||
if adminconfig is None or dvmconfig is None:
|
if adminconfig is None or dvmconfig is None:
|
||||||
return
|
return
|
||||||
@ -32,7 +34,8 @@ def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMC
|
|||||||
if not isinstance(adminconfig, AdminConfig):
|
if not isinstance(adminconfig, AdminConfig):
|
||||||
return
|
return
|
||||||
|
|
||||||
if ((adminconfig.WHITELISTUSER is True or adminconfig.UNWHITELISTUSER is True or adminconfig.BLACKLISTUSER is True or adminconfig.DELETEUSER is True)
|
if ((
|
||||||
|
adminconfig.WHITELISTUSER is True or adminconfig.UNWHITELISTUSER is True or adminconfig.BLACKLISTUSER is True or adminconfig.DELETEUSER is True)
|
||||||
and adminconfig.USERNPUB == ""):
|
and adminconfig.USERNPUB == ""):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -52,7 +55,6 @@ def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMC
|
|||||||
user = get_from_sql_table(db, publickey)
|
user = get_from_sql_table(db, publickey)
|
||||||
print(str(user.name) + " is whitelisted: " + str(user.iswhitelisted))
|
print(str(user.name) + " is whitelisted: " + str(user.iswhitelisted))
|
||||||
|
|
||||||
|
|
||||||
if adminconfig.UNWHITELISTUSER:
|
if adminconfig.UNWHITELISTUSER:
|
||||||
user = get_from_sql_table(db, publickey)
|
user = get_from_sql_table(db, publickey)
|
||||||
update_sql_table(db, user.npub, user.balance, False, False, user.nip05, user.lud16, user.name, user.lastactive)
|
update_sql_table(db, user.npub, user.balance, False, False, user.nip05, user.lud16, user.name, user.lastactive)
|
||||||
@ -76,15 +78,9 @@ def admin_make_database_updates(adminconfig: AdminConfig = None, dvmconfig: DVMC
|
|||||||
# TODO make this callable
|
# TODO make this callable
|
||||||
delete_previous_announcement = False
|
delete_previous_announcement = False
|
||||||
if delete_previous_announcement:
|
if delete_previous_announcement:
|
||||||
# privkey from sender
|
eventid = "" #Id of Event to delete
|
||||||
keys = Keys.from_sk_str("")
|
keys = Keys.from_sk_str("") # Private key from sender of Event (e.g. the key of an nip89 announcement you want to delete)
|
||||||
print("Pubkey generated from Private Key " + keys.public_key().to_hex())
|
fetch_nip89_paramters_for_deletion(keys, eventid, client, dvmconfig)
|
||||||
|
|
||||||
print("Pubkey of Event: " + "") #pubkey from event, to compare to given privkey
|
|
||||||
dtag = "" #dtag from event
|
|
||||||
event_id = "" #id of event
|
|
||||||
nip89_delete_announcement(event_id, keys, dtag, client, dvmconfig)
|
|
||||||
|
|
||||||
if adminconfig.UPDATE_PROFILE:
|
if adminconfig.UPDATE_PROFILE:
|
||||||
update_profile(dvmconfig, lud16=adminconfig.LUD16)
|
update_profile(dvmconfig, lud16=adminconfig.LUD16)
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@ class DVMConfig:
|
|||||||
|
|
||||||
RELAY_LIST = ["wss://relay.damus.io", "wss://nostr-pub.wellorder.net", "wss://nos.lol", "wss://nostr.wine",
|
RELAY_LIST = ["wss://relay.damus.io", "wss://nostr-pub.wellorder.net", "wss://nos.lol", "wss://nostr.wine",
|
||||||
"wss://relay.nostfiles.dev", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
"wss://relay.nostfiles.dev", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||||
"wss://relay.f7z.io"]
|
"wss://relay.f7z.io", "wss://pablof7z.nostr1.com", "wss://purplepag.es", "wss://nos.lol",
|
||||||
|
"wss://relay.snort.social", "wss://offchain.pub/",
|
||||||
|
"wss://nostr-pub.wellorder.net"]
|
||||||
|
|
||||||
RELAY_TIMEOUT = 3
|
RELAY_TIMEOUT = 3
|
||||||
LNBITS_INVOICE_KEY = ''
|
LNBITS_INVOICE_KEY = ''
|
||||||
|
@ -4,7 +4,7 @@ from hashlib import sha256
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import dotenv
|
import dotenv
|
||||||
from nostr_sdk import Tag, Keys, EventBuilder, Filter, Alphabet, PublicKey, Event, Client
|
from nostr_sdk import Tag, Keys, EventBuilder, Filter, Alphabet, PublicKey, Event, Client, EventId
|
||||||
|
|
||||||
from utils.definitions import EventDefinitions
|
from utils.definitions import EventDefinitions
|
||||||
from utils.nostr_utils import send_event
|
from utils.nostr_utils import send_event
|
||||||
@ -34,6 +34,28 @@ def nip89_announce_tasks(dvm_config, client):
|
|||||||
print("Announced NIP 89 for " + dvm_config.NIP89.NAME)
|
print("Announced NIP 89 for " + dvm_config.NIP89.NAME)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_nip89_paramters_for_deletion( keys, eventid, client, dvmconfig):
|
||||||
|
|
||||||
|
print("Pubkey generated from Private Key " + keys.public_key().to_hex())
|
||||||
|
idfilter = Filter().id(EventId.from_hex(eventid)).limit(1)
|
||||||
|
nip89events = client.get_events_of([idfilter], timedelta(seconds=dvmconfig.RELAY_TIMEOUT))
|
||||||
|
d_tag = ""
|
||||||
|
for event in nip89events:
|
||||||
|
print(event.as_json())
|
||||||
|
for tag in event.tags():
|
||||||
|
if tag.as_vec()[0] == "d":
|
||||||
|
d_tag = tag.as_vec()[1]
|
||||||
|
if d_tag == "":
|
||||||
|
print("No dtag found")
|
||||||
|
return
|
||||||
|
|
||||||
|
pubkey = event.pubkey().to_hex()
|
||||||
|
print("Pubkey of Event: " + pubkey)
|
||||||
|
event_id = event.id().to_hex()
|
||||||
|
nip89_delete_announcement(event_id, keys, d_tag, client, dvmconfig)
|
||||||
|
print("NIP89 announcement deleted from known relays!")
|
||||||
|
|
||||||
def nip89_delete_announcement(eid: str, keys: Keys, dtag: str, client: Client, config):
|
def nip89_delete_announcement(eid: str, keys: Keys, dtag: str, client: Client, config):
|
||||||
e_tag = Tag.parse(["e", eid])
|
e_tag = Tag.parse(["e", eid])
|
||||||
a_tag = Tag.parse(["a", str(EventDefinitions.KIND_ANNOUNCEMENT) + ":" + keys.public_key().to_hex() + ":" + dtag])
|
a_tag = Tag.parse(["a", str(EventDefinitions.KIND_ANNOUNCEMENT) + ":" + keys.public_key().to_hex() + ":" + dtag])
|
||||||
|
@ -72,10 +72,9 @@ def send_event(event: Event, client: Client, dvm_config) -> EventId:
|
|||||||
|
|
||||||
def check_and_decrypt_tags(event, dvm_config):
|
def check_and_decrypt_tags(event, dvm_config):
|
||||||
try:
|
try:
|
||||||
tags = []
|
|
||||||
is_encrypted = False
|
is_encrypted = False
|
||||||
p = ""
|
p = ""
|
||||||
sender = event.pubkey()
|
|
||||||
for tag in event.tags():
|
for tag in event.tags():
|
||||||
if tag.as_vec()[0] == 'encrypted':
|
if tag.as_vec()[0] == 'encrypted':
|
||||||
is_encrypted = True
|
is_encrypted = True
|
||||||
@ -106,10 +105,8 @@ def check_and_decrypt_tags(event, dvm_config):
|
|||||||
|
|
||||||
def check_and_decrypt_own_tags(event, dvm_config):
|
def check_and_decrypt_own_tags(event, dvm_config):
|
||||||
try:
|
try:
|
||||||
tags = []
|
|
||||||
is_encrypted = False
|
is_encrypted = False
|
||||||
p = ""
|
p = ""
|
||||||
sender = event.pubkey()
|
|
||||||
for tag in event.tags():
|
for tag in event.tags():
|
||||||
if tag.as_vec()[0] == 'encrypted':
|
if tag.as_vec()[0] == 'encrypted':
|
||||||
is_encrypted = True
|
is_encrypted = True
|
||||||
@ -187,6 +184,3 @@ def add_pk_to_env_file(dtag, oskey):
|
|||||||
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
||||||
dotenv.set_key(env_path, dtag, oskey)
|
dotenv.set_key(env_path, dtag, oskey)
|
||||||
|
|
||||||
|
|
||||||
def generate_private_key():
|
|
||||||
return Keys.generate()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user