mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-22 12:26:56 +01:00
fixes for bot
This commit is contained in:
@@ -49,7 +49,7 @@ class Bot:
|
||||
wait_for_send = True
|
||||
skip_disconnected_relays = True
|
||||
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)
|
||||
self.client = Client.with_opts(signer, opts)
|
||||
self.invoice_list = []
|
||||
@@ -69,6 +69,10 @@ class Bot:
|
||||
|
||||
for relay in self.dvm_config.RELAY_LIST:
|
||||
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()
|
||||
|
||||
zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_ZAP]).since(Timestamp.now())
|
||||
@@ -535,8 +539,6 @@ class Bot:
|
||||
self.dvm_config)
|
||||
|
||||
etag = ""
|
||||
print(zap_event.tags())
|
||||
print(zapped_event.tags())
|
||||
for tag in zapped_event.tags():
|
||||
if tag.as_vec()[0] == "e":
|
||||
etag = tag.as_vec()[1]
|
||||
|
||||
@@ -200,7 +200,7 @@ async def update_user_balance(db, npub, additional_sats, client, config, giftwra
|
||||
else:
|
||||
#await client.send_direct_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):
|
||||
|
||||
@@ -60,6 +60,9 @@ class DVMConfig:
|
||||
LOGLEVEL = LogLevel.DEBUG
|
||||
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
|
||||
# this is not installed by default
|
||||
# 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
|
||||
|
||||
|
||||
async def get_event_by_id(event_id: str, client: Client, config=None) -> Event | None:
|
||||
split = event_id.split(":")
|
||||
async def get_event_by_id(event_id_str: str, client: Client, config=None) -> Event | None:
|
||||
split = event_id_str.split(":")
|
||||
if len(split) == 3:
|
||||
pk = PublicKey.from_hex(split[1])
|
||||
id_filter = Filter().author(pk).custom_tag(SingleLetterTag.lowercase(Alphabet.D), [split[2]])
|
||||
events = await client.get_events_of([id_filter], relay_timeout)
|
||||
else:
|
||||
if str(event_id).startswith('note'):
|
||||
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)
|
||||
event_id = EventId.parse(event_id_str)
|
||||
|
||||
id_filter = Filter().id(event_id).limit(1)
|
||||
|
||||
events = await client.get_events_of([id_filter], relay_timeout)
|
||||
|
||||
|
||||
if len(events) > 0:
|
||||
|
||||
return events[0]
|
||||
else:
|
||||
print("Event not found")
|
||||
|
||||
@@ -39,6 +39,7 @@ async def parse_zap_event_tags(zap_event, keys, name, client, config):
|
||||
invoice_amount = parse_amount_from_bolt11_invoice(tag.as_vec()[1])
|
||||
elif tag.as_vec()[0] == 'e':
|
||||
zapped_event = await get_event_by_id(tag.as_vec()[1], client=client, config=config)
|
||||
if zapped_event is not None:
|
||||
zapped_event = check_and_decrypt_own_tags(zapped_event, config)
|
||||
elif tag.as_vec()[0] == 'p':
|
||||
p_tag = tag.as_vec()[1]
|
||||
|
||||
@@ -25,7 +25,7 @@ def playground():
|
||||
identifier = "bot_test"
|
||||
bot_config.PRIVATE_KEY = check_and_set_private_key(identifier)
|
||||
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.LNBITS_INVOICE_KEY = invoice_key
|
||||
bot_config.LNBITS_ADMIN_KEY = admin_key # The dvm might pay failed jobs back
|
||||
|
||||
Reference in New Issue
Block a user