From cbf113f7bb5868e4c0af8384b95c6de804dd7eda Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Nov 2025 20:20:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B5=D1=80=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=B0=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BC=D0=B0:=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D1=8D=D0=BA=D1=80=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/__init__.py | 10 ++++++-- handlers/referrals.py | 58 +++++++++++++++++++++++++++++++++++++++++++ keyboard/keyboards.py | 31 +++++++++++++++++++---- main.py | 10 +++++--- 4 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 handlers/referrals.py diff --git a/handlers/__init__.py b/handlers/__init__.py index 697552f..bc1fa73 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -2,6 +2,12 @@ from .start import router as start_router from .profile import router as profile_router from .subscriptions import router as subscriptions_router from .support import router as support_router +from .referrals import router as referrals_router -# Экспортируем все маршрутизаторы -routers = [start_router,profile_router,subscriptions_router,support_router] +routers = [ + start_router, + profile_router, + subscriptions_router, + support_router, + referrals_router, +] diff --git a/handlers/referrals.py b/handlers/referrals.py new file mode 100644 index 0000000..1cf44a3 --- /dev/null +++ b/handlers/referrals.py @@ -0,0 +1,58 @@ +from aiogram import Router, types +from aiogram.filters import Command +from aiogram.enums.parse_mode import ParseMode +import logging + +router = Router() +logger = logging.getLogger(__name__) + + +async def _build_referral_text(bot, user_id: int) -> str: + me = await bot.get_me() + bot_username = me.username or "LarkVPN_bot" + + link = f"https://t.me/{bot_username}?start=ref_{user_id}" + + text = ( + "👥 Реферальная программа\n\n" + "Зови друзей в Lark VPN и получай бонусы на баланс.\n\n" + f"🔗 Твоя ссылка:\n{link}\n\n" + "👤 Приглашено: —\n" + "💰 Начислено бонусов: — ₽\n\n" + "Бонусы падают автоматически, когда приглашённые пополняют баланс." + ) + return text + + +@router.message(Command("referrals")) +async def referrals_command(message: types.Message): + """ + Команда /referrals — показывает текст реферальной программы. + """ + try: + text = await _build_referral_text(message.bot, message.from_user.id) + await message.answer(text, parse_mode=ParseMode.HTML) + except Exception as e: + logger.exception(f"Ошибка в обработчике /referrals: {e}") + await message.answer("Произошла ошибка. Попробуй позже.") + + +@router.callback_query(lambda callback: callback.data == "referral") +async def referrals_callback(callback: types.CallbackQuery): + """ + Кнопка «Реферальная программа» в главном меню. + """ + try: + text = await _build_referral_text( + callback.message.bot, + callback.from_user.id, + ) + await callback.message.edit_text( + text, + parse_mode=ParseMode.HTML, + ) + except Exception as e: + logger.exception(f"Ошибка в обработчике callback 'referral': {e}") + await callback.message.answer("Произошла ошибка. Попробуй позже.") + finally: + await callback.answer() diff --git a/keyboard/keyboards.py b/keyboard/keyboards.py index f5afcc4..b3037c2 100644 --- a/keyboard/keyboards.py +++ b/keyboard/keyboards.py @@ -4,19 +4,40 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder from aiogram.types import InlineKeyboardButton, KeyboardButton +from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder +from aiogram.types import InlineKeyboardButton, KeyboardButton + +# ... остальной код выше не трогаем ... + + def main_keyboard(): """ Главное меню (только визуал перетянут под твой стиль) """ builder = InlineKeyboardBuilder() - builder.row(InlineKeyboardButton( - text="📜 Профиль", callback_data="profile")) - builder.row(InlineKeyboardButton(text="❔ FAQ ❔", callback_data="faq")) + builder.row( + InlineKeyboardButton( + text="📜 Профиль", + callback_data="profile", + ) + ) + builder.row( + InlineKeyboardButton( + text="👥 Реферальная программа", + callback_data="referral", + ) + ) + builder.row( + InlineKeyboardButton( + text="❔ FAQ ❔", + callback_data="faq", + ) + ) # Оставляем URL как у Вовы, меняем только текст builder.row( InlineKeyboardButton( text="ℹ️ О нас", - url="https://www.youtube.com/watch?v=Zirn-CKck-c" + url="https://www.youtube.com/watch?v=Zirn-CKck-c", ) ) return builder.as_markup() @@ -450,7 +471,7 @@ def tarif_confirm_keyboard(name, amount, classif): def confirm_popup_keyboard(): - """ + """ аааааааааааааааааааааа """ diff --git a/main.py b/main.py index 04735c9..1b3e2b4 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,8 @@ import logging BOT_TOKEN = os.getenv("TOKEN") if not BOT_TOKEN: - raise ValueError("Не задан токен бота. Убедитесь, что переменная окружения 'TOKEN' установлена.") + raise ValueError( + "Не задан токен бота. Убедитесь, что переменная окружения 'TOKEN' установлена.") bot = Bot(token=BOT_TOKEN) dp = Dispatcher() @@ -23,9 +24,10 @@ dp.message.middleware(AntiSpamMiddleware(rate_limit=1)) async def set_commands(): """Устанавливает команды для бота.""" commands = [ - BotCommand(command="/start", description="🥚Главное меню"), - BotCommand(command="/subscriptions", description="🦴Мои подписки"), - BotCommand(command="/support", description="❕Поддержка❕"), + BotCommand(command="start", description="Запуск бота"), + BotCommand(command="subscriptions", description="Мои подписки"), + BotCommand(command="support", description="Техподдержка"), + BotCommand(command="referrals", description="Реферальная программа"), ] await bot.set_my_commands(commands)