Fix time declination
-Склонение времени
This commit is contained in:
@@ -45,6 +45,7 @@ from handlers.texts import (
|
||||
KEY_RENEWED_TEMP_MSG,
|
||||
)
|
||||
from logger import logger
|
||||
from handlers.utils import format_hours, format_months, format_minutes
|
||||
|
||||
from .notify_utils import send_notification
|
||||
from .special_notifications import notify_inactive_trial_users, notify_users_no_traffic
|
||||
@@ -137,8 +138,10 @@ async def notify_24h_keys(bot: Bot, conn: asyncpg.Connection, current_time: int,
|
||||
continue
|
||||
|
||||
hours_left = int((expiry_timestamp - current_time) / (1000 * 3600))
|
||||
days_left_message = (
|
||||
f"⏳ Осталось времени: {hours_left} часов" if hours_left > 0 else "⏳ Последний день подписки!"
|
||||
hours_left_formatted = (
|
||||
f"⏳ Осталось времени: {format_hours(hours_left)}"
|
||||
if hours_left > 0
|
||||
else "⏳ Последний день подписки!"
|
||||
)
|
||||
|
||||
expiry_datetime = datetime.fromtimestamp(expiry_timestamp / 1000, tz=moscow_tz)
|
||||
@@ -146,7 +149,7 @@ async def notify_24h_keys(bot: Bot, conn: asyncpg.Connection, current_time: int,
|
||||
|
||||
notification_text = KEY_EXPIRY_24H.format(
|
||||
email=email,
|
||||
days_left_message=days_left_message,
|
||||
hours_left_formatted=hours_left_formatted,
|
||||
formatted_expiry_date=formatted_expiry_date,
|
||||
)
|
||||
|
||||
@@ -192,8 +195,10 @@ async def notify_10h_keys(bot: Bot, conn: asyncpg.Connection, current_time: int,
|
||||
continue
|
||||
|
||||
hours_left = int((expiry_timestamp - current_time) / (1000 * 3600))
|
||||
hours_left_message = (
|
||||
f"⏳ Осталось времени: {hours_left} часов" if hours_left > 0 else "⏳ Последний день подписки!"
|
||||
hours_left_formatted = (
|
||||
f"⏳ Осталось времени: {format_hours(hours_left)}"
|
||||
if hours_left > 0
|
||||
else "⏳ Последний день подписки!"
|
||||
)
|
||||
|
||||
expiry_datetime = datetime.fromtimestamp(expiry_timestamp / 1000, tz=moscow_tz)
|
||||
@@ -201,7 +206,7 @@ async def notify_10h_keys(bot: Bot, conn: asyncpg.Connection, current_time: int,
|
||||
|
||||
notification_text = KEY_EXPIRY_10H.format(
|
||||
email=email,
|
||||
hours_left_message=hours_left_message,
|
||||
hours_left_formatted=hours_left_formatted,
|
||||
formatted_expiry_date=formatted_expiry_date,
|
||||
)
|
||||
|
||||
@@ -308,15 +313,23 @@ async def handle_expired_keys(bot: Bot, conn: asyncpg.Connection, current_time:
|
||||
|
||||
if hours > 0:
|
||||
if minutes > 0:
|
||||
hour_suffix = "час" if hours == 1 else "часа" if 2 <= hours <= 4 else "часов"
|
||||
time_str = f"{hours} {hour_suffix} и {minutes} минут"
|
||||
delay_message = KEY_EXPIRED_DELAY_HOURS_MINUTES_MSG.format(email=email, time_str=time_str)
|
||||
time_left_formatted = f"{format_hours(hours)} и {format_minutes(minutes)}"
|
||||
delay_message = KEY_EXPIRED_DELAY_HOURS_MINUTES_MSG.format(
|
||||
email=email,
|
||||
time_left_formatted=time_left_formatted
|
||||
)
|
||||
else:
|
||||
hour_suffix = "час" if hours == 1 else "часа" if 2 <= hours <= 4 else "часов"
|
||||
time_str = f"{hours} {hour_suffix}"
|
||||
delay_message = KEY_EXPIRED_DELAY_HOURS_MSG.format(email=email, time_str=time_str)
|
||||
time_left_formatted = format_hours(hours)
|
||||
delay_message = KEY_EXPIRED_DELAY_HOURS_MSG.format(
|
||||
email=email,
|
||||
time_left_formatted=time_left_formatted
|
||||
)
|
||||
else:
|
||||
delay_message = KEY_EXPIRED_DELAY_MINUTES_MSG.format(email=email, minutes=NOTIFY_DELETE_DELAY)
|
||||
minutes_formatted = format_minutes(minutes)
|
||||
delay_message = KEY_EXPIRED_DELAY_MINUTES_MSG.format(
|
||||
email=email,
|
||||
minutes_formatted=minutes_formatted
|
||||
)
|
||||
else:
|
||||
delay_message = KEY_EXPIRED_NO_DELAY_MSG.format(email=email)
|
||||
|
||||
@@ -385,6 +398,7 @@ 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")
|
||||
months_formatted = format_months(renewal_period_months)
|
||||
|
||||
logger.info(
|
||||
f"[Автопродление] Продление подписки {email} на {renewal_period_months} мес. для пользователя {tg_id}. Баланс: {balance}, списываем: {renewal_cost}"
|
||||
@@ -403,7 +417,9 @@ async def process_auto_renew_or_notify(
|
||||
)
|
||||
|
||||
renewed_message = KEY_RENEWED.format(
|
||||
email=email, months=renewal_period_months, expiry_date=formatted_expiry_date
|
||||
email=email,
|
||||
months_formatted=months_formatted,
|
||||
expiry_date=formatted_expiry_date
|
||||
)
|
||||
|
||||
keyboard = build_notification_expired_kb()
|
||||
|
||||
Reference in New Issue
Block a user