From 7862713a063da68512cea87222a0f378bb1967ff Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 17 Sep 2025 12:20:38 +0300 Subject: [PATCH] feat(localization): add Pro subscription information and update command list - Introduced new localization entry for Pro subscription information. - Updated command list to include 'pro' command for better user guidance. - Enhanced existing subscription messages for clarity and consistency. --- apps/bot/locales/ru.ftl | 8 +++++++- apps/bot/src/bot/features/index.ts | 1 + apps/bot/src/bot/features/pro.ts | 28 +++++++++++++++++++++++++++ apps/bot/src/bot/settings/commands.ts | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 apps/bot/src/bot/features/pro.ts diff --git a/apps/bot/locales/ru.ftl b/apps/bot/locales/ru.ftl index 3566c58..a123e1e 100644 --- a/apps/bot/locales/ru.ftl +++ b/apps/bot/locales/ru.ftl @@ -32,6 +32,8 @@ help = .description = Список команд и поддержка subscribe = .description = Оформить подписку +pro = + .description = Информация о Pro подписке commands-list = 📋 Доступные команды: • /addcontact — добавить контакт клиента @@ -98,4 +100,8 @@ msg-subscribe-success = ✅ Платеж успешно обработан! msg-subscribe-error = ❌ Произошла ошибка при обработке платежа msg-subscription-active-until = 📅 Ваша подписка активна до { $date } msg-subscription-active-days = 📅 Осталось еще { $days } дней вашей подписки -msg-subscribe-disabled = 🚫 Подписка отключена. Все ограничения сняты! Наслаждайтесь полным доступом! 🎉 \ No newline at end of file +msg-subscribe-disabled = 🚫 Подписка отключена. Все ограничения сняты! Наслаждайтесь полным доступом! 🎉 + +# Информация о лимитах +msg-remaining-orders-this-month = 🧾 Доступно заказов в этом месяце: { $count } +msg-subscription-active-days = 📅 Осталось дней вашей подписки: { $days } \ No newline at end of file diff --git a/apps/bot/src/bot/features/index.ts b/apps/bot/src/bot/features/index.ts index c14ccbf..8d8908e 100644 --- a/apps/bot/src/bot/features/index.ts +++ b/apps/bot/src/bot/features/index.ts @@ -1,5 +1,6 @@ export * from './add-contact'; export * from './help'; +export * from './pro'; export * from './registration'; export * from './share-bot'; export * from './subscription'; diff --git a/apps/bot/src/bot/features/pro.ts b/apps/bot/src/bot/features/pro.ts new file mode 100644 index 0000000..4dbe49e --- /dev/null +++ b/apps/bot/src/bot/features/pro.ts @@ -0,0 +1,28 @@ +import { type Context } from '@/bot/context'; +import { logHandle } from '@/bot/helpers/logging'; +import { SubscriptionsService } from '@repo/graphql/api/subscriptions'; +import { Composer } from 'grammy'; + +const composer = new Composer(); +const feature = composer.chatType('private'); + +feature.command('pro', logHandle('command-pro'), async (ctx) => { + const telegramId = ctx.from.id; + const subscriptionsService = new SubscriptionsService({ telegramId }); + + const { subscriptionSetting } = await subscriptionsService.getSubscriptionSettings(); + const proEnabled = subscriptionSetting?.proEnabled; + + if (!proEnabled) return ctx.reply(ctx.t('msg-subscribe-disabled')); + + const { hasActiveSubscription, remainingDays, remainingOrdersCount } = + await subscriptionsService.getSubscription({ telegramId }); + + if (hasActiveSubscription && remainingDays > 0) { + return ctx.reply(ctx.t('msg-subscription-active-days', { days: remainingDays })); + } + + return ctx.reply(ctx.t('msg-remaining-orders-this-month', { count: remainingOrdersCount })); +}); + +export { composer as pro }; diff --git a/apps/bot/src/bot/settings/commands.ts b/apps/bot/src/bot/settings/commands.ts index f28e919..08a8473 100644 --- a/apps/bot/src/bot/settings/commands.ts +++ b/apps/bot/src/bot/settings/commands.ts @@ -5,7 +5,7 @@ import { type LanguageCode } from '@grammyjs/types'; import { type Api, type Bot, type RawApi } from 'grammy'; export async function setCommands({ api }: Bot>) { - const commands = createCommands(['start', 'addcontact', 'sharebot', 'help', 'subscribe']); + const commands = createCommands(['start', 'addcontact', 'sharebot', 'help', 'subscribe', 'pro']); for (const command of commands) { addLocalizations(command);