add user message hook system / fix SSL certificate validation

This commit is contained in:
Capybara-z
2025-08-15 15:44:07 +03:00
parent 8597eed42d
commit 2a3f346434
2 changed files with 20 additions and 8 deletions
+14
View File
@@ -5,6 +5,8 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
from config import SUPPORT_CHAT_URL
from handlers.buttons import MAIN_MENU, SUPPORT
from handlers.texts import FALLBACK_MESSAGE
from hooks.hooks import run_hooks
from database import async_session_maker
fallback_router = Router()
@@ -12,6 +14,18 @@ fallback_router = Router()
@fallback_router.message(F.text)
async def handle_unhandled_messages(message: Message):
async with async_session_maker() as session:
await run_hooks(
"user_message",
user_id=message.from_user.id,
message_text=message.text,
username=message.from_user.username,
first_name=message.from_user.first_name,
last_name=message.from_user.last_name,
session=session,
message=message
)
keyboard = InlineKeyboardBuilder()
keyboard.row(InlineKeyboardButton(text=SUPPORT, url=SUPPORT_CHAT_URL))
keyboard.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
+6 -8
View File
@@ -43,14 +43,12 @@ async def check_tcp_connection(host: str, port: int) -> bool:
await writer.wait_closed()
return True
except ssl.SSLError as e:
err_text = str(e)
if ("hostname mismatch" in err_text or
"certificate is not valid for" in err_text or
"sslv3 alert handshake failure" in err_text):
return True
logger.warning(f"[SSL Error] Сертификат сервера {host} вызвал ошибку: {e}")
await notify_ssl_error(host, err_text)
return False
err_text = str(e).lower()
if "certificate has expired" in err_text:
logger.warning(f"[SSL Error] Сертификат сервера {host} просрочен: {e}")
await notify_ssl_error(host, str(e))
return False
return True
except Exception:
return False