From ccf620d4765dfebc7af5d9fa1ba0a143b99876b9 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 6 Apr 2023 18:14:35 +0300 Subject: [PATCH] feat: check `account` for `REQ` --- relay/client_connection.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/relay/client_connection.py b/relay/client_connection.py index 23a8738..17c5348 100644 --- a/relay/client_connection.py +++ b/relay/client_connection.py @@ -8,8 +8,10 @@ from loguru import logger from lnbits.helpers import urlsafe_short_hash from ..crud import ( + NostrAccount, create_event, delete_events, + get_account, get_event, get_events, mark_events_deleted, @@ -189,6 +191,20 @@ class NostrClientConnection: if self.config.require_auth_filter: if not self.auth_pubkey: return [["AUTH", self._current_auth_challenge()]] + account = await get_account(self.relay_id, self.auth_pubkey) + if not account: + account = NostrAccount.null_account() + + if account.blocked: + return [ + [ + "NOTICE", + f"Public key '{self.auth_pubkey}' is not allowed in relay '{self.relay_id}'!", + ] + ] + + if not account.can_join and not self.config.is_free_to_join: + return [["NOTICE", f"This is a paid relay: '{self.relay_id}'"]] filter.subscription_id = subscription_id self._remove_filter(subscription_id)