diff --git a/handlers/__pycache__/instructions.cpython-310.pyc b/handlers/__pycache__/instructions.cpython-310.pyc index a72d557d..6299e604 100644 Binary files a/handlers/__pycache__/instructions.cpython-310.pyc and b/handlers/__pycache__/instructions.cpython-310.pyc differ diff --git a/handlers/__pycache__/keys.cpython-310.pyc b/handlers/__pycache__/keys.cpython-310.pyc index 49d6cd33..38afa961 100644 Binary files a/handlers/__pycache__/keys.cpython-310.pyc and b/handlers/__pycache__/keys.cpython-310.pyc differ diff --git a/handlers/__pycache__/notifications.cpython-310.pyc b/handlers/__pycache__/notifications.cpython-310.pyc index b0a30e75..e4475773 100644 Binary files a/handlers/__pycache__/notifications.cpython-310.pyc and b/handlers/__pycache__/notifications.cpython-310.pyc differ diff --git a/handlers/__pycache__/pay.cpython-310.pyc b/handlers/__pycache__/pay.cpython-310.pyc index ba9e9599..47c19e57 100644 Binary files a/handlers/__pycache__/pay.cpython-310.pyc and b/handlers/__pycache__/pay.cpython-310.pyc differ diff --git a/handlers/__pycache__/profile.cpython-310.pyc b/handlers/__pycache__/profile.cpython-310.pyc index 65878ea1..2fae3fe8 100644 Binary files a/handlers/__pycache__/profile.cpython-310.pyc and b/handlers/__pycache__/profile.cpython-310.pyc differ diff --git a/handlers/__pycache__/start.cpython-310.pyc b/handlers/__pycache__/start.cpython-310.pyc index 7a6b4b41..e08ad019 100644 Binary files a/handlers/__pycache__/start.cpython-310.pyc and b/handlers/__pycache__/start.cpython-310.pyc differ diff --git a/handlers/keys.py b/handlers/keys.py index 0061644d..b3a5b6b4 100644 --- a/handlers/keys.py +++ b/handlers/keys.py @@ -139,6 +139,7 @@ async def process_callback_delete_key(callback_query: types.CallbackQuery): await bot.edit_message_text("Вы уверены, что хотите удалить ключ?", chat_id=tg_id, message_id=callback_query.message.message_id, reply_markup=confirmation_keyboard, parse_mode="HTML") await callback_query.answer() + # Обработка выбора плана продления @router.callback_query(lambda c: c.data.startswith('renew_key|')) async def process_callback_renew_key(callback_query: types.CallbackQuery): @@ -155,10 +156,12 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery): expiry_time = record['expiry_time'] current_time = datetime.utcnow().timestamp() * 1000 # Получаем текущее время в миллисекундах - # Убираем проверку на истекший ключ + # Добавляем новые планы продления (6 месяцев и год) keyboard = types.InlineKeyboardMarkup(inline_keyboard=[ [types.InlineKeyboardButton(text='📅 1 месяц (100 руб.)', callback_data=f'renew_plan|1|{client_id}')], - [types.InlineKeyboardButton(text='📅 3 месяца (250 руб.)', callback_data=f'renew_plan|3|{client_id}')], + [types.InlineKeyboardButton(text='📅 3 месяца (285 руб.)', callback_data=f'renew_plan|3|{client_id}')], + [types.InlineKeyboardButton(text='📅 6 месяцев (540 руб.)', callback_data=f'renew_plan|6|{client_id}')], + [types.InlineKeyboardButton(text='📅 12 месяцев (1000 руб.)', callback_data=f'renew_plan|12|{client_id}')], [types.InlineKeyboardButton(text='🔙 Назад', callback_data='view_profile')] ]) @@ -177,46 +180,6 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery): await callback_query.answer() -async def handle_error(tg_id, callback_query, message): - await bot.edit_message_text(message, chat_id=tg_id, message_id=callback_query.message.message_id) - -# Подтверждение удаления -@router.callback_query(lambda c: c.data.startswith('renew_key|')) -async def process_callback_renew_key(callback_query: types.CallbackQuery): - tg_id = callback_query.from_user.id - client_id = callback_query.data.split('|')[1] # Используем разделитель вертикальная черта - - try: - conn = await asyncpg.connect(DATABASE_URL) - try: - record = await conn.fetchrow('SELECT email, expiry_time FROM keys WHERE client_id = $1', client_id) - - if record: - email = record['email'] - expiry_time = record['expiry_time'] - current_time = datetime.utcnow().timestamp() * 1000 # Получаем текущее время в миллисекундах - - # Убираем проверку на истекший ключ - keyboard = types.InlineKeyboardMarkup(inline_keyboard=[ - [types.InlineKeyboardButton(text='Продлить на 1 месяц (100 руб.)', callback_data=f'renew_plan|1|{client_id}')], - [types.InlineKeyboardButton(text='Продлить на 3 месяца (250 руб.)', callback_data=f'renew_plan|3|{client_id}')], - [types.InlineKeyboardButton(text='Назад', callback_data='view_profile')] - ]) - - balance = await get_balance(tg_id) - response_message = (f"Выберите план продления:\n" - f"Баланс: {balance} руб.\n" - f"Текущая дата истечения ключа: {datetime.utcfromtimestamp(expiry_time / 1000).strftime('%Y-%m-%d %H:%M:%S')}") - - await bot.edit_message_text(response_message, chat_id=tg_id, message_id=callback_query.message.message_id, reply_markup=keyboard, parse_mode="HTML") - - finally: - await conn.close() - - except Exception as e: - await bot.edit_message_text(f"Ошибка при выборе плана: {e}", chat_id=tg_id, message_id=callback_query.message.message_id) - - await callback_query.answer() @router.callback_query(lambda c: c.data.startswith('confirm_delete|')) async def process_callback_confirm_delete(callback_query: types.CallbackQuery): @@ -259,8 +222,8 @@ async def process_callback_confirm_delete(callback_query: types.CallbackQuery): @router.callback_query(lambda c: c.data.startswith('renew_plan|')) async def process_callback_renew_plan(callback_query: types.CallbackQuery): tg_id = callback_query.from_user.id - plan, client_id = callback_query.data.split('|')[1], callback_query.data.split('|')[2] # '1' или '3' и client_id - days_to_extend = 30 * int(plan) + plan, client_id = callback_query.data.split('|')[1], callback_query.data.split('|')[2] # '1', '3', '6' или '12' и client_id + days_to_extend = 30 * int(plan) # Умножаем на количество месяцев (1 месяц = 30 дней) try: conn = await asyncpg.connect(DATABASE_URL) @@ -274,14 +237,19 @@ async def process_callback_renew_plan(callback_query: types.CallbackQuery): # Проверяем, если ключ истек, то продлеваем от текущей даты, иначе продлеваем от текущей даты истечения if expiry_time <= current_time: - # Ключ истек, начинаем отсчет от текущего времени new_expiry_time = int(current_time + timedelta(days=days_to_extend).total_seconds() * 1000) else: - # Ключ активен, продлеваем от текущей даты истечения new_expiry_time = int(expiry_time + timedelta(days=days_to_extend).total_seconds() * 1000) # Стоимость продления в зависимости от выбранного плана - cost = 100 if plan == '1' else 250 + if plan == '1': + cost = 100 + elif plan == '3': + cost = 285 + elif plan == '6': + cost = 540 # Стоимость для 6 месяцев + elif plan == '12': + cost = 1000 # Стоимость для 12 месяцев balance = await get_balance(tg_id) if balance < cost: @@ -317,5 +285,6 @@ async def process_callback_renew_plan(callback_query: types.CallbackQuery): await callback_query.answer() + async def handle_error(tg_id, callback_query, message): await bot.edit_message_text(message, chat_id=tg_id, message_id=callback_query.message.message_id) \ No newline at end of file diff --git a/handlers/pay.py b/handlers/pay.py index af8c9c5d..7f42f840 100644 --- a/handlers/pay.py +++ b/handlers/pay.py @@ -49,7 +49,7 @@ async def process_callback_replenish_balance(callback_query: types.CallbackQuery # Если записи нет, создаем нового клиента в базе данных if not exists: await add_connection(tg_id, balance=0.0, trial=0) - + await state.set_state(ReplenishBalanceState.choosing_transfer_method) keyboard = InlineKeyboardMarkup(inline_keyboard=[ [InlineKeyboardButton(text='По реквизитам', callback_data='transfer_method_requisites')], @@ -78,9 +78,8 @@ async def process_transfer_method_selection(callback_query: types.CallbackQuery, if transfer_method == 'requisites': amount_keyboard = InlineKeyboardMarkup(inline_keyboard=[ - [InlineKeyboardButton(text='100 RUB', callback_data='amount_100')], - [InlineKeyboardButton(text='300 RUB', callback_data='amount_300')], - [InlineKeyboardButton(text='500 RUB', callback_data='amount_500')], + [InlineKeyboardButton(text='100 RUB', callback_data='amount_100'), InlineKeyboardButton(text='300 RUB', callback_data='amount_300')], + [InlineKeyboardButton(text='600 RUB', callback_data='amount_600'), InlineKeyboardButton(text='1000 RUB', callback_data='amount_1000')], [InlineKeyboardButton(text='⬅️ Назад', callback_data='back_to_profile')] ]) @@ -95,6 +94,7 @@ async def process_transfer_method_selection(callback_query: types.CallbackQuery, await send_message_with_deletion(callback_query.from_user.id, "Неверный метод перевода.", state=state, message_key='transfer_method_error_message_id') return + @router.callback_query(lambda c: c.data.startswith('amount_')) async def process_amount_selection(callback_query: types.CallbackQuery, state: FSMContext): data = callback_query.data.split('_', 1) @@ -104,7 +104,11 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F return amount_str = data[1] - amount = int(amount_str) + try: + amount = int(amount_str) + except ValueError: + await send_message_with_deletion(callback_query.from_user.id, "Некорректная сумма.", state=state, message_key='amount_error_message_id') + return state_data = await state.get_data() amount_selection_message_id = state_data.get('amount_selection_message_id') @@ -155,17 +159,18 @@ async def process_admin_confirmation(callback_query: types.CallbackQuery, state: data = callback_query.data.split('_', 4) - if len(data) < 4: + if len(data) < 5: await send_message_with_deletion(callback_query.from_user.id, "Неверные данные для обработки запроса.", state=state, message_key='admin_error_message_id') return action = data[1] user_id_str = data[2] transfer_method = data[3] - amount = int(data[4]) + amount_str = data[4] try: user_id = int(user_id_str) + amount = int(amount_str) state_data = await state.get_data() requisites_message_id = state_data.get('requisites_message_id') @@ -201,6 +206,9 @@ async def process_admin_confirmation(callback_query: types.CallbackQuery, state: await send_message_with_deletion(callback_query.from_user.id, "Пополнение баланса отклонено.", state=state, message_key='admin_decline_message_id') await bot.send_message(user_id, "Ваш запрос на пополнение баланса был отклонен.") + except ValueError: + await send_message_with_deletion(callback_query.from_user.id, "Некорректные данные суммы.", state=state, message_key='admin_error_message_id') + return except Exception as e: await send_message_with_deletion(callback_query.from_user.id, f"Ошибка при пополнении баланса: {e}", state=state, message_key='admin_error_message_id') print(f"Ошибка при пополнении баланса: {e}")