From 88e947beb9444671b6693912c54559fa92e4c191 Mon Sep 17 00:00:00 2001 From: Capybara-z Date: Mon, 20 Apr 2026 22:35:46 +0000 Subject: [PATCH] Redis pool limit / Systemd killmode / Devices plural --- bot.py | 1 + cli_launcher.py | 4 +++- handlers/tariffs/addons/key_addons_main.py | 4 ++-- handlers/tariffs/addons/key_addons_pack.py | 4 ++-- handlers/tariffs/addons/utils.py | 3 ++- handlers/tariffs/buy/key_tariffs.py | 13 ++++++++----- main.py | 0 7 files changed, 18 insertions(+), 11 deletions(-) mode change 100644 => 100755 main.py diff --git a/bot.py b/bot.py index 8079ea4c..f6aae335 100644 --- a/bot.py +++ b/bot.py @@ -27,6 +27,7 @@ redis = redis_from_url( REDIS_URL, encoding="utf-8", decode_responses=True, + max_connections=64, health_check_interval=30, socket_connect_timeout=5, socket_timeout=5, diff --git a/cli_launcher.py b/cli_launcher.py index 61093a34..8cb626e4 100755 --- a/cli_launcher.py +++ b/cli_launcher.py @@ -402,7 +402,9 @@ def build_systemd_service() -> str: f"WorkingDirectory={PROJECT_DIR}\n" f"ExecStart={VENV_PYTHON} {os.path.join(PROJECT_DIR, 'main.py')}\n" "Restart=always\n" - "RestartSec=5\n" + "RestartSec=10\n" + "TimeoutStopSec=10\n" + "KillMode=control-group\n" 'Environment="PYTHONUNBUFFERED=1"\n\n' "[Install]\n" "WantedBy=multi-user.target\n" diff --git a/handlers/tariffs/addons/key_addons_main.py b/handlers/tariffs/addons/key_addons_main.py index 564b1524..ed87f386 100644 --- a/handlers/tariffs/addons/key_addons_main.py +++ b/handlers/tariffs/addons/key_addons_main.py @@ -28,7 +28,7 @@ from handlers.texts import ( UNLIMITED_DEVICES_LABEL, UNLIMITED_TRAFFIC_LABEL, ) -from handlers.utils import edit_or_send_message +from handlers.utils import edit_or_send_message, get_plural_form from hooks.hook_buttons import insert_hook_buttons from hooks.processors import process_addon_purchase_complete, process_addons_menu from logger import logger @@ -236,7 +236,7 @@ async def render_addons_screen(callback: CallbackQuery, state: FSMContext, sessi if value == 0: caption = f"{UNLIMITED_DEVICES_LABEL.capitalize()}{mark}" else: - caption = f"{value} устройств{mark}" + caption = f"{value} {get_plural_form(value, 'устройство', 'устройства', 'устройств')}{mark}" device_buttons.append( InlineKeyboardButton( text=caption, diff --git a/handlers/tariffs/addons/key_addons_pack.py b/handlers/tariffs/addons/key_addons_pack.py index 6d2e4a5b..eed89978 100644 --- a/handlers/tariffs/addons/key_addons_pack.py +++ b/handlers/tariffs/addons/key_addons_pack.py @@ -29,7 +29,7 @@ from handlers.texts import ( UNLIMITED_DEVICES_LABEL, UNLIMITED_TRAFFIC_LABEL, ) -from handlers.utils import edit_or_send_message +from handlers.utils import edit_or_send_message, get_plural_form from hooks.hook_buttons import insert_hook_buttons from hooks.processors import process_addon_purchase_complete, process_addons_menu from logger import logger @@ -324,7 +324,7 @@ async def render_addons_screen(callback: CallbackQuery, state: FSMContext, sessi if value == 0: caption = f"{UNLIMITED_DEVICES_LABEL.capitalize()}{mark}" else: - caption = f"{value} устройств{mark}" + caption = f"{value} {get_plural_form(value, 'устройство', 'устройства', 'устройств')}{mark}" device_buttons.append( InlineKeyboardButton( text=caption, diff --git a/handlers/tariffs/addons/utils.py b/handlers/tariffs/addons/utils.py index 98c3119a..4536f17d 100644 --- a/handlers/tariffs/addons/utils.py +++ b/handlers/tariffs/addons/utils.py @@ -3,6 +3,7 @@ from typing import Any from aiogram.fsm.state import State, StatesGroup +from handlers.utils import get_plural_form from handlers.texts import ( ADDONS_CURRENT_HEADER_TEXT, ADDONS_HINT_BOTH_OPTIONS_TEXT, @@ -39,7 +40,7 @@ def format_devices_label(value, default_text: str = "по умолчанию") - value_int = int(value) if value_int <= 0: return UNLIMITED_DEVICES_LABEL - return f"{value_int} устройств" + return f"{value_int} {get_plural_form(value_int, 'устройство', 'устройства', 'устройств')}" def format_traffic_label(value, default_text: str = "по умолчанию") -> str: diff --git a/handlers/tariffs/buy/key_tariffs.py b/handlers/tariffs/buy/key_tariffs.py index 35d85294..dbc6797c 100644 --- a/handlers/tariffs/buy/key_tariffs.py +++ b/handlers/tariffs/buy/key_tariffs.py @@ -23,7 +23,7 @@ from handlers.texts import ( UNLIMITED_DEVICES_LABEL, UNLIMITED_TRAFFIC_LABEL, ) -from handlers.utils import edit_or_send_message, safe_answer_callback +from handlers.utils import edit_or_send_message, get_plural_form, safe_answer_callback from hooks.processors import process_check_discount_validity from logger import logger from services.payments.currency_rates import format_for_user @@ -430,7 +430,8 @@ async def render_user_config_screen( if int(base_device) <= 0: base_devices_label = UNLIMITED_DEVICES_LABEL else: - base_devices_label = f"{int(base_device)} устройств" + _bd = int(base_device) + base_devices_label = f"{_bd} {get_plural_form(_bd, 'устройство', 'устройства', 'устройств')}" base_parts.append(base_devices_label) if base_traffic_gb is not None: @@ -454,7 +455,8 @@ async def render_user_config_screen( if int(selected_devices) <= 0: devices_label = UNLIMITED_DEVICES_LABEL else: - devices_label = f"{int(selected_devices)} устройств" + _sd = int(selected_devices) + devices_label = f"{_sd} {get_plural_form(_sd, 'устройство', 'устройства', 'устройств')}" choice_parts.append(devices_label) if has_traffic_choice: @@ -480,7 +482,8 @@ async def render_user_config_screen( _rs_trf = data.get("renew_selected_traffic_limit") _addon_parts: list[str] = [] if _rc_dev is not None and _rs_dev is not None and int(_rc_dev) > int(_rs_dev): - _addon_parts.append(f"+{int(_rc_dev) - int(_rs_dev)} устройств") + _diff_dev = int(_rc_dev) - int(_rs_dev) + _addon_parts.append(f"+{_diff_dev} {get_plural_form(_diff_dev, 'устройство', 'устройства', 'устройств')}") if _rc_trf is not None and _rs_trf is not None and int(_rc_trf) > int(_rs_trf): _addon_parts.append(f"+{int(_rc_trf) - int(_rs_trf)} ГБ") if _addon_parts: @@ -505,7 +508,7 @@ async def render_user_config_screen( if value == 0: caption = f"{UNLIMITED_DEVICES_LABEL.capitalize()}{mark}" else: - caption = f"{value} устройств{mark}" + caption = f"{value} {get_plural_form(value, 'устройство', 'устройства', 'устройств')}{mark}" device_buttons.append( InlineKeyboardButton( text=caption, diff --git a/main.py b/main.py old mode 100644 new mode 100755