fix remna traffic for create_key
This commit is contained in:
@@ -895,26 +895,23 @@ async def confirm_admin_key_reissue(
|
||||
|
||||
if USE_COUNTRY_SELECTION:
|
||||
unique_countries = {srv["server_name"] for srv in cluster_servers}
|
||||
|
||||
if len(unique_countries) > 1:
|
||||
await state.update_data(tg_id=tg_id, email=email, cluster_id=cluster_id)
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
for country in sorted(unique_countries):
|
||||
builder.button(
|
||||
text=country,
|
||||
callback_data=f"admin_reissue_country|{tg_id}|{email}|{country}",
|
||||
)
|
||||
builder.row(
|
||||
InlineKeyboardButton(
|
||||
text="Назад", callback_data=f"users_key_edit|{email}"
|
||||
)
|
||||
await state.update_data(tg_id=tg_id, email=email, cluster_id=cluster_id)
|
||||
builder = InlineKeyboardBuilder()
|
||||
for country in sorted(unique_countries):
|
||||
builder.button(
|
||||
text=country,
|
||||
callback_data=f"admin_reissue_country|{tg_id}|{email}|{country}",
|
||||
)
|
||||
await callback_query.message.edit_text(
|
||||
"🌍 Выберите страну, на которой пересоздать подписку:",
|
||||
reply_markup=builder.as_markup(),
|
||||
builder.row(
|
||||
InlineKeyboardButton(
|
||||
text="Назад", callback_data=f"users_key_edit|{email}"
|
||||
)
|
||||
return
|
||||
)
|
||||
await callback_query.message.edit_text(
|
||||
"🌍 Выберите сервер (страну) для пересоздания подписки:",
|
||||
reply_markup=builder.as_markup(),
|
||||
)
|
||||
return
|
||||
|
||||
result = await session.execute(
|
||||
select(Key.remnawave_link).where(Key.email == email)
|
||||
@@ -941,7 +938,18 @@ async def admin_reissue_country(callback_query: CallbackQuery, session: AsyncSes
|
||||
tg_id = int(tg_id)
|
||||
|
||||
try:
|
||||
await update_subscription(tg_id, email, session, country_override=country)
|
||||
result = await session.execute(
|
||||
select(Key.remnawave_link, Key.tariff_id).where(Key.email == email)
|
||||
)
|
||||
remnawave_link, tariff_id = result.one_or_none() or (None, None)
|
||||
|
||||
await update_subscription(
|
||||
tg_id=tg_id,
|
||||
email=email,
|
||||
session=session,
|
||||
country_override=country,
|
||||
remnawave_link=remnawave_link,
|
||||
)
|
||||
|
||||
await handle_key_edit(
|
||||
callback_query,
|
||||
|
||||
@@ -352,6 +352,7 @@ async def finalize_key_creation(
|
||||
client_id = old_key_details["client_id"]
|
||||
email = old_key_details["email"]
|
||||
expiry_timestamp = old_key_details["expiry_time"]
|
||||
tariff_id = old_key_details.get("tariff_id") or tariff_id
|
||||
else:
|
||||
while True:
|
||||
key_name = generate_random_email()
|
||||
@@ -376,7 +377,7 @@ async def finalize_key_creation(
|
||||
tariff = result.scalar_one_or_none()
|
||||
if tariff:
|
||||
if tariff.traffic_limit is not None:
|
||||
traffic_limit_bytes = int(tariff.traffic_limit)
|
||||
traffic_limit_bytes = int(tariff.traffic_limit) * 1024**3
|
||||
if tariff.device_limit is not None:
|
||||
device_limit = int(tariff.device_limit)
|
||||
|
||||
@@ -543,8 +544,6 @@ async def finalize_key_creation(
|
||||
builder.row(InlineKeyboardButton(text=SUPPORT, url=SUPPORT_CHAT_URL))
|
||||
builder.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
|
||||
|
||||
remaining_time = expiry_time - datetime.now(moscow_tz)
|
||||
days = remaining_time.days
|
||||
link_to_show = public_link or remnawave_link or "Ссылка не найдена"
|
||||
|
||||
tariff_info = None
|
||||
|
||||
@@ -6,6 +6,7 @@ from aiogram import F, Router
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery, InlineKeyboardButton, Message
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from math import ceil
|
||||
|
||||
from config import (
|
||||
NOTIFY_EXTRA_DAYS,
|
||||
@@ -144,11 +145,11 @@ async def select_tariff_plan(
|
||||
duration_days = tariff["duration_days"]
|
||||
price_rub = tariff["price_rub"]
|
||||
|
||||
balance = round(await get_balance(session, tg_id))
|
||||
price_rub = round(tariff["price_rub"])
|
||||
balance = await get_balance(session, tg_id)
|
||||
price_rub = tariff["price_rub"]
|
||||
|
||||
if balance < price_rub:
|
||||
required_amount = max(price_rub - balance, 0)
|
||||
required_amount = ceil(price_rub - balance)
|
||||
await create_temporary_data(
|
||||
session,
|
||||
tg_id,
|
||||
|
||||
@@ -6,6 +6,7 @@ from aiogram.types import CallbackQuery, InlineKeyboardButton
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from sqlalchemy import or_, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from math import ceil
|
||||
|
||||
from bot import bot
|
||||
from config import USE_NEW_PAYMENT_FLOW
|
||||
@@ -19,7 +20,6 @@ from database import (
|
||||
update_balance,
|
||||
update_key_expiry,
|
||||
check_tariff_exists,
|
||||
get_tariffs_for_cluster,
|
||||
)
|
||||
from database.models import Server, Key
|
||||
from handlers.buttons import BACK, MAIN_MENU, PAYMENT
|
||||
@@ -34,6 +34,7 @@ from handlers.texts import (
|
||||
PLAN_SELECTION_MSG,
|
||||
SUCCESS_RENEWAL_MSG,
|
||||
)
|
||||
from handlers.buttons import MY_SUB
|
||||
from handlers.utils import edit_or_send_message, format_days, format_months
|
||||
from logger import logger
|
||||
|
||||
@@ -180,7 +181,7 @@ async def process_callback_renew_plan(callback_query: CallbackQuery, session: An
|
||||
balance = round(await get_balance(session, tg_id), 2)
|
||||
cost = round(cost, 2)
|
||||
if balance < cost:
|
||||
required_amount = round(cost - balance, 2)
|
||||
required_amount = ceil(cost - balance)
|
||||
logger.info(f"[RENEW] Недостаточно средств: {required_amount}₽")
|
||||
|
||||
await create_temporary_data(
|
||||
@@ -288,7 +289,7 @@ async def complete_key_renewal(
|
||||
months_formatted = format_days(tariff["duration_days"])
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
builder.row(InlineKeyboardButton(text=MAIN_MENU, callback_data="profile"))
|
||||
builder.row(InlineKeyboardButton(text=MY_SUB, callback_data=f"view_key|{email}"))
|
||||
response_message = SUCCESS_RENEWAL_MSG.format(months_formatted=months_formatted)
|
||||
|
||||
if callback_query:
|
||||
|
||||
@@ -584,7 +584,7 @@ async def update_key_on_cluster(
|
||||
"activeUserInbounds": inbound_ids,
|
||||
}
|
||||
if traffic_limit is not None:
|
||||
user_data["trafficLimitBytes"] = traffic_limit
|
||||
user_data["trafficLimitBytes"] = traffic_limit * 1024 ** 3
|
||||
if device_limit is not None:
|
||||
user_data["hwidDeviceLimit"] = device_limit
|
||||
if short_uuid:
|
||||
|
||||
Reference in New Issue
Block a user