scalar total_gb

This commit is contained in:
Vladless
2025-04-24 22:42:14 +03:00
parent 15fcc0ac70
commit ff498feb7e
4 changed files with 12 additions and 7 deletions
+2 -4
View File
@@ -310,9 +310,6 @@ async def handle_cluster_availability(
total_online_users = 0
result_text = f"<b>🖥️ Проверка доступности серверов</b>\n\n⚙️ Кластер: <b>{cluster_name}</b>\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)
+4 -1
View File
@@ -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
+4 -1
View File
@@ -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()
@@ -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)