mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-09-25 13:41:00 +02:00
Update bot.py
This commit is contained in:
@@ -5,7 +5,7 @@ import signal
|
|||||||
|
|
||||||
from nostr_sdk import (Keys, Timestamp, Filter, nip04_decrypt, nip44_decrypt, HandleNotification, EventBuilder, PublicKey,
|
from nostr_sdk import (Keys, Timestamp, Filter, nip04_decrypt, nip44_decrypt, HandleNotification, EventBuilder, PublicKey,
|
||||||
Options, Tag, Event, EventId, Nip19Event, Kind, NostrSigner, nip44_encrypt, Nip44Version,
|
Options, Tag, Event, EventId, Nip19Event, Kind, NostrSigner, nip44_encrypt, Nip44Version,
|
||||||
UnsignedEvent, UnwrappedGift, uniffi_set_event_loop, ClientBuilder, make_private_msg)
|
UnsignedEvent, UnwrappedGift, KindStandard, ClientBuilder, make_private_msg)
|
||||||
|
|
||||||
from nostr_dvm.utils.admin_utils import admin_make_database_updates
|
from nostr_dvm.utils.admin_utils import admin_make_database_updates
|
||||||
from nostr_dvm.utils.cashu_utils import redeem_cashu
|
from nostr_dvm.utils.cashu_utils import redeem_cashu
|
||||||
@@ -73,7 +73,7 @@ class Bot:
|
|||||||
|
|
||||||
zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_ZAP]).since(Timestamp.now())
|
zap_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_ZAP]).since(Timestamp.now())
|
||||||
dm_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_DM]).since(Timestamp.now())
|
dm_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_DM]).since(Timestamp.now())
|
||||||
nip17_filter = Filter().pubkey(pk).kinds([EventDefinitions.KIND_GIFTWRAP]).limit(0)
|
nip59_filter = Filter().pubkey(pk).kind(Kind.from_std(KindStandard.GIFT_WRAP)).limit(0)
|
||||||
kinds = [EventDefinitions.KIND_NIP90_GENERIC, EventDefinitions.KIND_FEEDBACK]
|
kinds = [EventDefinitions.KIND_NIP90_GENERIC, EventDefinitions.KIND_FEEDBACK]
|
||||||
for dvm in self.dvm_config.SUPPORTED_DVMS:
|
for dvm in self.dvm_config.SUPPORTED_DVMS:
|
||||||
if dvm.KIND not in kinds:
|
if dvm.KIND not in kinds:
|
||||||
@@ -84,7 +84,7 @@ class Bot:
|
|||||||
|
|
||||||
await self.client.subscribe(zap_filter, None)
|
await self.client.subscribe(zap_filter, None)
|
||||||
await self.client.subscribe(dm_filter, None)
|
await self.client.subscribe(dm_filter, None)
|
||||||
await self.client.subscribe(nip17_filter, None)
|
await self.client.subscribe(nip59_filter, None)
|
||||||
await self.client.subscribe(dvm_filter, None)
|
await self.client.subscribe(dvm_filter, None)
|
||||||
|
|
||||||
create_sql_table(self.dvm_config.DB)
|
create_sql_table(self.dvm_config.DB)
|
||||||
@@ -110,7 +110,8 @@ class Bot:
|
|||||||
await handle_dm(nostr_event, False)
|
await handle_dm(nostr_event, False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error during content NIP04 decryption: {e}")
|
print(f"Error during content NIP04 decryption: {e}")
|
||||||
elif nostr_event.kind().as_u16() == EventDefinitions.KIND_GIFTWRAP.as_u16():
|
elif nostr_event.kind().as_std() == KindStandard.GIFT_WRAP:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await handle_dm(nostr_event, True)
|
await handle_dm(nostr_event, True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -128,24 +129,25 @@ class Bot:
|
|||||||
try:
|
try:
|
||||||
sealed = " "
|
sealed = " "
|
||||||
if giftwrap:
|
if giftwrap:
|
||||||
|
signer = NostrSigner.keys(self.keys)
|
||||||
|
if nostr_event.kind().as_std() == KindStandard.GIFT_WRAP:
|
||||||
|
print("Decrypting NIP59 event")
|
||||||
try:
|
try:
|
||||||
# Extract rumor
|
# Extract rumor
|
||||||
unwrapped_gift = await UnwrappedGift.from_gift_wrap(NostrSigner.keys(self.keys), nostr_event)
|
unwrapped_gift = await UnwrappedGift.from_gift_wrap(signer, nostr_event)
|
||||||
sender = unwrapped_gift.sender().to_hex()
|
sender = unwrapped_gift.sender().to_hex()
|
||||||
rumor: UnsignedEvent = unwrapped_gift.rumor()
|
rumor: UnsignedEvent = unwrapped_gift.rumor()
|
||||||
|
|
||||||
|
# Check timestamp of rumor
|
||||||
if rumor.created_at().as_secs() >= Timestamp.now().as_secs():
|
if rumor.created_at().as_secs() >= Timestamp.now().as_secs():
|
||||||
if rumor.kind().as_u16() == EventDefinitions.KIND_PRIVATE_DM.as_u16():
|
if rumor.kind().as_std() == KindStandard.PRIVATE_DIRECT_MESSAGE:
|
||||||
print(f"Received new msg [sealed]: {decrypted_text}")
|
|
||||||
decrypted_text = rumor.content()
|
decrypted_text = rumor.content()
|
||||||
sealed = " [sealed] "
|
|
||||||
else:
|
else:
|
||||||
print(f"{rumor.as_json()}")
|
print(f"{rumor.as_json()}")
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error during content NIP59 decryption: {e}")
|
print(f"Error during content NIP59 decryption: {e}")
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
decrypted_text = nip04_decrypt(self.keys.secret_key(), nostr_event.author(),
|
decrypted_text = nip04_decrypt(self.keys.secret_key(), nostr_event.author(),
|
||||||
|
Reference in New Issue
Block a user