From 041c8e15110407afa1486948bb6df3be913d8af5 Mon Sep 17 00:00:00 2001 From: Zakhar Izmaylov Date: Sun, 24 Nov 2024 11:26:54 +0300 Subject: [PATCH] Fix srssion --- handlers/instructions/instructions.py | 2 +- handlers/keys/key_management.py | 6 +++--- handlers/keys/keys.py | 10 +++++----- handlers/payments/cryprobot_pay.py | 11 ++++++----- handlers/payments/freekassa_pay.py | 4 ++-- handlers/payments/robokassa_pay.py | 17 +++++++++-------- handlers/payments/stars_pay.py | 7 ++++--- handlers/payments/yookassa_pay.py | 9 +++++---- handlers/profile.py | 4 ++-- handlers/start.py | 4 ++-- 10 files changed, 39 insertions(+), 35 deletions(-) diff --git a/handlers/instructions/instructions.py b/handlers/instructions/instructions.py index 8a1e9f97..dd7dc5dd 100644 --- a/handlers/instructions/instructions.py +++ b/handlers/instructions/instructions.py @@ -35,7 +35,7 @@ async def send_instructions(callback_query: types.CallbackQuery): @router.callback_query(F.data.startswith("connect_pc|")) async def process_connect_pc(callback_query: types.CallbackQuery, session: Any): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id key_name = callback_query.data.split("|")[1] record = await session.fetchrow( diff --git a/handlers/keys/key_management.py b/handlers/keys/key_management.py index 47ab10dc..0a0666d2 100644 --- a/handlers/keys/key_management.py +++ b/handlers/keys/key_management.py @@ -34,7 +34,7 @@ async def process_callback_create_key(callback_query: CallbackQuery, state: FSMC async def select_server(callback_query: CallbackQuery, state: FSMContext, session: Any): - trial_status = await get_trial(callback_query.chat.id, session) + trial_status = await get_trial(callback_query.message.chat.id, session) if trial_status == 1: builder = InlineKeyboardBuilder() builder.row( @@ -54,7 +54,7 @@ async def select_server(callback_query: CallbackQuery, state: FSMContext, sessio @router.callback_query(F.data == "confirm_create_new_key") async def confirm_create_new_key(callback_query: CallbackQuery, state: FSMContext): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id logger.info(f"User {tg_id} confirmed creation of a new key.") @@ -176,7 +176,7 @@ async def handle_key_name_input(message: Message, state: FSMContext, session: An if trial_status == 0: await use_trial(message.chat.id, session) else: - await add_connection(tg_id, 0, 1) + await add_connection(tg_id=tg_id, balance=0, trial=1, session=session) logger.info(f"Storing key for user {tg_id} in the database.") await store_key(tg_id, client_id, email, expiry_timestamp, public_link, least_loaded_cluster, session) diff --git a/handlers/keys/keys.py b/handlers/keys/keys.py index 816bd9b8..689526bf 100644 --- a/handlers/keys/keys.py +++ b/handlers/keys/keys.py @@ -35,7 +35,7 @@ router = Router() @router.callback_query(F.data == "view_keys") async def process_callback_view_keys(callback_query: types.CallbackQuery, session: Any): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id try: records = await session.fetch( """ @@ -99,7 +99,7 @@ async def process_callback_view_keys(callback_query: types.CallbackQuery, sessio @router.callback_query(F.data.startswith("view_key|")) async def process_callback_view_key(callback_query: types.CallbackQuery, session: Any): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id key_name = callback_query.data.split("|")[1] try: record = await session.fetchrow( @@ -185,7 +185,7 @@ async def process_callback_view_key(callback_query: types.CallbackQuery, session @router.callback_query(F.data.startswith("update_subscription|")) async def process_callback_update_subscription(callback_query: types.CallbackQuery, session: Any): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id email = callback_query.data.split("|")[1] try: record = await session.fetchrow( @@ -284,7 +284,7 @@ async def process_callback_delete_key(callback_query: types.CallbackQuery): @router.callback_query(F.data.startswith("renew_key|")) async def process_callback_renew_key(callback_query: types.CallbackQuery, session: Any): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id key_name = callback_query.data.split("|")[1] try: record = await session.fetchrow( @@ -390,7 +390,7 @@ async def process_callback_confirm_delete(callback_query: types.CallbackQuery, s @router.callback_query(F.data.startswith("renew_plan|")) async def process_callback_renew_plan(callback_query: types.CallbackQuery, session: Any): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id plan, client_id = ( callback_query.data.split("|")[1], callback_query.data.split("|")[2], diff --git a/handlers/payments/cryprobot_pay.py b/handlers/payments/cryprobot_pay.py index b7a5306a..acda2a1a 100644 --- a/handlers/payments/cryprobot_pay.py +++ b/handlers/payments/cryprobot_pay.py @@ -1,3 +1,4 @@ +from typing import Any from aiocryptopay import AioCryptoPay, Networks from aiogram import F, Router, types from aiogram.fsm.context import FSMContext @@ -25,7 +26,7 @@ class ReplenishBalanceState(StatesGroup): @router.callback_query(F.data == "pay_cryptobot") -async def process_callback_pay_cryptobot(callback_query: types.CallbackQuery, state: FSMContext): +async def process_callback_pay_cryptobot(callback_query: types.CallbackQuery, state: FSMContext,session:Any): builder = InlineKeyboardBuilder() for i in range(0, len(PAYMENT_OPTIONS), 2): if i + 1 < len(PAYMENT_OPTIONS): @@ -53,11 +54,11 @@ async def process_callback_pay_cryptobot(callback_query: types.CallbackQuery, st ) ) builder.row(InlineKeyboardButton(text="⬅️ Назад", callback_data="back_to_profile")) - key_count = await get_key_count(callback_query.chat.id) + key_count = await get_key_count(callback_query.message.chat.id) if key_count == 0: - exists = await check_connection_exists(callback_query.chat.id) + exists = await check_connection_exists(callback_query.message.chat.id) if not exists: - await add_connection(callback_query.chat.id, balance=0.0, trial=0) + await add_connection(tg_id=callback_query.message.chat.id, balance=0.0, trial=0,session=session) await callback_query.message.answer( "Выберите сумму пополнения:", reply_markup=builder.as_markup(), @@ -88,7 +89,7 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F asset="USDT", amount=str(int(amount // RUB_TO_USDT)), description=f"Пополнения баланса на {amount} руб", - payload=f"{callback_query.chat.id}:{int(amount)}", + payload=f"{callback_query.message.chat.id}:{int(amount)}", ) if hasattr(invoice, "bot_invoice_url"): diff --git a/handlers/payments/freekassa_pay.py b/handlers/payments/freekassa_pay.py index ca9e67da..b3c26790 100644 --- a/handlers/payments/freekassa_pay.py +++ b/handlers/payments/freekassa_pay.py @@ -130,9 +130,9 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F await callback_query.message.answer("Некорректная сумма.") return - user_email = f"{callback_query.chat.id}@solo.net" + user_email = f"{callback_query.message.chat.id}@solo.net" user_ip = callback_query.message.chat.id - payment_url = await create_payment(callback_query.chat.id, amount, user_email, user_ip) + payment_url = await create_payment(callback_query.message.chat.id, amount, user_email, user_ip) if payment_url: confirm_keyboard = InlineKeyboardMarkup( diff --git a/handlers/payments/robokassa_pay.py b/handlers/payments/robokassa_pay.py index b06ebc36..4a21eac8 100644 --- a/handlers/payments/robokassa_pay.py +++ b/handlers/payments/robokassa_pay.py @@ -1,4 +1,5 @@ import hashlib +from typing import Any from aiogram import F, Router, types from aiogram.fsm.context import FSMContext @@ -48,8 +49,8 @@ def generate_payment_link(amount, inv_id, description, tg_id): @router.callback_query(F.data == "pay_robokassa") -async def process_callback_pay_robokassa(callback_query: types.CallbackQuery, state: FSMContext): - tg_id = callback_query.chat.id +async def process_callback_pay_robokassa(callback_query: types.CallbackQuery, state: FSMContext,session:Any): + tg_id = callback_query.message.chat.id logger.info(f"User {tg_id} initiated Robokassa payment.") builder = InlineKeyboardBuilder() @@ -85,7 +86,7 @@ async def process_callback_pay_robokassa(callback_query: types.CallbackQuery, st if key_count == 0: exists = await check_connection_exists(tg_id) if not exists: - await add_connection(tg_id, balance=0.0, trial=0) + await add_connection(tg_id, balance=0.0, trial=0,session=session) logger.info(f"Created new connection for user {tg_id} with balance 0.0.") await callback_query.message.answer( @@ -117,13 +118,13 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F return await state.update_data(amount=amount) - logger.info(f"User {callback_query.chat.id} selected amount: {amount}.") + logger.info(f"User {callback_query.message.chat.id} selected amount: {amount}.") inv_id = 0 - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id payment_url = generate_payment_link(amount, inv_id, "Пополнение баланса", tg_id) - logger.info(f"Payment URL for user {callback_query.chat.id}: {payment_url}") + logger.info(f"Payment URL for user {callback_query.message.chat.id}: {payment_url}") confirm_keyboard = InlineKeyboardMarkup( inline_keyboard=[ @@ -136,7 +137,7 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F text=f"Вы выбрали пополнение на {amount} рублей. Для оплаты перейдите по ссылке ниже:", reply_markup=confirm_keyboard, ) - logger.info(f"Payment link sent to user {callback_query.chat.id}.") + logger.info(f"Payment link sent to user {callback_query.message.chat.id}.") async def robokassa_webhook(request): @@ -200,7 +201,7 @@ def check_payment_signature(params): @router.callback_query(F.data == "enter_custom_amount_robokassa") async def process_custom_amount_selection(callback_query: types.CallbackQuery, state: FSMContext): - tg_id = callback_query.chat.id + tg_id = callback_query.message.chat.id logger.info(f"User {tg_id} chose to enter a custom amount.") await callback_query.message.answer(text="Пожалуйста, введите сумму пополнения в рублях (например, 150):") diff --git a/handlers/payments/stars_pay.py b/handlers/payments/stars_pay.py index dec6b6aa..b55bff13 100644 --- a/handlers/payments/stars_pay.py +++ b/handlers/payments/stars_pay.py @@ -1,3 +1,4 @@ +from typing import Any from aiogram import F, Router, types from aiogram.fsm.context import FSMContext from aiogram.fsm.state import State, StatesGroup @@ -20,8 +21,8 @@ class ReplenishBalanceState(StatesGroup): @router.callback_query(F.data == "pay_stars") -async def process_callback_pay_stars(callback_query: types.CallbackQuery, state: FSMContext): - tg_id = callback_query.chat.id +async def process_callback_pay_stars(callback_query: types.CallbackQuery, state: FSMContext,session:Any): + tg_id = callback_query.message.chat.id builder = InlineKeyboardBuilder() builder.row(InlineKeyboardButton(text="🤖 Бот для покупки звезд", url="https://t.me/PremiumBot")) @@ -58,7 +59,7 @@ async def process_callback_pay_stars(callback_query: types.CallbackQuery, state: if key_count == 0: exists = await check_connection_exists(tg_id) if not exists: - await add_connection(tg_id, balance=0.0, trial=0) + await add_connection(tg_id, balance=0.0, trial=0,session=session) try: await callback_query.message.delete() diff --git a/handlers/payments/yookassa_pay.py b/handlers/payments/yookassa_pay.py index c2bc30a6..c8ec2ebf 100644 --- a/handlers/payments/yookassa_pay.py +++ b/handlers/payments/yookassa_pay.py @@ -1,3 +1,4 @@ +from typing import Any import uuid from aiogram import F, Router, types @@ -30,8 +31,8 @@ class ReplenishBalanceState(StatesGroup): @router.callback_query(F.data == "pay_yookassa") -async def process_callback_pay_yookassa(callback_query: types.CallbackQuery, state: FSMContext): - tg_id = callback_query.chat.id +async def process_callback_pay_yookassa(callback_query: types.CallbackQuery, state: FSMContext,session:Any): + tg_id = callback_query.message.chat.id builder = InlineKeyboardBuilder() @@ -67,7 +68,7 @@ async def process_callback_pay_yookassa(callback_query: types.CallbackQuery, sta if key_count == 0: exists = await check_connection_exists(tg_id) if not exists: - await add_connection(tg_id, balance=0.0, trial=0) + await add_connection(tg_id, balance=0.0, trial=0,session=session) await callback_query.message.answer( text="Выберите сумму пополнения:", @@ -95,7 +96,7 @@ async def process_amount_selection(callback_query: types.CallbackQuery, state: F # state_data = await state.get_data() customer_name = callback_query.from_user.full_name - customer_id = callback_query.chat.id + customer_id = callback_query.message.chat.id customer_email = f"{customer_id}@solo.net" diff --git a/handlers/profile.py b/handlers/profile.py index bdf8edba..e4d67c20 100644 --- a/handlers/profile.py +++ b/handlers/profile.py @@ -14,7 +14,7 @@ router = Router() @router.callback_query(F.data == "profile") async def process_callback_view_profile(callback_query: types.CallbackQuery, state: FSMContext, admin: bool): - chat_id = callback_query.chat.id + chat_id = callback_query.message.chat.id username = callback_query.from_user.full_name image_path = os.path.join("img", "pic.jpg") key_count = await get_key_count(chat_id) @@ -84,7 +84,7 @@ async def view_tariffs_handler(callback_query: types.CallbackQuery): @router.callback_query(F.data == "invite") async def invite_handler(callback_query: types.CallbackQuery): - chat_id = callback_query.chat.id + chat_id = callback_query.message.chat.id referral_link = get_referral_link(chat_id) referral_stats = await get_referral_stats(chat_id) diff --git a/handlers/start.py b/handlers/start.py index 2aafbccc..b199fc9a 100644 --- a/handlers/start.py +++ b/handlers/start.py @@ -30,7 +30,7 @@ async def start_command(message: Message, state: FSMContext, session: Any, admin pass connection_exists = await check_connection_exists(message.chat.id) if not connection_exists: - await add_connection(message.chat.id, session) + await add_connection(tg_id=message.chat.id, session=session) trial_status = await get_trial(message.chat.id, session) image_path = os.path.join("img", "pic.jpg") @@ -64,7 +64,7 @@ async def start_command(message: Message, state: FSMContext, session: Any, admin @router.callback_query(F.data == "connect_vpn") async def handle_connect_vpn(callback_query: CallbackQuery, session: Any): - user_id = callback_query.chat.id + user_id = callback_query.message.chat.id trial_key_info = await create_trial_key(user_id, session)