From 48528e611fbfa3c5d9cf5090a2bd10d70927f7c4 Mon Sep 17 00:00:00 2001 From: Vladless Date: Sat, 2 Nov 2024 01:17:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20v2raytun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/keys/key_management.py | 13 +++---- handlers/keys/keys.py | 29 +++++++++++----- handlers/pay.py | 7 ++-- handlers/profile.py | 61 +++++++++++++++++---------------- 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/handlers/keys/key_management.py b/handlers/keys/key_management.py index 06d765a5..cf4603aa 100644 --- a/handlers/keys/key_management.py +++ b/handlers/keys/key_management.py @@ -1,7 +1,7 @@ import uuid from datetime import datetime, timedelta -from bot import dp +from bot import dp, bot import asyncpg from aiogram import F, Router from aiogram.fsm.context import FSMContext @@ -43,16 +43,17 @@ async def process_callback_create_key(callback_query: CallbackQuery, state: FSMC await conn.close() button_back = InlineKeyboardButton(text='⬅️ Назад', callback_data='view_profile') - server_buttons.append([button_back]) + server_buttons.append([button_back]) - await callback_query.message.edit_text( - "⚙️ Выберите сервер для создания ключа:", + await callback_query.message.delete() + await bot.send_message( + chat_id=tg_id, + text="⚙️ Выберите сервер для создания ключа:", parse_mode="HTML", reply_markup=InlineKeyboardMarkup(inline_keyboard=server_buttons) ) - - await state.set_state(Form.waiting_for_server_selection) + await state.set_state(Form.waiting_for_server_selection) await callback_query.answer() diff --git a/handlers/keys/keys.py b/handlers/keys/keys.py index cf886a22..2a21bc29 100644 --- a/handlers/keys/keys.py +++ b/handlers/keys/keys.py @@ -42,20 +42,32 @@ async def process_callback_view_keys(callback_query: types.CallbackQuery): inline_keyboard = types.InlineKeyboardMarkup(inline_keyboard=buttons) response_message = ( "Это ваши устройства:\n\n" - "Нажмите на имя устройства для управления его ключом." # Добавлено курсивом + "Нажмите на имя устройства для управления его ключом." ) - await bot.edit_message_text(response_message, chat_id=tg_id, message_id=callback_query.message.message_id, reply_markup=inline_keyboard, parse_mode="HTML") - else: - response_message = ( - NO_KEYS + await bot.delete_message(chat_id=tg_id, message_id=callback_query.message.message_id) + + await bot.send_message( + chat_id=tg_id, + text=response_message, + reply_markup=inline_keyboard, + parse_mode="HTML" ) + else: + response_message = NO_KEYS create_key_button = types.InlineKeyboardButton(text='➕ Создать ключ', callback_data='create_key') back_button = types.InlineKeyboardButton(text='🔙 Назад', callback_data='view_profile') keyboard = types.InlineKeyboardMarkup(inline_keyboard=[[create_key_button], [back_button]]) - await bot.edit_message_text(response_message, chat_id=tg_id, message_id=callback_query.message.message_id, reply_markup=keyboard, parse_mode="HTML") + await bot.delete_message(chat_id=tg_id, message_id=callback_query.message.message_id) + + await bot.send_message( + chat_id=tg_id, + text=response_message, + reply_markup=keyboard, + parse_mode="HTML" + ) finally: await conn.close() @@ -65,7 +77,6 @@ async def process_callback_view_keys(callback_query: types.CallbackQuery): await callback_query.answer() - @router.callback_query(lambda c: c.data.startswith('view_key|')) async def process_callback_view_key(callback_query: types.CallbackQuery): tg_id = callback_query.from_user.id @@ -355,11 +366,11 @@ async def process_callback_select_server(callback_query: types.CallbackQuery): back_button = types.InlineKeyboardButton(text='Назад', callback_data='view_keys') iphone_button = types.InlineKeyboardButton( text='🍏IPhone', - url=f'{APP_URL}/?url=streisand://import/{new_key}' + url=f'{APP_URL}/?url=v2raytun://import/{new_key}' ) android_button = types.InlineKeyboardButton( text='🤖Android', - url=f'{APP_URL}/?url=v2rayng://install-sub?url={new_key}' + url=f'{APP_URL}/?url=v2raytun://import-sub?url={new_key}' ) keyboard = types.InlineKeyboardMarkup( diff --git a/handlers/pay.py b/handlers/pay.py index 8b81498f..b95d85d1 100644 --- a/handlers/pay.py +++ b/handlers/pay.py @@ -76,14 +76,17 @@ async def process_callback_replenish_balance(callback_query: types.CallbackQuery ] ]) - await callback_query.message.edit_text( + await bot.delete_message(chat_id=tg_id, message_id=callback_query.message.message_id) + + await bot.send_message( + chat_id=tg_id, text="Выберите сумму пополнения:", reply_markup=amount_keyboard ) + await state.set_state(ReplenishBalanceState.choosing_amount) await callback_query.answer() - @router.callback_query(lambda c: c.data == 'back_to_profile') async def back_to_profile_handler(callback_query: types.CallbackQuery, state: FSMContext): await process_callback_view_profile(callback_query, state) diff --git a/handlers/profile.py b/handlers/profile.py index 7cee93a8..d58bbcb6 100644 --- a/handlers/profile.py +++ b/handlers/profile.py @@ -1,7 +1,9 @@ +import os + from aiogram import Router, types from aiogram.fsm.context import FSMContext from aiogram.fsm.state import State, StatesGroup -from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup +from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, BufferedInputFile from bot import bot from database import get_balance, get_key_count, get_referral_stats @@ -14,54 +16,53 @@ class ReplenishBalanceState(StatesGroup): router = Router() + async def process_callback_view_profile(callback_query: types.CallbackQuery, state: FSMContext): tg_id = callback_query.from_user.id username = callback_query.from_user.full_name + image_path = os.path.join(os.path.dirname(__file__), 'pic.jpg') + + if not os.path.isfile(image_path): + await bot.send_message(tg_id, "Файл изображения не найден.") + return + try: key_count = await get_key_count(tg_id) balance = await get_balance(tg_id) if balance is None: balance = 0 - profile_message = ( - profile_message_send(username, tg_id, balance, key_count) - ) - + profile_message = profile_message_send(username, tg_id, balance, key_count) + profile_message += ( f"Обязательно подпишитесь на канал здесь\n" ) if key_count == 0: - profile_message += "\nНажмите ➕Устройство снизу чтобы добавить устройство в VPN" + profile_message += "\nНажмите ➕Устройство снизу, чтобы добавить устройство в VPN" - button_create_key = InlineKeyboardButton(text='➕ Устройство', callback_data='create_key') - button_view_keys = InlineKeyboardButton(text='📱 Мои устройства', callback_data='view_keys') - button_replenish_balance = InlineKeyboardButton(text='💳 Пополнить баланс', callback_data='replenish_balance') - button_invite = InlineKeyboardButton(text='👥 Пригласить', callback_data='invite') - button_instructions = InlineKeyboardButton(text='📘 Инструкции', callback_data='instructions') - button_back = InlineKeyboardButton(text='⬅️ Назад', callback_data='back_to_menu') - - keyboard = InlineKeyboardMarkup(inline_keyboard=[ - [button_create_key, button_view_keys], - [button_replenish_balance], - [button_invite, button_instructions], - [button_back] + inline_keyboard = InlineKeyboardMarkup(inline_keyboard=[ + [InlineKeyboardButton(text='➕ Устройство', callback_data='create_key'), InlineKeyboardButton(text='📱 Мои устройства', callback_data='view_keys')], + [InlineKeyboardButton(text='💳 Пополнить баланс', callback_data='replenish_balance')], + [InlineKeyboardButton(text='👥 Пригласить', callback_data='invite'), InlineKeyboardButton(text='📘 Инструкции', callback_data='instructions')], + [InlineKeyboardButton(text='⬅️ Назад', callback_data='back_to_menu')] ]) + await callback_query.message.delete() + + with open(image_path, 'rb') as image_file: + await bot.send_photo( + chat_id=tg_id, + photo=BufferedInputFile(image_file.read(), filename="pic.jpg"), + caption=profile_message, + parse_mode='HTML', + reply_markup=inline_keyboard + ) + except Exception as e: - profile_message = f"❗️ Ошибка при получении данных профиля: {e}" - keyboard = None - - await callback_query.message.delete() - - await bot.send_message( - chat_id=tg_id, - text=profile_message, - parse_mode='HTML', - reply_markup=keyboard - ) - + await bot.send_message(tg_id, f"❗️ Ошибка при получении данных профиля: {e}") + await callback_query.answer() @router.callback_query(lambda c: c.data == 'invite')