mirror of
https://github.com/aljazceru/nostrdvm.git
synced 2025-12-23 17:04:27 +01:00
fixes for bot
This commit is contained in:
@@ -49,7 +49,7 @@ class Bot:
|
|||||||
wait_for_send = True
|
wait_for_send = True
|
||||||
skip_disconnected_relays = True
|
skip_disconnected_relays = True
|
||||||
opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||||
.skip_disconnected_relays(skip_disconnected_relays))
|
.skip_disconnected_relays(skip_disconnected_relays).gossip(True))
|
||||||
signer = NostrSigner.keys(self.keys)
|
signer = NostrSigner.keys(self.keys)
|
||||||
self.client = Client.with_opts(signer, opts)
|
self.client = Client.with_opts(signer, opts)
|
||||||
self.invoice_list = []
|
self.invoice_list = []
|
||||||
@@ -69,6 +69,10 @@ class Bot:
|
|||||||
|
|
||||||
for relay in self.dvm_config.RELAY_LIST:
|
for relay in self.dvm_config.RELAY_LIST:
|
||||||
await self.client.add_relay(relay)
|
await self.client.add_relay(relay)
|
||||||
|
|
||||||
|
await self.client.add_read_relay("wss://relay.nostr.band")
|
||||||
|
await self.client.add_read_relay("wss://relay.damus.io")
|
||||||
|
|
||||||
await self.client.connect()
|
await self.client.connect()
|
||||||
|
|
||||||
zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_ZAP]).since(Timestamp.now())
|
zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_ZAP]).since(Timestamp.now())
|
||||||
@@ -535,8 +539,6 @@ class Bot:
|
|||||||
self.dvm_config)
|
self.dvm_config)
|
||||||
|
|
||||||
etag = ""
|
etag = ""
|
||||||
print(zap_event.tags())
|
|
||||||
print(zapped_event.tags())
|
|
||||||
for tag in zapped_event.tags():
|
for tag in zapped_event.tags():
|
||||||
if tag.as_vec()[0] == "e":
|
if tag.as_vec()[0] == "e":
|
||||||
etag = tag.as_vec()[1]
|
etag = tag.as_vec()[1]
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ async def update_user_balance(db, npub, additional_sats, client, config, giftwra
|
|||||||
else:
|
else:
|
||||||
#await client.send_direct_msg(PublicKey.parse(npub), message, None)
|
#await client.send_direct_msg(PublicKey.parse(npub), message, None)
|
||||||
#await client.send_private_msg(PublicKey.parse(npub), message, None)
|
#await client.send_private_msg(PublicKey.parse(npub), message, None)
|
||||||
await send_nip04_dm(client, message, npub, config)
|
await send_nip04_dm(client, message, PublicKey.parse(npub), config)
|
||||||
|
|
||||||
|
|
||||||
def update_user_subscription(npub, subscribed_until, client, dvm_config):
|
def update_user_subscription(npub, subscribed_until, client, dvm_config):
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ class DVMConfig:
|
|||||||
LOGLEVEL = LogLevel.DEBUG
|
LOGLEVEL = LogLevel.DEBUG
|
||||||
KIND = None
|
KIND = None
|
||||||
|
|
||||||
|
DVM_KEY = None
|
||||||
|
CHATBOT = None
|
||||||
|
|
||||||
# Make sure you have the cashu library installed and built correctly on your system, before enableing nutzaps for a DVM
|
# Make sure you have the cashu library installed and built correctly on your system, before enableing nutzaps for a DVM
|
||||||
# this is not installed by default
|
# this is not installed by default
|
||||||
# pip install cashu. You might run into trouble with building secp256k1
|
# pip install cashu. You might run into trouble with building secp256k1
|
||||||
|
|||||||
@@ -12,31 +12,21 @@ from nostr_sdk import Filter, Client, Alphabet, EventId, Event, PublicKey, Tag,
|
|||||||
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout, relay_timeout_long
|
from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout, relay_timeout_long
|
||||||
|
|
||||||
|
|
||||||
async def get_event_by_id(event_id: str, client: Client, config=None) -> Event | None:
|
async def get_event_by_id(event_id_str: str, client: Client, config=None) -> Event | None:
|
||||||
split = event_id.split(":")
|
split = event_id_str.split(":")
|
||||||
if len(split) == 3:
|
if len(split) == 3:
|
||||||
pk = PublicKey.from_hex(split[1])
|
pk = PublicKey.from_hex(split[1])
|
||||||
id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]])
|
id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]])
|
||||||
events = await client.get_events_of([id_filter], relay_timeout)
|
events = await client.get_events_of([id_filter], relay_timeout)
|
||||||
else:
|
else:
|
||||||
if str(event_id).startswith('note'):
|
event_id = EventId.parse(event_id_str)
|
||||||
event_id = EventId.from_bech32(event_id)
|
|
||||||
elif str(event_id).startswith("nevent"):
|
|
||||||
event_id = Nip19Event.from_bech32(event_id).event_id()
|
|
||||||
elif str(event_id).startswith('nostr:note'):
|
|
||||||
event_id = EventId.from_nostr_uri(event_id)
|
|
||||||
elif str(event_id).startswith("nostr:nevent"):
|
|
||||||
event_id = Nip19Event.from_nostr_uri(event_id).event_id()
|
|
||||||
|
|
||||||
else:
|
|
||||||
event_id = EventId.from_hex(event_id)
|
|
||||||
|
|
||||||
id_filter = Filter().id(event_id).limit(1)
|
id_filter = Filter().id(event_id).limit(1)
|
||||||
|
|
||||||
events = await client.get_events_of([id_filter], relay_timeout)
|
events = await client.get_events_of([id_filter], relay_timeout)
|
||||||
|
|
||||||
|
|
||||||
if len(events) > 0:
|
if len(events) > 0:
|
||||||
|
|
||||||
return events[0]
|
return events[0]
|
||||||
else:
|
else:
|
||||||
print("Event not found")
|
print("Event not found")
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ async def parse_zap_event_tags(zap_event, keys, name, client, config):
|
|||||||
invoice_amount = parse_amount_from_bolt11_invoice(tag.as_vec()[1])
|
invoice_amount = parse_amount_from_bolt11_invoice(tag.as_vec()[1])
|
||||||
elif tag.as_vec()[0] == 'e':
|
elif tag.as_vec()[0] == 'e':
|
||||||
zapped_event = await get_event_by_id(tag.as_vec()[1], client=client, config=config)
|
zapped_event = await get_event_by_id(tag.as_vec()[1], client=client, config=config)
|
||||||
zapped_event = check_and_decrypt_own_tags(zapped_event, config)
|
if zapped_event is not None:
|
||||||
|
zapped_event = check_and_decrypt_own_tags(zapped_event, config)
|
||||||
elif tag.as_vec()[0] == 'p':
|
elif tag.as_vec()[0] == 'p':
|
||||||
p_tag = tag.as_vec()[1]
|
p_tag = tag.as_vec()[1]
|
||||||
elif tag.as_vec()[0] == 'description':
|
elif tag.as_vec()[0] == 'description':
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ def playground():
|
|||||||
identifier = "bot_test"
|
identifier = "bot_test"
|
||||||
bot_config.PRIVATE_KEY = check_and_set_private_key(identifier)
|
bot_config.PRIVATE_KEY = check_and_set_private_key(identifier)
|
||||||
npub = Keys.parse(bot_config.PRIVATE_KEY).public_key().to_bech32()
|
npub = Keys.parse(bot_config.PRIVATE_KEY).public_key().to_bech32()
|
||||||
invoice_key, admin_key, wallet_id, user_id, lnaddress = check_and_set_ln_bits_keys(identifier, npub)
|
invoice_key, admin_key, wallet_id, lnaddress = check_and_set_ln_bits_keys(identifier, npub)
|
||||||
bot_config.LN_ADDRESS = lnaddress
|
bot_config.LN_ADDRESS = lnaddress
|
||||||
bot_config.LNBITS_INVOICE_KEY = invoice_key
|
bot_config.LNBITS_INVOICE_KEY = invoice_key
|
||||||
bot_config.LNBITS_ADMIN_KEY = admin_key # The dvm might pay failed jobs back
|
bot_config.LNBITS_ADMIN_KEY = admin_key # The dvm might pay failed jobs back
|
||||||
|
|||||||
Reference in New Issue
Block a user