fix: use reply keyboard for subscription purchase

This commit is contained in:
admin committed 2026-10-12 21:14:58 +02:00
1 parent aba1eb4ced
commit 073c7d2c81
4 files changed
+89 -33

No files matched your search

+23 -22
View File
@@ -39,7 +39,7 @@ from raw_updates import RawUpdateMiddleware, init_raw_updates_db
from apinex_client import APINEX_STT_URL, POST_HISTORY_CHAR_LIMIT, POST_HISTORY_LIMIT, classify_intent, classify_prompt_injection, create_tone_profile, current_operation_id, diagnostic_operation, extract_posts_from_images, extract_transcript, generate_ideas, generate_posts, generate_posts_from_images, transcribe_audio
from help_message import WELCOME_RICH_HTML, help_plain_view, help_view, rich_to_plain
from keyboards import MAIN_MENU_VALUE, SUPPORT_VALUE, TRAINING_RESET_VALUE, help_inline_keyboard, main_menu_keyboard, mode_keyboard, resolve_button_text
from keyboards import MAIN_MENU_VALUE, SUBSCRIPTION_ACTION_VALUE, SUPPORT_VALUE, TRAINING_RESET_VALUE, help_inline_keyboard, main_menu_keyboard, mode_keyboard, resolve_button_text
from payments import send_subscription_invoice
import support
from user_store import (
@@ -148,10 +148,7 @@ MODE_COPY = {
"Генерация",
"Напиши запрос или отправь голосовое.\nДля правки ответь на мой вариант.",
),
"subscription": (
"Подписка",
"Проверь статус ниже.\nКнопка откроет оплату или продление.",
),
"subscription": ("Подписка", "Проверь статус ниже.\nВыбери действие в меню."),
"help": ("Помощь", "Выбери раздел в сообщении выше."),
}
@@ -172,6 +169,9 @@ async def enter_mode(message: Message, state: FSMContext, mode: str) -> None:
await _close_support_case(message)
await state.clear()
await state.set_state(MODE_STATES[mode])
subscription = None
if mode == "subscription" and message.from_user is not None:
subscription = await asyncio.to_thread(subscription_row, message.from_user.id)
title, description = MODE_COPY[mode]
if mode == "help":
await send_rich_message(
@@ -182,11 +182,17 @@ async def enter_mode(message: Message, state: FSMContext, mode: str) -> None:
)
await message.answer(
f"Режим «{title}».\n{description}",
reply_markup=mode_keyboard(mode),
reply_markup=mode_keyboard(
mode,
subscription_purchased=bool(subscription and subscription["last_paid_at"]),
),
)
if mode == "subscription" and message.from_user is not None:
sub = await asyncio.to_thread(subscription_row, message.from_user.id)
await _show_subscription_info(message, sub)
await _show_subscription_info(message, subscription)
elif mode == "subscription":
await message.answer(
"Не удалось определить пользователя.", reply_markup=mode_keyboard("subscription")
)
async def show_main_menu(message: Message, state: FSMContext) -> None:
@@ -472,23 +478,14 @@ async def _show_subscription_info(
text += f"\n\nПродление на 30 дней — {SUBSCRIPTION_PRICE_STARS} ⭐."
if message.from_user is not None:
text += f"\nID пользователя: {message.from_user.id}"
markup = subscription_renew_keyboard()
markup = mode_keyboard(
"subscription", subscription_purchased=bool(sub["last_paid_at"])
) if sub else mode_keyboard("subscription")
else:
markup = mode_keyboard(mode)
await message.answer(text, reply_markup=markup)
def subscription_renew_keyboard() -> InlineKeyboardMarkup:
return InlineKeyboardMarkup(
inline_keyboard=[[
InlineKeyboardButton(
text="Продлить подписку",
callback_data="subscription:renew",
)
]]
)
async def balance_command(message: Message, state: FSMContext) -> None:
if not await require_mode(message, state, "subscription"):
return
@@ -1439,6 +1436,10 @@ async def handle_text(message: Message, state: FSMContext) -> None:
if button == SUPPORT_VALUE:
await open_support(message, state)
return
if button == SUBSCRIPTION_ACTION_VALUE:
if await require_mode(message, state, "subscription") and message.from_user is not None:
await _send_subscription_invoice(message, message.from_user.id)
return
if button == TRAINING_RESET_VALUE:
await clear_command(message, state)
return
@@ -1463,7 +1464,7 @@ async def handle_text(message: Message, state: FSMContext) -> None:
prompts = {
"lobby": "Выбери режим работы кнопкой ниже.",
"training": "Пришли пост текстом, скриншотом, голосовым или аудиофайлом — профиль будет накапливаться.",
"subscription": "Статус уже показан выше. Для продления нажми кнопку «Продлить подписку».",
"subscription": "Статус уже показан выше. Нажми кнопку покупки или продления подписки.",
"help": "Открой нужный раздел справки выше или выбери другой режим.",
}
await message.answer(
@@ -1484,7 +1485,7 @@ async def handle_other_message(message: Message, state: FSMContext) -> None:
elif mode == "generation":
text = "Для генерации отправь текстовый запрос или голосовое сообщение."
elif mode == "subscription":
text = "Статус уже показан выше. Для продления нажми «Продлить подписку»."
text = "Статус уже показан выше. Нажми кнопку покупки или продления подписки."
elif mode == "help":
text = "Выбери раздел справки или другой режим в меню."
else: