diff --git a/handlers/admin/clusters/clusters_handler.py b/handlers/admin/clusters/clusters_handler.py index d472a27b..e16e224e 100644 --- a/handlers/admin/clusters/clusters_handler.py +++ b/handlers/admin/clusters/clusters_handler.py @@ -310,9 +310,6 @@ async def handle_cluster_availability( total_online_users = 0 result_text = f"🖥️ Проверка доступности серверов\n\n⚙️ Кластер: {cluster_name}\n\n" - now = datetime.utcnow() - start_time = now - timedelta(minutes=5) - for server in cluster_servers: server_name = server["server_name"] panel_type = server.get("panel_type", "3x-ui").lower() @@ -569,6 +566,7 @@ async def handle_days_input(message: Message, state: FSMContext, session: Any): now = int(time.time() * 1000) add_ms = days * 86400 * 1000 + total_gb = int((days / 30) * TOTAL_GB * 1024**3) keys = await session.fetch( "SELECT tg_id, client_id, email, expiry_time FROM keys WHERE server_id = $1", @@ -587,7 +585,7 @@ async def handle_days_input(message: Message, state: FSMContext, session: Any): email=key["email"], client_id=key["client_id"], new_expiry_time=new_expiry, - total_gb=TOTAL_GB, + total_gb=total_gb, ) await update_key_expiry(key["client_id"], new_expiry, session) diff --git a/handlers/admin/users/users_handler.py b/handlers/admin/users/users_handler.py index 774bccfa..8a896127 100644 --- a/handlers/admin/users/users_handler.py +++ b/handlers/admin/users/users_handler.py @@ -1,5 +1,6 @@ import asyncio import uuid +import time from datetime import datetime, timedelta, timezone from typing import Any @@ -667,6 +668,8 @@ async def change_expiry_time(expiry_time: int, email: str, session: Any) -> Exce return ValueError(f"User with client_id {server_id} was not found") clusters = await get_servers() + added_days = max((expiry_time - int(time.time() * 1000)) / (1000 * 86400), 1) + total_gb = int((added_days / 30) * TOTAL_GB * 1024**3) async def update_key_on_all_servers(): tasks = [ @@ -676,7 +679,7 @@ async def change_expiry_time(expiry_time: int, email: str, session: Any) -> Exce email, client_id, expiry_time, - total_gb=TOTAL_GB, + total_gb=total_gb, ) ) for cluster_name in clusters diff --git a/handlers/keys/key_freeze.py b/handlers/keys/key_freeze.py index ca3bea85..c655dc4d 100644 --- a/handlers/keys/key_freeze.py +++ b/handlers/keys/key_freeze.py @@ -95,13 +95,16 @@ async def process_callback_unfreeze_subscription_confirm(callback_query: Callbac record["tg_id"], client_id, ) + added_days = max(leftover / (1000 * 86400), 0.01) + total_gb = int((added_days / 30) * TOTAL_GB * 1024**3) + await renew_key_in_cluster( cluster_id=cluster_id, email=email, client_id=client_id, new_expiry_time=new_expiry_time, - total_gb=TOTAL_GB, + total_gb=total_gb, ) text_ok = SUBSCRIPTION_UNFROZEN_MSG builder = InlineKeyboardBuilder() diff --git a/handlers/notifications/general_notifications.py b/handlers/notifications/general_notifications.py index bed3eaac..ba9fbdf9 100644 --- a/handlers/notifications/general_notifications.py +++ b/handlers/notifications/general_notifications.py @@ -404,13 +404,14 @@ async def process_auto_renew_or_notify( new_expiry_time = current_expiry + renewal_period_months * 30 * 24 * 3600 * 1000 formatted_expiry_date = datetime.fromtimestamp(new_expiry_time / 1000, moscow_tz).strftime("%d %B %Y, %H:%M") + total_gb = int(renewal_period_months * TOTAL_GB * 1024**3) logger.info( f"[Автопродление] Продление подписки {email} на {renewal_period_months} мес. для пользователя {tg_id}. Баланс: {balance}, списываем: {renewal_cost}" ) try: - await renew_key_in_cluster(server_id, email, client_id, new_expiry_time, TOTAL_GB) + await renew_key_in_cluster(server_id, email, client_id, new_expiry_time, total_gb) await update_balance(tg_id, -renewal_cost, session=conn) await update_key_expiry(client_id, new_expiry_time, conn)