mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-18 05:41:51 +01:00
added examples for nwc (currently not yet used by the framework)
This commit is contained in:
parent
b9a8e22b41
commit
225981eea3
@ -100,7 +100,9 @@ class TextToSpeech(DVMTaskInterface):
|
||||
|
||||
print(TTS().list_models())
|
||||
try:
|
||||
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
||||
model = "tts_models/multilingual/multi-dataset/your_tts"
|
||||
#model = "tts_models/multilingual/multi-dataset/xtts_v2"
|
||||
tts = TTS(model).to(device)
|
||||
|
||||
tts.tts_to_file(
|
||||
text=options["prompt"],
|
||||
|
86
nostr_dvm/utils/nwc_tools.py
Normal file
86
nostr_dvm/utils/nwc_tools.py
Normal file
@ -0,0 +1,86 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import requests
|
||||
from nostr_sdk import Keys, PublicKey, Client, nip04_encrypt, EventBuilder, Tag
|
||||
|
||||
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 zaprequest
|
||||
|
||||
|
||||
def nwc_zap(connectionstr, bolt11, keys):
|
||||
target_pubkey, relay, secret = parse_connection_str(connectionstr)
|
||||
SecretSK = Keys.from_sk_str(secret)
|
||||
|
||||
content = {
|
||||
"method": "pay_invoice",
|
||||
"params": {
|
||||
"invoice": bolt11
|
||||
}
|
||||
}
|
||||
|
||||
client = Client(keys)
|
||||
client.add_relay(relay)
|
||||
client.connect()
|
||||
|
||||
client_public_key = PublicKey.from_hex(target_pubkey)
|
||||
encrypted_content = nip04_encrypt(SecretSK.secret_key(), client_public_key, json.dumps(content))
|
||||
|
||||
pTag = Tag.parse(["p", client_public_key.to_hex()])
|
||||
event = EventBuilder(23194, encrypted_content,
|
||||
[pTag]).to_event(keys)
|
||||
|
||||
event_id = client.send_event(event)
|
||||
print(event_id.to_hex())
|
||||
|
||||
|
||||
def parse_connection_str(connectionstring):
|
||||
split = connectionstring.split("?")
|
||||
targetpubkey = split[0].split(":")[1]
|
||||
split2 = split[1].split("&")
|
||||
relay = split2[0].split("=")[1]
|
||||
relay = relay.replace("%3A%2F%2F", "://")
|
||||
secret = split2[1].split("=")[1]
|
||||
return targetpubkey, relay, secret
|
||||
|
||||
|
||||
def make_nwc_account(identifier, nwcdomain):
|
||||
pubkey = Keys.from_sk_str(os.getenv("DVM_PRIVATE_KEY_" + identifier.upper())).public_key().to_hex()
|
||||
data = {
|
||||
'name': identifier,
|
||||
'host': os.getenv("LNBITS_HOST"),
|
||||
'key': os.getenv("LNBITS_ADMIN_KEY_" + identifier.upper()),
|
||||
'pubkey': pubkey,
|
||||
}
|
||||
|
||||
try:
|
||||
url = nwcdomain
|
||||
header = {"content-type": "application/json"}
|
||||
res = requests.post(url, headers=header, json=data)
|
||||
obj = json.loads(res.text)
|
||||
if obj['params']['connectionURI'] != "Users already exists":
|
||||
return obj['params']['connectionURI']
|
||||
else:
|
||||
return ""
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return ""
|
||||
|
||||
|
||||
def nwc_test(nwc_server):
|
||||
connectionstring = make_nwc_account("test", nwc_server + "/api/new")
|
||||
print(connectionstring)
|
||||
# TODO Store the connection string in a db, use here if you already have one
|
||||
# connectionstring = "nostr+walletconnect:..."
|
||||
if connectionstring != "":
|
||||
# we use the keys from a test user
|
||||
keys = Keys.from_sk_str(check_and_set_private_key("test"))
|
||||
|
||||
# we zap npub1nxa4tywfz9nqp7z9zp7nr7d4nchhclsf58lcqt5y782rmf2hefjquaa6q8's profile 21 sats and say Cool stuff
|
||||
pubkey = PublicKey.from_bech32("npub1nxa4tywfz9nqp7z9zp7nr7d4nchhclsf58lcqt5y782rmf2hefjquaa6q8")
|
||||
bolt11 = zaprequest("hype@bitcoinfixesthis.org", 21, "Cool Stuff", None,
|
||||
pubkey, keys, DVMConfig.RELAY_LIST)
|
||||
|
||||
nwc_zap(connectionstring, bolt11, keys)
|
Loading…
x
Reference in New Issue
Block a user