mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-10-10 22:42:30 +02:00
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
from nostr_sdk import Tag, Keys, EventBuilder, Kind
|
|
|
|
from nostr_dvm.utils.definitions import EventDefinitions
|
|
from nostr_dvm.utils.dvmconfig import DVMConfig
|
|
from nostr_dvm.utils.nostr_utils import send_event
|
|
from nostr_dvm.utils.print_utils import bcolors
|
|
|
|
|
|
async def announce_dm_relays(dvm_config, client):
|
|
tags = []
|
|
relays_to_publish = DVMConfig.RELAY_LIST
|
|
|
|
for relay in dvm_config.RELAY_LIST:
|
|
if relay not in relays_to_publish:
|
|
relays_to_publish.append(relay)
|
|
|
|
for relay in relays_to_publish:
|
|
r_tag = Tag.parse(["r", relay])
|
|
tags.append(r_tag)
|
|
|
|
keys = Keys.parse(dvm_config.NIP89.PK)
|
|
content = ""
|
|
|
|
event = EventBuilder(Kind(10050), content).tags(tags).sign_with_keys(keys)
|
|
eventid = await send_event(event, client=client, dvm_config=dvm_config)
|
|
if eventid is not None:
|
|
print(
|
|
bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced DM relays for " + dvm_config.NIP89.NAME + " (EventID: " + str(
|
|
eventid.id.to_hex()) + ")" + bcolors.ENDC)
|
|
else:
|
|
print(
|
|
bcolors.RED + "[" + dvm_config.NIP89.NAME + "] Could not announce DM relays for " + dvm_config.NIP89.NAME + bcolors.ENDC)
|
|
|
|
|
|
async def nip65_announce_relays(dvm_config, client):
|
|
# todo we might want to call the dm relays seperately but for now we do it together with the inbox relays
|
|
await announce_dm_relays(dvm_config, client)
|
|
|
|
tags = []
|
|
|
|
relays_to_publish = DVMConfig.RELAY_LIST
|
|
|
|
for relay in dvm_config.RELAY_LIST:
|
|
if relay not in relays_to_publish:
|
|
relays_to_publish.append(relay)
|
|
|
|
|
|
for relay in relays_to_publish:
|
|
r_tag = Tag.parse(["r", relay])
|
|
tags.append(r_tag)
|
|
|
|
keys = Keys.parse(dvm_config.NIP89.PK)
|
|
content = ""
|
|
|
|
event = EventBuilder(EventDefinitions.KIND_RELAY_ANNOUNCEMENT, content).tags(tags).sign_with_keys(keys)
|
|
eventid = await send_event(event, client=client, dvm_config=dvm_config)
|
|
if eventid is not None:
|
|
print(
|
|
bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced NIP 65 for " + dvm_config.NIP89.NAME + " (EventID: " + str(
|
|
eventid.id.to_hex()) + ")" + bcolors.ENDC)
|
|
else:
|
|
print(
|
|
bcolors.RED + "[" + dvm_config.NIP89.NAME + "] Could not announce NIP 65 for " + dvm_config.NIP89.NAME + bcolors.ENDC)
|