multiple fixes

This commit is contained in:
Vladless
2025-12-07 23:01:21 +03:00
parent 8183c2b678
commit 654b20c18f
3 changed files with 27 additions and 37 deletions
+11 -3
View File
@@ -6,6 +6,7 @@ from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.ext.asyncio import AsyncSession
from config import DISCOUNT_ACTIVE_HOURS
from core.bootstrap import NOTIFICATIONS_CONFIG
from database.models import Key, Notification, User
from logger import logger
@@ -81,7 +82,9 @@ async def check_hot_lead_discount(session: AsyncSession, tg_id: int) -> dict:
notification_type, last_time = row
expires_at = last_time + timedelta(hours=DISCOUNT_ACTIVE_HOURS)
hours = int(NOTIFICATIONS_CONFIG.get("DISCOUNT_ACTIVE_HOURS", DISCOUNT_ACTIVE_HOURS))
expires_at = last_time + timedelta(hours=hours)
current_time = datetime.utcnow()
if current_time > expires_at:
@@ -89,7 +92,12 @@ async def check_hot_lead_discount(session: AsyncSession, tg_id: int) -> dict:
tariff_group = "discounts" if notification_type == "hot_lead_step_2" else "discounts_max"
return {"available": True, "type": notification_type, "tariff_group": tariff_group, "expires_at": expires_at}
return {
"available": True,
"type": notification_type,
"tariff_group": tariff_group,
"expires_at": expires_at,
}
except Exception as e:
logger.error(f"❌ Ошибка при проверке скидки горячего лида для {tg_id}: {e}")
@@ -157,7 +165,7 @@ async def check_notifications_bulk(
"username": row.username,
"first_name": row.first_name,
"last_name": row.last_name,
"last_notification_time": (int(last_time.timestamp() * 1000) if last_time else None),
"last_notification_time": int(last_time.timestamp() * 1000) if last_time else None,
})
logger.info(f"Найдено {len(users)} пользователей, готовых к уведомлению типа {notification_type}")
+16 -34
View File
@@ -141,44 +141,26 @@ async def process_start_logic(
user_data = user_data or extract_user_data(message.from_user or message.chat)
text = text_to_process or message.text or message.caption
if text == "/start":
await add_user(session=session, **user_data)
trial_key = await get_or_load_user_snapshot(session, user_snapshot, user_data["tg_id"])
trial = 0
key_count = 0
if trial_key is not None:
trial, key_count = trial_key
await show_start_menu(message, admin, session, trial=trial, key_count=key_count)
return
if not text:
trial_key = await get_or_load_user_snapshot(session, user_snapshot, user_data["tg_id"])
trial = 0
key_count = 0
if trial_key is not None:
trial, key_count = trial_key
await show_start_menu(message, admin, session, trial=trial, key_count=key_count)
return
if text.startswith("/start "):
if text and text.startswith("/start "):
text = text.split(maxsplit=1)[1]
await state.update_data(original_text=text, user_data=user_data)
gift_detected = False
for part in text.split("-"):
await run_hooks("start_link", message=message, state=state, session=session, user_data=user_data, part=part)
if "coupons" in part:
await handle_coupon_link(part, message, state, session, admin, user_data)
continue
if "gift" in part:
gift_detected = await handle_gift(part, message, state, session, user_data)
break
if "referral" in part:
await handle_referral_link_safe(part, message, state, session, user_data)
continue
if "utm" in part:
await handle_utm_link(part, message, state, session, user_data)
if text:
for part in text.split("-"):
await run_hooks("start_link", message=message, state=state, session=session, user_data=user_data, part=part)
if "coupons" in part:
await handle_coupon_link(part, message, state, session, admin, user_data)
continue
if "gift" in part:
gift_detected = await handle_gift(part, message, state, session, user_data)
break
if "referral" in part:
await handle_referral_link_safe(part, message, state, session, user_data)
continue
if "utm" in part:
await handle_utm_link(part, message, state, session, user_data)
await state.clear()
if gift_detected:
@@ -186,7 +168,7 @@ async def process_start_logic(
await add_user(session=session, **user_data)
tl = text.strip().lower()
tl = (text or "").strip().lower()
if tl == "trial":
await confirm_create_new_key(message, state, session)
return
Binary file not shown.