format tariff duration in messages / format delete delay message for expired subscriptions
This commit is contained in:
@@ -38,6 +38,7 @@ from handlers.utils import (
|
||||
get_least_loaded_cluster,
|
||||
is_full_remnawave_cluster,
|
||||
format_days,
|
||||
format_months,
|
||||
)
|
||||
from logger import logger
|
||||
|
||||
@@ -181,16 +182,30 @@ async def key_cluster_mode(
|
||||
|
||||
if is_trial:
|
||||
trial_days = TRIAL_CONFIG.get("duration_days", 1)
|
||||
if trial_days >= 30:
|
||||
months = trial_days // 30
|
||||
tariff_duration = format_months(months)
|
||||
else:
|
||||
tariff_duration = format_days(trial_days)
|
||||
key_message_text = key_message_success(
|
||||
final_link,
|
||||
tariff_name=format_days(trial_days),
|
||||
tariff_name=tariff_duration,
|
||||
traffic_limit=TRIAL_CONFIG.get("traffic_limit_gb", 100),
|
||||
device_limit=TRIAL_CONFIG.get("hwid_limit", 1)
|
||||
)
|
||||
else:
|
||||
tariff_duration = ""
|
||||
if tariff_info and tariff_info.get("duration_days", 0) > 0:
|
||||
duration_days = tariff_info["duration_days"]
|
||||
if duration_days >= 30:
|
||||
months = duration_days // 30
|
||||
tariff_duration = format_months(months)
|
||||
else:
|
||||
tariff_duration = format_days(duration_days)
|
||||
|
||||
key_message_text = key_message_success(
|
||||
final_link,
|
||||
tariff_name=tariff_info.get("name", "") if tariff_info else "",
|
||||
tariff_name=tariff_duration,
|
||||
traffic_limit=tariff_info.get("traffic_limit", 0) if tariff_info else 0,
|
||||
device_limit=tariff_info.get("device_limit", 0) if tariff_info else 0
|
||||
)
|
||||
|
||||
@@ -52,6 +52,7 @@ from handlers.utils import (
|
||||
get_least_loaded_cluster,
|
||||
is_full_remnawave_cluster,
|
||||
format_days,
|
||||
format_months,
|
||||
)
|
||||
from logger import logger
|
||||
from panels.remnawave import RemnawaveAPI
|
||||
@@ -553,18 +554,32 @@ async def finalize_key_creation(
|
||||
|
||||
if is_trial:
|
||||
trial_days = TRIAL_CONFIG.get("duration_days", 1)
|
||||
if trial_days >= 30:
|
||||
months = trial_days // 30
|
||||
tariff_duration = format_months(months)
|
||||
else:
|
||||
tariff_duration = format_days(trial_days)
|
||||
key_message_text = key_message_success(
|
||||
link_to_show,
|
||||
tariff_name=format_days(trial_days),
|
||||
tariff_name=tariff_duration,
|
||||
traffic_limit=TRIAL_CONFIG.get("traffic_limit_gb", 100),
|
||||
device_limit=TRIAL_CONFIG.get("hwid_limit", 1)
|
||||
)
|
||||
else:
|
||||
tariff_duration = ""
|
||||
if tariff_info and tariff_info.get("duration_days", 0) > 0:
|
||||
duration_days = tariff_info["duration_days"]
|
||||
if duration_days >= 30:
|
||||
months = duration_days // 30
|
||||
tariff_duration = format_months(months)
|
||||
else:
|
||||
tariff_duration = format_days(duration_days)
|
||||
|
||||
key_message_text = key_message_success(
|
||||
link_to_show,
|
||||
tariff_name=tariff_info.name if tariff_info else "",
|
||||
traffic_limit=tariff_info.traffic_limit if tariff_info and tariff_info.traffic_limit is not None else 0,
|
||||
device_limit=tariff_info.device_limit if tariff_info and tariff_info.device_limit is not None else 0
|
||||
tariff_name=tariff_duration,
|
||||
traffic_limit=tariff_info.get("traffic_limit", 0) if tariff_info else 0,
|
||||
device_limit=tariff_info.get("device_limit", 0) if tariff_info else 0
|
||||
)
|
||||
|
||||
await edit_or_send_message(
|
||||
|
||||
@@ -7,6 +7,7 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from sqlalchemy import or_, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from math import ceil
|
||||
import pytz
|
||||
|
||||
from bot import bot
|
||||
from config import USE_NEW_PAYMENT_FLOW
|
||||
@@ -32,13 +33,14 @@ from handlers.texts import (
|
||||
INSUFFICIENT_FUNDS_RENEWAL_MSG,
|
||||
KEY_NOT_FOUND_MSG,
|
||||
PLAN_SELECTION_MSG,
|
||||
SUCCESS_RENEWAL_MSG,
|
||||
get_renewal_message,
|
||||
)
|
||||
from handlers.buttons import MY_SUB
|
||||
from handlers.utils import edit_or_send_message, format_days, format_months
|
||||
from handlers.utils import edit_or_send_message, format_days, format_months, get_russian_month
|
||||
from logger import logger
|
||||
|
||||
router = Router()
|
||||
moscow_tz = pytz.timezone("Europe/Moscow")
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("renew_key|"))
|
||||
@@ -290,7 +292,22 @@ async def complete_key_renewal(
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
builder.row(InlineKeyboardButton(text=MY_SUB, callback_data=f"view_key|{email}"))
|
||||
response_message = SUCCESS_RENEWAL_MSG.format(months_formatted=months_formatted)
|
||||
|
||||
formatted_expiry_date = datetime.fromtimestamp(
|
||||
new_expiry_time / 1000, tz=moscow_tz
|
||||
).strftime("%d %B %Y, %H:%M")
|
||||
|
||||
formatted_expiry_date = formatted_expiry_date.replace(
|
||||
datetime.fromtimestamp(new_expiry_time / 1000, tz=moscow_tz).strftime("%B"),
|
||||
get_russian_month(datetime.fromtimestamp(new_expiry_time / 1000, tz=moscow_tz))
|
||||
)
|
||||
|
||||
response_message = get_renewal_message(
|
||||
tariff_name=months_formatted,
|
||||
traffic_limit=tariff.get("traffic_limit") if tariff.get("traffic_limit") is not None else 0,
|
||||
device_limit=tariff.get("device_limit") if tariff.get("device_limit") is not None else 0,
|
||||
expiry_date=formatted_expiry_date
|
||||
)
|
||||
|
||||
if callback_query:
|
||||
try:
|
||||
|
||||
@@ -48,6 +48,7 @@ from handlers.utils import (
|
||||
format_days,
|
||||
format_hours,
|
||||
format_minutes,
|
||||
format_months,
|
||||
get_russian_month,
|
||||
is_full_remnawave_cluster,
|
||||
)
|
||||
@@ -289,14 +290,23 @@ async def render_key_info(
|
||||
traffic_limit = tariff.get("traffic_limit", 0)
|
||||
device_limit = tariff.get("device_limit", 0)
|
||||
|
||||
tariff_duration = ""
|
||||
if tariff and tariff.get("duration_days", 0) > 0:
|
||||
duration_days = tariff["duration_days"]
|
||||
if duration_days >= 30:
|
||||
months = duration_days // 30
|
||||
tariff_duration = format_months(months)
|
||||
else:
|
||||
tariff_duration = format_days(duration_days)
|
||||
|
||||
response_message = key_message(
|
||||
final_link,
|
||||
formatted_expiry_date,
|
||||
days_left_message,
|
||||
server_name,
|
||||
server_name if USE_COUNTRY_SELECTION else None,
|
||||
hwid_count=hwid_count,
|
||||
tariff_name=tariff_name,
|
||||
hwid_count=hwid_count if device_limit is not None else 0,
|
||||
tariff_name=tariff_duration,
|
||||
traffic_limit=traffic_limit,
|
||||
device_limit=device_limit
|
||||
)
|
||||
|
||||
@@ -38,15 +38,13 @@ from handlers.notifications.notify_kb import (
|
||||
)
|
||||
from handlers.texts import (
|
||||
KEY_DELETED_MSG,
|
||||
KEY_EXPIRED_DELAY_HOURS_MINUTES_MSG,
|
||||
KEY_EXPIRED_DELAY_HOURS_MSG,
|
||||
KEY_EXPIRED_DELAY_MINUTES_MSG,
|
||||
KEY_EXPIRED_DELAY_MSG,
|
||||
KEY_EXPIRED_NO_DELAY_MSG,
|
||||
KEY_EXPIRY_10H,
|
||||
KEY_EXPIRY_24H,
|
||||
get_renewal_message,
|
||||
)
|
||||
from handlers.utils import format_hours, format_minutes, get_russian_month
|
||||
from handlers.utils import format_hours, format_minutes, get_russian_month, format_months, format_days
|
||||
from logger import logger
|
||||
|
||||
from .hot_leads_notifications import notify_hot_leads
|
||||
@@ -460,19 +458,16 @@ async def handle_expired_keys(
|
||||
hours = NOTIFY_DELETE_DELAY // 60
|
||||
minutes = NOTIFY_DELETE_DELAY % 60
|
||||
if hours > 0 and minutes > 0:
|
||||
delay_message = KEY_EXPIRED_DELAY_HOURS_MINUTES_MSG.format(
|
||||
email=email,
|
||||
hours_formatted=format_hours(hours),
|
||||
minutes_formatted=format_minutes(minutes),
|
||||
)
|
||||
time_formatted = f"{format_hours(hours)} и {format_minutes(minutes)}"
|
||||
elif hours > 0:
|
||||
delay_message = KEY_EXPIRED_DELAY_HOURS_MSG.format(
|
||||
email=email, hours_formatted=format_hours(hours)
|
||||
)
|
||||
time_formatted = format_hours(hours)
|
||||
else:
|
||||
delay_message = KEY_EXPIRED_DELAY_MINUTES_MSG.format(
|
||||
email=email, minutes_formatted=format_minutes(minutes)
|
||||
)
|
||||
time_formatted = format_minutes(minutes)
|
||||
|
||||
delay_message = KEY_EXPIRED_DELAY_MSG.format(
|
||||
email=email,
|
||||
time_formatted=time_formatted
|
||||
)
|
||||
else:
|
||||
delay_message = KEY_EXPIRED_NO_DELAY_MSG.format(email=email)
|
||||
|
||||
@@ -585,6 +580,13 @@ async def process_auto_renew_or_notify(
|
||||
client_id = key.client_id
|
||||
current_expiry = key.expiry_time
|
||||
duration_days = selected_tariff["duration_days"]
|
||||
tariff_duration = ""
|
||||
if duration_days > 0:
|
||||
if duration_days >= 30:
|
||||
months = duration_days // 30
|
||||
tariff_duration = format_months(months)
|
||||
else:
|
||||
tariff_duration = format_days(duration_days)
|
||||
renewal_cost = selected_tariff["price_rub"]
|
||||
traffic_limit = selected_tariff["traffic_limit"]
|
||||
device_limit = selected_tariff["device_limit"]
|
||||
@@ -625,7 +627,7 @@ async def process_auto_renew_or_notify(
|
||||
await delete_notification(conn, tg_id, notification_id)
|
||||
|
||||
renewed_message = get_renewal_message(
|
||||
tariff_name=selected_tariff.get("name", ""),
|
||||
tariff_name=tariff_duration,
|
||||
traffic_limit=selected_tariff.get("traffic_limit") if selected_tariff.get("traffic_limit") is not None else 0,
|
||||
device_limit=selected_tariff.get("device_limit") if selected_tariff.get("device_limit") is not None else 0,
|
||||
expiry_date=formatted_expiry_date
|
||||
|
||||
Reference in New Issue
Block a user