From dd801361949853932f6ba8db17b0aa99d5630541 Mon Sep 17 00:00:00 2001 From: Disledg Date: Sun, 15 Dec 2024 14:23:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BD=D1=8E=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20=D0=BA=D0=B0=D0=BA?= =?UTF-8?q?=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D1=85=D0=BE=D1=82=D0=B5?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +-- databases/mongodb.py | 6 +++--- databases/postgresql.py | 15 +------------- docker-compose.yml | 2 +- handlers/handlers.py | 44 ++++++++++++++++++++++++++--------------- keyboard/keyboards.py | 26 ++++++++++++------------ 6 files changed, 47 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 86526bd..6e28450 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ ---- + # VPN Configuration Sales Bot @@ -33,5 +33,4 @@ Этот проект распространяется под лицензией MIT License. Подробности в файле [LICENSE](./LICENSE). ---- diff --git a/databases/mongodb.py b/databases/mongodb.py index edc7db8..d960454 100644 --- a/databases/mongodb.py +++ b/databases/mongodb.py @@ -39,13 +39,13 @@ class MongoDBRepository: self.logger.debug(f"VPN сервер добавлен с ID: {result.inserted_id}") return result.inserted_id - async def get_server(self, server_id: str): + async def get_server(self, server_name: str): """Получает сервер VPN по его ID.""" - server = await self.collection.find_one({"name": server_id}) + server = await self.collection.find_one({"server.name": server_name}) if server: self.logger.debug(f"Найден VPN сервер: {server}") else: - self.logger.debug(f"VPN сервер с ID {server_id} не найден.") + self.logger.debug(f"VPN сервер с ID {server_name} не найден.") return server async def get_server_with_least_clients(self): diff --git a/databases/postgresql.py b/databases/postgresql.py index 277aa08..984625d 100644 --- a/databases/postgresql.py +++ b/databases/postgresql.py @@ -181,17 +181,6 @@ class DatabaseManager: self.logger.error(f"Не удалось найти сервер с ID {user_sub.vpn_server_id}.") return "ERROR" - # Найдем клиента на сервере по telegram_id - client = None - for client_info in server['clients']: - if client_info['subscriptions']['tgId'] == telegram_id: - client = client_info - break - - if not client: - self.logger.error(f"Не удалось найти клиента с Telegram ID {telegram_id} на сервере.") - return "ERROR" - # Доступ к данным сервера для добавления клиента server_info = server['server'] url_base = f"https://{server_info['ip']}:{server_info['port']}/{server_info['secretKey']}" @@ -203,10 +192,8 @@ class DatabaseManager: # Инициализируем взаимодействие с панелью управления panel = PanelInteraction(url_base, login_data, self.logger) - # Добавляем клиента на сервер - client_id = client['id'] expiry_date_iso = user_sub.expiry_date.isoformat() - response = await panel.add_client(client_id, expiry_date_iso, user.username) + response = await panel.add_client(user.id, expiry_date_iso, user.username) # Логируем результат if response == "OK": diff --git a/docker-compose.yml b/docker-compose.yml index 7db74e6..81c4e27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,7 +42,7 @@ services: context: . container_name: telegram_bot environment: - TOKEN: "7502946151:AAHspA8iieJqrhUHZveILGfeZWp-VqQhEnQ" + TOKEN: "8104061818:AAGJ6H1PTFmfJm-_mZqGv7EnHxGl4dZndnU" POSTGRES_URL: "postgresql+asyncpg://AH3J9GSPBYOP:uPS9?y~mcu2@postgres:5432/bot_db" MONGO_URL: "mongodb://root:itOj4CE2miKR@mongodb:27017" DB_NAME: "MongoDBSub&Ser" diff --git a/handlers/handlers.py b/handlers/handlers.py index 7bbbbf7..00a4c02 100644 --- a/handlers/handlers.py +++ b/handlers/handlers.py @@ -3,7 +3,7 @@ from aiogram.filters import Command from databases.postgresql import DatabaseManager from databases.model import User, Subscription, Transaction, Administrators from databases.db_config import get_postgres_session -from keyboard.keyboards import subhist_keyboard,confirm_popup_keyboard,tarif_confirm_keyboard, popup_keyboard, main_keyboard,faq_keyboard,about_tarifs_keyboard, account_keyboard, buy_keyboard,balance_keyboard,guide_keyboard,tarif_Lark_keyboard,tarif_Lark_pro_keyboard,tranhist_keyboard +from keyboard.keyboards import subhist_keyboard,confirm_popup_keyboard,tarif_confirm_keyboard, popup_keyboard, main_keyboard,faq_keyboard, account_keyboard, buy_keyboard,balance_keyboard,guide_keyboard,tarif_Lark_keyboard,tarif_Lark_pro_keyboard,tranhist_keyboard # Инициализируем менеджер базы данных db_manager = DatabaseManager(get_postgres_session) @@ -24,14 +24,26 @@ async def start_command(message: types.Message): """ Обработчик команды /start. """ - await message.answer("Привет! Я ваш Telegram-бот.", reply_markup=main_keyboard()) + await message.answer(f"""Приветствуем в рядах птенец {message.from_user.username}🐣 + \nСкорее пополни баланс, приобрети подписку и получай доступ к TikTok, YouTube, Discord, Instagram на всех устройствах без ограничений ❕❕❕ + \nОзнакомься с руководством по пользованию и выбери подходящий тариф 🦅 + \nСледи за акциями, спец-предложениями, а также розыгрышами по ссылке ниже + \n👇👇👇 + \nhttps://t.me/+0z5xqn3F1m02OTJi + \nС любовью ваши пернатые разработчики 🤍🤍🤍""", reply_markup=main_keyboard()) async def start_callback_handler(callback: types.CallbackQuery): """ Обработчик callback_query с data="base". """ await callback.message.edit_text( - f"Привет! Я ваш Telegram-бот.", + f"""Приветствуем в рядах птенец {callback.from_user.username}🐣 + \nСкорее пополни баланс, приобрети подписку и получай доступ к TikTok, YouTube, Discord, Instagram на всех устройствах без ограничений ❕❕❕ + \nОзнакомься с руководством по пользованию и выбери подходящий тариф 🦅 + \nСледи за акциями, спец-предложениями, а также розыгрышами по ссылке ниже + \n👇👇👇 + \nhttps://t.me/+0z5xqn3F1m02OTJi + \nС любовью ваши пернатые разработчики 🤍🤍🤍""", reply_markup=main_keyboard() ) @@ -48,9 +60,9 @@ async def profile_callback_handler(callback: types.CallbackQuery): return if user: + text = f"""Ваш профиль:\nID: {user.username}\nБаланс: {user.balance}""" await callback.message.edit_text( - f"Ваш профиль:\n" - f"👤 Username: {user.username}\n", + text, reply_markup=account_keyboard() ) else: @@ -71,7 +83,7 @@ async def balance_callback_handler(callback: types.CallbackQuery): if user: await callback.message.edit_text( - f"Ваш баланс: {user.balance} рубликов", + f"Ваш баланс: {user.balance} ₽", reply_markup=balance_keyboard() ) else: @@ -170,7 +182,7 @@ async def buy_subscription_callback_handler(callback: types.CallbackQuery): Обработчик callback_query с data="buy_subscription". """ await callback.message.edit_text( - f"Покупайте, покупайте потому что мы скоро закроемся!!!", + f"Ознакомься с условиями в вкладке \"О тарифах\" и выбери подходящий 🦅", reply_markup=buy_keyboard() ) @@ -201,14 +213,14 @@ async def subs_pro_callback_handler(callback: types.CallbackQuery): reply_markup=tarif_Lark_pro_keyboard() ) -async def about_tarifs_callback_handler(callback: types.CallbackQuery): - """ - Обработчик callback_query с data="about_tarifs". - """ - await callback.message.edit_text( - f"Бла бла бла, хуйня на хуйне", - reply_markup=about_tarifs_keyboard() - ) +# async def about_tarifs_callback_handler(callback: types.CallbackQuery): +# """ +# Обработчик callback_query с data="about_tarifs". +# """ +# await callback.message.edit_text( +# f"Бла бла бла, хуйня на хуйне", +# reply_markup=about_tarifs_keyboard() +# ) async def faq_callback_handler(callback:types.CallbackQuery): """ @@ -309,7 +321,7 @@ def register_handlers(dp: Dispatcher): dp.message.register(start_command, Command("start")) dp.callback_query.register(balance_callback_handler, lambda c: c.data == "balance") dp.callback_query.register(guide_callback_handler, lambda c: c.data == "guide") - dp.callback_query.register(about_tarifs_callback_handler, lambda c: c.data == "about_tarifs") + # dp.callback_query.register(about_tarifs_callback_handler, lambda c: c.data == "about_tarifs") dp.callback_query.register(lark_tariff_callback_handler, lambda c: c.data.startswith("Lark:")) dp.callback_query.register(confirm_callback_handler, lambda c: c.data.startswith("confirm:")) dp.callback_query.register(popup_confirm_callback_handler, lambda c: c.data.startswith("popup:")) \ No newline at end of file diff --git a/keyboard/keyboards.py b/keyboard/keyboards.py index c2901a0..a0fc285 100644 --- a/keyboard/keyboards.py +++ b/keyboard/keyboards.py @@ -31,7 +31,7 @@ def buy_keyboard(): builder = InlineKeyboardBuilder() builder.row(InlineKeyboardButton(text="Тариф Lark", callback_data="subs")) builder.row(InlineKeyboardButton(text="Тариф Lark Pro", callback_data="subs_pro")) - builder.row(InlineKeyboardButton(text="О тарифах", callback_data="about_tarifs")) + builder.row(InlineKeyboardButton(text="О тарифах", url="https://t.me/proxylark/19")) builder.row(InlineKeyboardButton(text="Назад", callback_data="profile")) return builder.as_markup() @@ -48,9 +48,9 @@ def popup_keyboard(): Пополнение """ builder = InlineKeyboardBuilder() - builder.row(InlineKeyboardButton(text="Пополнение на 100", callback_data="popup:100")) - builder.row(InlineKeyboardButton(text="Пополнение на 300", callback_data="popup:300")) - builder.row(InlineKeyboardButton(text="Пополнение на 500", callback_data="popup:500")) + builder.row(InlineKeyboardButton(text="200₽", callback_data="popup:200"),InlineKeyboardButton(text="500₽", callback_data="popup:500")) + builder.row(InlineKeyboardButton(text="1000₽", callback_data="popup:1000"),InlineKeyboardButton(text="2000₽", callback_data="popup:2000")) + builder.row(InlineKeyboardButton(text="3000₽", callback_data="popup:3000"),InlineKeyboardButton(text="5000₽", callback_data="popup:5000")) builder.row(InlineKeyboardButton(text="Назад", callback_data="balance")) return builder.as_markup() @@ -70,8 +70,8 @@ def tarif_Lark_keyboard(): """ builder = InlineKeyboardBuilder() builder.row(InlineKeyboardButton(text="Тариф Lark 1 Месяц", callback_data="Lark:Standart:1")) - builder.row(InlineKeyboardButton(text="Тариф Lark 3 Месяц", callback_data="Lark:Standart:3")) builder.row(InlineKeyboardButton(text="Тариф Lark 6 Месяц", callback_data="Lark:Standart:6")) + builder.row(InlineKeyboardButton(text="Тариф Lark 12 Месяц", callback_data="Lark:Standart:12")) builder.row(InlineKeyboardButton(text="Назад", callback_data="buy_subscription")) return builder.as_markup() @@ -81,8 +81,8 @@ def tarif_Lark_pro_keyboard(): """ builder = InlineKeyboardBuilder() builder.row(InlineKeyboardButton(text="Тариф Lark Pro 1 Месяц", callback_data="Lark:Pro:1")) - builder.row(InlineKeyboardButton(text="Тариф Lark Pro 3 Месяц", callback_data="Lark:Pro:3")) builder.row(InlineKeyboardButton(text="Тариф Lark Pro 6 Месяц", callback_data="Lark:Pro:6")) + builder.row(InlineKeyboardButton(text="Тариф Lark Pro 12 Месяц", callback_data="Lark:Pro:12")) builder.row(InlineKeyboardButton(text="Назад", callback_data="buy_subscription")) return builder.as_markup() @@ -97,13 +97,13 @@ def guide_keyboard(): return builder.as_markup() -def about_tarifs_keyboard(): - """ - О тарифах - """ - builder = InlineKeyboardBuilder() - builder.row(InlineKeyboardButton(text="Назад", callback_data="buy_subscription")) - return builder.as_markup() +# def about_tarifs_keyboard(): +# """ +# О тарифах +# """ +# builder = InlineKeyboardBuilder() +# builder.row(InlineKeyboardButton(text="Назад", callback_data="buy_subscription")) +# return builder.as_markup() def faq_keyboard():