fix: eligibility and display use best non-daily subscription in multi-tariff
Contests, wheel spin, and menu now select best non-daily subscription (most days remaining) instead of arbitrary active_subs[0].
This commit is contained in:
@@ -94,7 +94,10 @@ async def show_contests_menu(callback: types.CallbackQuery, db_user, db: AsyncSe
|
||||
texts = get_texts(db_user.language)
|
||||
|
||||
active_subs = await get_active_subscriptions_by_user_id(db, db_user.id)
|
||||
subscription = active_subs[0] if active_subs else None
|
||||
# For eligibility: pick best non-daily subscription (most days left)
|
||||
non_daily = [s for s in active_subs if not getattr(s, 'is_daily_tariff', False)]
|
||||
eligible = non_daily or active_subs
|
||||
subscription = max(eligible, key=lambda s: s.days_left) if eligible else None
|
||||
if not _user_allowed(subscription):
|
||||
await _reply_not_eligible(callback, db_user.language)
|
||||
return
|
||||
@@ -148,7 +151,10 @@ async def play_contest(callback: types.CallbackQuery, state: FSMContext, db_user
|
||||
texts = get_texts(db_user.language)
|
||||
|
||||
active_subs = await get_active_subscriptions_by_user_id(db, db_user.id)
|
||||
subscription = active_subs[0] if active_subs else None
|
||||
# For eligibility: pick best non-daily subscription (most days left)
|
||||
non_daily = [s for s in active_subs if not getattr(s, 'is_daily_tariff', False)]
|
||||
eligible = non_daily or active_subs
|
||||
subscription = max(eligible, key=lambda s: s.days_left) if eligible else None
|
||||
if not _user_allowed(subscription):
|
||||
await _reply_not_eligible(callback, db_user.language)
|
||||
return
|
||||
@@ -263,7 +269,10 @@ async def handle_pick(callback: types.CallbackQuery, db_user, db: AsyncSession):
|
||||
|
||||
# Re-check subscription
|
||||
active_subs = await get_active_subscriptions_by_user_id(db, db_user.id)
|
||||
subscription = active_subs[0] if active_subs else None
|
||||
# For eligibility: pick best non-daily subscription (most days left)
|
||||
non_daily = [s for s in active_subs if not getattr(s, 'is_daily_tariff', False)]
|
||||
eligible = non_daily or active_subs
|
||||
subscription = max(eligible, key=lambda s: s.days_left) if eligible else None
|
||||
if not _user_allowed(subscription):
|
||||
await callback.answer(
|
||||
texts.t('CONTEST_NOT_ELIGIBLE', 'Игра недоступна без активной подписки.'),
|
||||
|
||||
@@ -1258,7 +1258,10 @@ async def handle_activate_button(callback: types.CallbackQuery, db_user: User, d
|
||||
from app.database.crud.subscription import get_active_subscriptions_by_user_id
|
||||
|
||||
active_subs = await get_active_subscriptions_by_user_id(db, db_user.id)
|
||||
subscription = active_subs[0] if active_subs else None
|
||||
# For menu display: prefer non-daily, most days remaining
|
||||
non_daily = [s for s in active_subs if not getattr(s, 'is_daily_tariff', False)]
|
||||
_eligible = non_daily or active_subs
|
||||
subscription = max(_eligible, key=lambda s: s.days_left) if _eligible else None
|
||||
else:
|
||||
subscription = await get_subscription_by_user_id(db, db_user.id)
|
||||
|
||||
|
||||
@@ -45,8 +45,10 @@ async def _handle_wheel_spin_payment(
|
||||
from app.database.crud.subscription import get_active_subscriptions_by_user_id
|
||||
|
||||
active_subs = await get_active_subscriptions_by_user_id(db, user.id)
|
||||
# Check if user has any active subscription (Type A check)
|
||||
subscription = active_subs[0] if active_subs else None
|
||||
# Wheel eligibility: any active non-daily subscription qualifies
|
||||
non_daily = [s for s in active_subs if not getattr(s, 'is_daily_tariff', False)]
|
||||
eligible = non_daily or active_subs
|
||||
subscription = max(eligible, key=lambda s: s.days_left) if eligible else None
|
||||
else:
|
||||
subscription = await get_subscription_by_user_id(db, user.id)
|
||||
if not subscription or not subscription.is_active:
|
||||
|
||||
Reference in New Issue
Block a user