Merge pull request #873 from PR0M3TH3AN/remove-unused-event-handler-5859192189539737629

Remove unused EventHandler class
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-16 12:47:25 -05:00
commit c6560305a9
2 files changed
-77

No files matched your search

-33
View File
@@ -1,33 +0,0 @@
# nostr/event_handler.py
import time
import logging
from nostr_sdk import Event
# Instantiate the logger
logger = logging.getLogger(__name__)
class EventHandler:
"""
Handles incoming Nostr events.
"""
def __init__(self):
pass # Initialize if needed
def handle_new_event(self, evt: Event):
"""Process and log details from a Nostr event."""
try:
created_at = evt.created_at().as_secs()
created_at_str = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(created_at))
event_id = evt.id().to_hex()
logger.info(
f"[New Event] ID: {event_id} | Created At: {created_at_str} | Content: {evt.content()}"
)
except Exception as e:
logger.error(f"Error handling new event: {e}", exc_info=True)
-44
View File
@@ -1,44 +0,0 @@
import logging
import time
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).resolve().parents[1]))
from nostr import event_handler
from nostr_sdk import EventBuilder, Keys
def test_handle_new_event_logs(caplog):
handler = event_handler.EventHandler()
keys = Keys.generate()
evt = EventBuilder.text_note("hello").sign_with_keys(keys)
caplog.set_level(logging.INFO, logger=event_handler.logger.name)
handler.handle_new_event(evt)
event_id = evt.id().to_hex()
created_at = evt.created_at().as_secs()
created_at_str = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(created_at))
assert (
f"[New Event] ID: {event_id} | Created At: {created_at_str} | Content: hello"
in caplog.text
)
def test_handle_new_event_error(monkeypatch, caplog):
handler = event_handler.EventHandler()
keys = Keys.generate()
evt = EventBuilder.text_note("boom").sign_with_keys(keys)
def raise_info(*args, **kwargs):
raise RuntimeError("fail")
monkeypatch.setattr(event_handler.logger, "info", raise_info)
caplog.set_level(logging.ERROR, logger=event_handler.logger.name)
handler.handle_new_event(evt)
assert "Error handling new event: fail" in caplog.text