diff --git a/Dockerfile b/Dockerfile index 7a35e5d0..5644fd57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,15 +12,12 @@ RUN apt-get update && \ sed -i '/ru_RU.UTF-8/s/^# //g' /etc/locale.gen && \ locale-gen ru_RU.UTF-8 -# Устанавливаем переменные окружения ENV LANG=ru_RU.UTF-8 ENV LANGUAGE=ru_RU:ru ENV LC_ALL=ru_RU.UTF-8 COPY . . -# Замена DATABASE_URL на значение из переменной окружения RUN sed -i "s|DATABASE_URL = .*|DATABASE_URL = '${DATABASE_URL}'|" config.py -# dosker-compose в полной версии бота CMD ["python", "main.py"] diff --git a/auth.py b/auth.py index 2eeae90a..8e6684a0 100644 --- a/auth.py +++ b/auth.py @@ -50,7 +50,6 @@ async def link(session, server_id: str, client_id: str, email: str): raise Exception("Не удалось получить данные клиентов.") inbounds = response["obj"][0] - # settings = json.loads(inbounds["settings"]) stream_settings = json.loads(inbounds["streamSettings"]) tcp = stream_settings.get("network", "tcp") diff --git a/bot.py b/bot.py index 9bcefb32..8a03a93f 100644 --- a/bot.py +++ b/bot.py @@ -2,10 +2,6 @@ from aiogram import Bot, Dispatcher, Router from aiogram.fsm.storage.memory import MemoryStorage from config import API_TOKEN, FREEKASSA_ENABLE, YOOKASSA_ENABLE -from handlers import commands, notifications, profile, start -from handlers.admin import admin, admin_panel, user_editor -from handlers.keys import key_management, keys -from handlers.payment import freekassa_pay, yookassa_pay from middlewares.admin import AdminMiddleware from middlewares.logging import UserActivityMiddleware @@ -14,6 +10,11 @@ storage = MemoryStorage() dp = Dispatcher(bot=bot, storage=storage) router = Router() +from handlers import commands, notifications, profile, start +from handlers.admin import admin, admin_panel, user_editor +from handlers.keys import key_management, keys +from handlers.payment import freekassa_pay, yookassa_pay + dp.include_router(admin.router) dp.include_router(admin_panel.router) diff --git a/handlers/admin/user_editor.py b/handlers/admin/user_editor.py index 38d256f1..1cff36c7 100644 --- a/handlers/admin/user_editor.py +++ b/handlers/admin/user_editor.py @@ -245,7 +245,6 @@ async def handle_key_name_input(message: types.Message, state: FSMContext): key_buttons = [] for record in user_records: - # tg_id = record["tg_id"] balance = record["balance"] email = record["email"] key = record["key"] @@ -448,7 +447,6 @@ async def process_callback_confirm_delete(callback_query: types.CallbackQuery): ) if record: - # email = record["email"] response_message = "Ключ успешно удален." back_button = types.InlineKeyboardButton( text="Назад", callback_data="view_keys" diff --git a/handlers/keys/key_management.py b/handlers/keys/key_management.py index 5b84ce55..82d7c9a6 100644 --- a/handlers/keys/key_management.py +++ b/handlers/keys/key_management.py @@ -45,7 +45,6 @@ async def process_callback_create_key(callback_query: CallbackQuery, state: FSMC async def select_server(callback_query: CallbackQuery, state: FSMContext): - # selected_server_id = (await state.get_data()).get("selected_server_id") conn = await asyncpg.connect(DATABASE_URL) try: @@ -92,8 +91,6 @@ async def select_server(callback_query: CallbackQuery, state: FSMContext): @dp.callback_query(F.data == "confirm_create_new_key") async def confirm_create_new_key(callback_query: CallbackQuery, state: FSMContext): tg_id = callback_query.from_user.id - # data = await state.get_data() - # server_id = data.get("selected_server_id") balance = await get_balance(tg_id) if balance < RENEWAL_PLANS["1"]["price"]: @@ -145,7 +142,6 @@ async def handle_key_name_input(message: Message, state: FSMContext): finally: await conn.close() - # data = await state.get_data() client_id = str(uuid.uuid4()) email = key_name.lower() current_time = datetime.utcnow() diff --git a/handlers/keys/key_utils.py b/handlers/keys/key_utils.py index a269ba18..4872dd42 100644 --- a/handlers/keys/key_utils.py +++ b/handlers/keys/key_utils.py @@ -68,7 +68,7 @@ async def delete_key_from_db(client_id): async def delete_key_from_server(server_id, client_id): """Удаление ключа с сервера""" try: - async with login_with_credentials( + async with await login_with_credentials( server_id, ADMIN_USERNAME, ADMIN_PASSWORD ) as session: success = await delete_client(session, server_id, client_id) diff --git a/handlers/keys/keys.py b/handlers/keys/keys.py index 2c03ed15..5d1be053 100644 --- a/handlers/keys/keys.py +++ b/handlers/keys/keys.py @@ -390,9 +390,7 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery): ) if record: - # email = record["email"] expiry_time = record["expiry_time"] - # current_time = datetime.utcnow().timestamp() * 1000 keyboard = types.InlineKeyboardMarkup( inline_keyboard=[ [ @@ -474,7 +472,6 @@ async def process_callback_confirm_delete(callback_query: types.CallbackQuery): ) if record: - # email = record["email"] response_message = "Ключ успешно удален." back_button = types.InlineKeyboardButton( text="Назад", callback_data="view_keys" diff --git a/handlers/keys/pic_view.jpg b/handlers/keys/pic_view.jpg index cced6e03..1064f788 100644 Binary files a/handlers/keys/pic_view.jpg and b/handlers/keys/pic_view.jpg differ diff --git a/handlers/notifications.py b/handlers/notifications.py index 25f37a03..f87a7dec 100644 --- a/handlers/notifications.py +++ b/handlers/notifications.py @@ -248,14 +248,6 @@ async def handle_expired_keys(bot: Bot, conn: asyncpg.Connection, current_time: f"Время истечения ключа: {expiry_time} (дата: {expiry_date}), Текущее время: {current_date}, Оставшееся время: {time_left}." ) - # if time_left.total_seconds() <= 0: - # days_left_message = "Ключ истек" - # elif time_left.days > 0: - # days_left_message = f"Осталось дней: {time_left.days}" - # else: - # hours_left = time_left.seconds // 3600 - # days_left_message = f"Осталось часов: {hours_left}" - message_expired = f"Ваш ключ {email} истек и был удален!\n\n Перейдите в профиль для создания нового ключа" button_profile = types.InlineKeyboardButton( text="👤 Мой профиль", callback_data="view_profile" diff --git a/handlers/payment/yookassa_pay.py b/handlers/payment/yookassa_pay.py index fc791543..4755cfe1 100644 --- a/handlers/payment/yookassa_pay.py +++ b/handlers/payment/yookassa_pay.py @@ -4,6 +4,7 @@ from aiogram import F, Router, types from aiogram.fsm.context import FSMContext from aiogram.fsm.state import State, StatesGroup from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup +from aiogram.utils.keyboard import InlineKeyboardBuilder from aiohttp import web from loguru import logger from yookassa import Configuration, Payment @@ -60,14 +61,42 @@ async def process_callback_replenish_balance( callback_query: types.CallbackQuery, state: FSMContext ): tg_id = callback_query.from_user.id - inline_keyboard = [] - for payment in PAYMENT_OPTIONS: - inline_keyboard.append( - InlineKeyboardButton( - text=payment.get("text"), callback_data=payment.get("callback_data") - ) + builder = InlineKeyboardBuilder() + + builder.row( + InlineKeyboardButton( + text=PAYMENT_OPTIONS[0]["text"], + callback_data=PAYMENT_OPTIONS[0]["callback_data"], + ), + InlineKeyboardButton( + text=PAYMENT_OPTIONS[1]["text"], + callback_data=PAYMENT_OPTIONS[1]["callback_data"], + ), + ) + builder.row( + InlineKeyboardButton( + text=PAYMENT_OPTIONS[2]["text"], + callback_data=PAYMENT_OPTIONS[2]["callback_data"], + ), + InlineKeyboardButton( + text=PAYMENT_OPTIONS[3]["text"], + callback_data=PAYMENT_OPTIONS[3]["callback_data"], + ), + ) + + builder.row( + InlineKeyboardButton( + text=PAYMENT_OPTIONS[4]["text"], + callback_data=PAYMENT_OPTIONS[4]["callback_data"], ) + ) + builder.row( + InlineKeyboardButton( + text=PAYMENT_OPTIONS[5]["text"], + callback_data=PAYMENT_OPTIONS[5]["callback_data"], + ) + ) key_count = await get_key_count(tg_id) @@ -76,14 +105,17 @@ async def process_callback_replenish_balance( if not exists: await add_connection(tg_id, balance=0.0, trial=0) - amount_keyboard = InlineKeyboardMarkup(inline_keyboard) - - await bot.delete_message( - chat_id=tg_id, message_id=callback_query.message.message_id - ) + try: + await bot.delete_message( + chat_id=tg_id, message_id=callback_query.message.message_id + ) + except Exception as e: + logger.error(f"Не удалось удалить сообщение: {e}") await bot.send_message( - chat_id=tg_id, text="Выберите сумму пополнения:", reply_markup=amount_keyboard + chat_id=tg_id, + text="Выберите сумму пополнения:", + reply_markup=builder.as_markup(), ) await state.set_state(ReplenishBalanceState.choosing_amount) diff --git a/handlers/pic.jpg b/handlers/pic.jpg index cced6e03..1064f788 100644 Binary files a/handlers/pic.jpg and b/handlers/pic.jpg differ diff --git a/handlers/profile.py b/handlers/profile.py index ea6539ba..8ee36394 100644 --- a/handlers/profile.py +++ b/handlers/profile.py @@ -58,14 +58,10 @@ async def process_callback_view_profile( ) builder.row(InlineKeyboardButton(text="⬅️ Назад", callback_data="back_to_menu")) - # Попробуем удалить предыдущее сообщение try: await callback_query.message.delete() except Exception as e: - logger.error( - f"Ошибка при удалении сообщения: {e}" - ) # Логируем ошибку, если удаление не удалось - + logger.error(f"Ошибка при удалении сообщения: {e}") if os.path.isfile(image_path): with open(image_path, "rb") as image_file: await bot.send_photo( diff --git a/pic.png b/pic.png deleted file mode 100644 index a6a548c5..00000000 Binary files a/pic.png and /dev/null differ