Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ async def errors_handler(
),
caption=f"{hbold(type(event.exception).__name__)}: {str(event.exception)[:1021]}...",
)
try:
from handlers.start import handle_start_callback_query, start_command

if event.update.message:
await start_command(event.update.message, state=dp.storage, session=None, admin=False, captcha=False)
elif event.update.callback_query:
await handle_start_callback_query(
event.update.callback_query, state=dp.storage, session=None, admin=False, captcha=False
)
except Exception as e:
logger.error(f"Ошибка при показе стартового меню после ошибки: {e}")
except TelegramBadRequest as exception:
logger.warning(f"Failed to send error details: {exception}")
except Exception as exception:
Expand Down
5 changes: 3 additions & 2 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ async def get_keys(tg_id: int, session: Any):
try:
records = await session.fetch(
"""
SELECT client_id, email, created_at, key
SELECT *
FROM keys
WHERE tg_id = $1
""",
Expand Down Expand Up @@ -1234,7 +1234,7 @@ async def store_gift_link(
async def get_key_details(email, session):
record = await session.fetchrow(
"""
SELECT k.key, k.email, k.expiry_time, k.server_id,k, k.client_id, k.created_at, c.tg_id, c.balance
SELECT k.server_id, k.key, k.email, k.expiry_time, k.client_id, k.created_at, c.tg_id, c.balance
FROM keys k
JOIN connections c ON k.tg_id = c.tg_id
WHERE k.email = $1
Expand Down Expand Up @@ -1262,6 +1262,7 @@ async def get_key_details(email, session):

return {
"key": record["key"],
"server_id": record["server_id"],
"created_at": record["created_at"],
"expiry_time": record["expiry_time"],
"client_id": record["client_id"],
Expand Down
2 changes: 0 additions & 2 deletions handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from .payments import router as payments_router
from .profile import router as profile_router
from .start import router as start_router
from .user import router as user_router

router = Router(name="handlers_main_router")

Expand All @@ -29,5 +28,4 @@
keys_router,
instructions_router,
admin_router,
user_router,
)
13 changes: 6 additions & 7 deletions handlers/admin/admin_coupons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from aiogram import F, Router, types
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import State, StatesGroup
from aiogram.types import CallbackQuery, Message

from database import create_coupon, delete_coupon, get_all_coupons
from filters.admin import IsAdminFilter
Expand All @@ -22,7 +23,7 @@ class AdminCouponsState(StatesGroup):
IsAdminFilter(),
)
async def handle_coupons(
callback_query: types.CallbackQuery,
callback_query: CallbackQuery,
):
await callback_query.message.edit_text(text="🛠 Меню управления купонами:", reply_markup=build_coupons_kb())

Expand All @@ -31,7 +32,7 @@ async def handle_coupons(
AdminPanelCallback.filter(F.action == "coupons_create"),
IsAdminFilter(),
)
async def handle_coupons_create(callback_query: types.CallbackQuery, state: FSMContext):
async def handle_coupons_create(callback_query: CallbackQuery, state: FSMContext):
text = (
"🎫 <b>Введите данные для создания купона в формате:</b>\n\n"
"📝 <i>код</i> 💰 <i>сумма</i> 🔢 <i>лимит</i>\n\n"
Expand All @@ -46,7 +47,7 @@ async def handle_coupons_create(callback_query: types.CallbackQuery, state: FSMC


@router.message(AdminCouponsState.waiting_for_coupon_data, IsAdminFilter())
async def handle_coupon_data_input(message: types.Message, state: FSMContext, session: Any):
async def handle_coupon_data_input(message: Message, state: FSMContext, session: Any):
text = message.text.strip()
parts = text.split()

Expand Down Expand Up @@ -98,7 +99,7 @@ async def handle_coupon_data_input(message: types.Message, state: FSMContext, se
AdminPanelCallback.filter(F.action == "coupons_list"),
IsAdminFilter(),
)
async def handle_coupons_list(callback_query: types.CallbackQuery, session: Any):
async def handle_coupons_list(callback_query: CallbackQuery, session: Any):
try:
page = int(callback_query.data.split(":")[1]) if ":" in callback_query.data else 1
per_page = 10
Expand Down Expand Up @@ -136,9 +137,7 @@ async def handle_coupons_list(callback_query: types.CallbackQuery, session: Any)
AdminCouponDeleteCallback.filter(),
IsAdminFilter(),
)
async def handle_coupon_delete(
callback_query: types.CallbackQuery, callback_data: AdminCouponDeleteCallback, session: Any
):
async def handle_coupon_delete(callback_query: CallbackQuery, callback_data: AdminCouponDeleteCallback, session: Any):
coupon_code = callback_data.coupon_code

try:
Expand Down
4 changes: 2 additions & 2 deletions handlers/admin/admin_panel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from aiogram import F, Router, types
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery
from aiogram.types import CallbackQuery, Message

from bot import version
from filters.admin import IsAdminFilter
Expand All @@ -24,7 +24,7 @@ async def handle_admin_callback_query(callback_query: CallbackQuery, state: FSMC


@router.message(Command("admin"), IsAdminFilter())
async def handle_admin_message(message: types.Message, state: FSMContext):
async def handle_admin_message(message: Message, state: FSMContext):
text = f"🤖 Панель администратора\n📌 Версия бота: {version}"

await state.clear()
Expand Down
4 changes: 2 additions & 2 deletions handlers/admin/admin_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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 CallbackQuery
from aiogram.types import CallbackQuery, Message

from filters.admin import IsAdminFilter
from keyboards.admin.panel_kb import AdminPanelCallback, build_admin_back_kb
Expand Down Expand Up @@ -58,7 +58,7 @@ async def handle_sender_callback(callback_query: CallbackQuery, session: Any):
AdminSender.waiting_for_message,
IsAdminFilter(),
)
async def handle_message_input(message: types.Message, state: FSMContext, session: Any):
async def handle_message_input(message: Message, state: FSMContext, session: Any):
text_message = message.text

try:
Expand Down
26 changes: 14 additions & 12 deletions handlers/admin/admin_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aiogram import F, Router, types
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import State, StatesGroup
from aiogram.types import CallbackQuery, Message
from py3xui import AsyncApi

from backup import create_backup_and_send_to_admins
Expand Down Expand Up @@ -37,7 +38,7 @@ class AdminServersEditor(StatesGroup):
AdminPanelCallback.filter(F.action == "servers"),
IsAdminFilter(),
)
async def handle_servers(callback_query: types.CallbackQuery):
async def handle_servers(callback_query: CallbackQuery):
servers = await get_servers()

text = (
Expand All @@ -58,7 +59,7 @@ async def handle_servers(callback_query: types.CallbackQuery):
AdminPanelCallback.filter(F.action == "clusters_add"),
IsAdminFilter(),
)
async def handle_clusters_add(callback_query: types.CallbackQuery, state: FSMContext):
async def handle_clusters_add(callback_query: CallbackQuery, state: FSMContext):
text = (
"🔧 <b>Введите имя нового кластера:</b>\n\n"
"<b>Имя кластера должно быть уникальным!</b>\n"
Expand All @@ -71,7 +72,7 @@ async def handle_clusters_add(callback_query: types.CallbackQuery, state: FSMCon


@router.message(AdminServersEditor.waiting_for_cluster_name, IsAdminFilter())
async def handle_cluster_name_input(message: types.Message, state: FSMContext):
async def handle_cluster_name_input(message: Message, state: FSMContext):
if not message.text:
await message.answer(
text="❌ Имя кластера не может быть пустым. Попробуйте снова.", reply_markup=build_admin_back_kb("servers")
Expand All @@ -96,7 +97,7 @@ async def handle_cluster_name_input(message: types.Message, state: FSMContext):


@router.message(AdminServersEditor.waiting_for_server_name, IsAdminFilter())
async def handle_server_name_input(message: types.Message, state: FSMContext):
async def handle_server_name_input(message: Message, state: FSMContext, session: Any):
if not message.text:
await message.answer(
text="❌ Имя сервера не может быть пустым. Попробуйте снова.", reply_markup=build_admin_back_kb("servers")
Expand All @@ -105,15 +106,16 @@ async def handle_server_name_input(message: types.Message, state: FSMContext):

server_name = message.text.strip()

if not await check_unique_server_name(server_name):
user_data = await state.get_data()
cluster_name = user_data.get("cluster_name")

if not await check_unique_server_name(server_name, session, cluster_name):
await message.answer(
text="❌ Сервер с таким именем уже существует. Пожалуйста, выберите другое имя.",
reply_markup=build_admin_back_kb("servers"),
)
return

user_data = await state.get_data()
cluster_name = user_data.get("cluster_name")
await state.update_data(server_name=server_name)

text = (
Expand All @@ -132,7 +134,7 @@ async def handle_server_name_input(message: types.Message, state: FSMContext):


@router.message(AdminServersEditor.waiting_for_api_url, IsAdminFilter())
async def handle_api_url_input(message: types.Message, state: FSMContext):
async def handle_api_url_input(message: Message, state: FSMContext, session: Any):
if not message.text or not message.text.strip().startswith("https://"):
await message.answer(
text="❌ API URL должен начинаться с <code>https://</code>. Попробуйте снова.",
Expand Down Expand Up @@ -164,7 +166,7 @@ async def handle_api_url_input(message: types.Message, state: FSMContext):


@router.message(AdminServersEditor.waiting_for_subscription_url, IsAdminFilter())
async def handle_subscription_url_input(message: types.Message, state: FSMContext):
async def handle_subscription_url_input(message: Message, state: FSMContext):
if not message.text or not message.text.strip().startswith("https://"):
await message.answer(
text="❌ subscription_url должен начинаться с <code>https://</code>. Попробуйте снова.",
Expand Down Expand Up @@ -192,7 +194,7 @@ async def handle_subscription_url_input(message: types.Message, state: FSMContex


@router.message(AdminServersEditor.waiting_for_inbound_id, IsAdminFilter())
async def handle_inbound_id_input(message: types.Message, state: FSMContext):
async def handle_inbound_id_input(message: Message, state: FSMContext):
inbound_id = message.text.strip()

if not inbound_id.isdigit():
Expand Down Expand Up @@ -283,7 +285,7 @@ async def handle_servers_availability(


@router.callback_query(AdminServerEditorCallback.filter(F.action == "servers_manage"), IsAdminFilter())
async def handle_servers_manage(callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback):
async def handle_servers_manage(callback_query: CallbackQuery, callback_data: AdminServerEditorCallback):
server_name = callback_data.data
servers = await get_servers()

Expand Down Expand Up @@ -312,7 +314,7 @@ async def handle_servers_manage(callback_query: types.CallbackQuery, callback_da


@router.callback_query(AdminServerEditorCallback.filter(F.action == "servers_delete"), IsAdminFilter())
async def handle_servers_delete(callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback):
async def handle_servers_delete(callback_query: CallbackQuery, callback_data: AdminServerEditorCallback):
server_name = callback_data.data

await callback_query.message.edit_text(
Expand Down
Loading
Loading