From 0ca55040bd8baffe1dbc83adccb51a178b321f25 Mon Sep 17 00:00:00 2001 From: hteppl Date: Thu, 16 Jan 2025 09:20:33 +0300 Subject: [PATCH] Rename handlers functions with actual names + delete parse_mode --- handlers/admin/admin_backups.py | 2 +- handlers/admin/admin_coupons.py | 14 +++++++------- handlers/admin/admin_restart.py | 2 +- handlers/admin/admin_sender.py | 2 +- handlers/admin/admin_servers.py | 29 +++++++++-------------------- handlers/admin/admin_stats.py | 6 +++--- handlers/admin/admin_users.py | 22 +++++++++++----------- 7 files changed, 33 insertions(+), 44 deletions(-) diff --git a/handlers/admin/admin_backups.py b/handlers/admin/admin_backups.py index 6d14fba5..fef74df2 100644 --- a/handlers/admin/admin_backups.py +++ b/handlers/admin/admin_backups.py @@ -12,7 +12,7 @@ router = Router() AdminPanelCallback.filter(F.action == "backups"), IsAdminFilter(), ) -async def handle_backup( +async def handle_backups( callback_query: CallbackQuery ): kb = build_admin_back_kb("management") diff --git a/handlers/admin/admin_coupons.py b/handlers/admin/admin_coupons.py index 357b9946..d1a34644 100644 --- a/handlers/admin/admin_coupons.py +++ b/handlers/admin/admin_coupons.py @@ -21,7 +21,7 @@ class AdminCouponsState(StatesGroup): AdminPanelCallback.filter(F.action == "coupons"), IsAdminFilter(), ) -async def show_coupon_management_menu( +async def handle_coupons( callback_query: types.CallbackQuery, ): await callback_query.message.edit_text( @@ -34,7 +34,7 @@ async def show_coupon_management_menu( AdminPanelCallback.filter(F.action == "coupons_create"), IsAdminFilter(), ) -async def handle_create_coupon( +async def handle_coupons_create( callback_query: types.CallbackQuery, state: FSMContext ): @@ -55,7 +55,7 @@ async def handle_create_coupon( AdminCouponsState.waiting_for_coupon_data, IsAdminFilter() ) -async def process_coupon_data( +async def handle_coupon_data_input( message: types.Message, state: FSMContext, session: Any @@ -117,7 +117,7 @@ async def process_coupon_data( AdminPanelCallback.filter(F.action == "coupons_list"), IsAdminFilter(), ) -async def show_coupon_list( +async def handle_coupons_list( callback_query: types.CallbackQuery, session: Any ): @@ -155,7 +155,7 @@ async def show_coupon_list( AdminCouponDeleteCallback.filter(), IsAdminFilter(), ) -async def handle_delete_coupon( +async def handle_coupon_delete( callback_query: types.CallbackQuery, callback_data: AdminCouponDeleteCallback, session: Any @@ -166,12 +166,12 @@ async def handle_delete_coupon( result = await delete_coupon_from_db(coupon_code, session) if result: - await show_coupon_list(callback_query, session) + await handle_coupons_list(callback_query, session) else: await callback_query.message.edit_text( text=f"❌ Купон с кодом {coupon_code} не найден.", ) - await show_coupon_list(callback_query, session) + await handle_coupons_list(callback_query, session) except Exception as e: logger.error(f"Ошибка при удалении купона: {e}") diff --git a/handlers/admin/admin_restart.py b/handlers/admin/admin_restart.py index be39f694..157bf13b 100644 --- a/handlers/admin/admin_restart.py +++ b/handlers/admin/admin_restart.py @@ -24,7 +24,7 @@ async def handle_restart(callback_query: CallbackQuery): AdminPanelCallback.filter(F.action == "restart_confirm"), IsAdminFilter(), ) -async def confirm_restart_bot(callback_query: CallbackQuery): +async def handle_restart_confirm(callback_query: CallbackQuery): kb = build_admin_back_kb() try: subprocess.run( diff --git a/handlers/admin/admin_sender.py b/handlers/admin/admin_sender.py index 7f691d5d..e82598bd 100644 --- a/handlers/admin/admin_sender.py +++ b/handlers/admin/admin_sender.py @@ -52,7 +52,7 @@ async def handle_sender_callback( AdminSender.waiting_for_message, IsAdminFilter(), ) -async def process_message( +async def handle_message_input( message: types.Message, state: FSMContext, session: Any diff --git a/handlers/admin/admin_servers.py b/handlers/admin/admin_servers.py index 1b12d60e..dffe9726 100644 --- a/handlers/admin/admin_servers.py +++ b/handlers/admin/admin_servers.py @@ -28,7 +28,7 @@ class AdminServersEditor(StatesGroup): AdminPanelCallback.filter(F.action == "servers"), IsAdminFilter(), ) -async def handle_servers_editor( +async def handle_servers( callback_query: types.CallbackQuery ): servers = await get_servers_from_db() @@ -43,7 +43,6 @@ async def handle_servers_editor( await callback_query.message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_clusters_editor_kb(servers), ) @@ -52,7 +51,7 @@ async def handle_servers_editor( AdminPanelCallback.filter(F.action == "clusters_add"), IsAdminFilter(), ) -async def handle_add_cluster( +async def handle_clusters_add( callback_query: types.CallbackQuery, state: FSMContext ): @@ -64,7 +63,6 @@ async def handle_add_cluster( await callback_query.message.edit_text( text=text, - parse_mode="HTML", ) await state.set_state(AdminServersEditor.waiting_for_cluster_name) @@ -95,7 +93,6 @@ async def handle_cluster_name_input( await message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_admin_back_kb("servers"), ) @@ -137,7 +134,6 @@ async def handle_server_name_input( await message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_admin_back_kb("servers"), ) @@ -155,7 +151,6 @@ async def handle_api_url_input( if not message.text or not message.text.strip().startswith("https://"): await message.answer( text="❌ API URL должен начинаться с https://. Попробуйте снова.", - parse_mode="HTML", ) return @@ -176,7 +171,6 @@ async def handle_api_url_input( await message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_cancel_kb(), ) @@ -194,7 +188,6 @@ async def handle_subscription_url_input( if not message.text or not message.text.strip().startswith("https://"): await message.answer( text="❌ subscription_url должен начинаться с https://. Попробуйте снова.", - parse_mode="HTML", ) return @@ -212,7 +205,6 @@ async def handle_subscription_url_input( await message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_admin_back_kb("servers"), ) await state.set_state(AdminServersEditor.waiting_for_inbound_id) @@ -266,7 +258,7 @@ async def handle_inbound_id_input( AdminServerEditorCallback.filter(F.action == "clusters_manage"), IsAdminFilter() ) -async def handle_manage_cluster( +async def handle_clusters_manage( callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback, ): @@ -285,7 +277,7 @@ async def handle_manage_cluster( AdminServerEditorCallback.filter(F.action == "servers_availability"), IsAdminFilter() ) -async def handle_check_server_availability( +async def handle_servers_availability( callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback ): @@ -339,7 +331,7 @@ async def handle_check_server_availability( AdminServerEditorCallback.filter(F.action == "servers_manage"), IsAdminFilter() ) -async def handle_manage_server( +async def handle_servers_manage( callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback ): @@ -366,7 +358,6 @@ async def handle_manage_server( await callback_query.message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_manage_server_kb(server_name, cluster_name), ) else: @@ -379,7 +370,7 @@ async def handle_manage_server( AdminServerEditorCallback.filter(F.action == "servers_delete"), IsAdminFilter() ) -async def handle_delete_server( +async def handle_servers_delete( callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback ): @@ -395,7 +386,7 @@ async def handle_delete_server( AdminServerEditorCallback.filter(F.action == "servers_delete_confirm"), IsAdminFilter() ) -async def handle_confirm_delete_server( +async def handle_servers_delete_confirm( callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback ): @@ -420,7 +411,7 @@ async def handle_confirm_delete_server( AdminServerEditorCallback.filter(F.action == "servers_add"), IsAdminFilter() ) -async def handle_add_server( +async def handle_servers_add( callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback, state: FSMContext @@ -437,7 +428,6 @@ async def handle_add_server( await callback_query.message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_admin_back_kb("servers"), ) @@ -448,7 +438,7 @@ async def handle_add_server( AdminServerEditorCallback.filter(F.action == "clusters_backup"), IsAdminFilter() ) -async def handle_backup_cluster( +async def handle_clusters_backup( callback_query: types.CallbackQuery, callback_data: AdminServerEditorCallback, ): @@ -472,6 +462,5 @@ async def handle_backup_cluster( await callback_query.message.edit_text( text=text, - parse_mode="HTML", reply_markup=build_admin_back_kb("servers"), ) diff --git a/handlers/admin/admin_stats.py b/handlers/admin/admin_stats.py index e5e4a869..ff5191b6 100644 --- a/handlers/admin/admin_stats.py +++ b/handlers/admin/admin_stats.py @@ -17,7 +17,7 @@ router = Router() AdminPanelCallback.filter(F.action == "stats"), IsAdminFilter(), ) -async def user_stats_menu(callback_query: CallbackQuery, session: Any): +async def handle_stats(callback_query: CallbackQuery, session: Any): try: total_users = await session.fetchval("SELECT COUNT(*) FROM users") total_keys = await session.fetchval("SELECT COUNT(*) FROM keys") @@ -90,7 +90,7 @@ async def user_stats_menu(callback_query: CallbackQuery, session: Any): AdminPanelCallback.filter(F.action == "stats_export_users_csv"), IsAdminFilter(), ) -async def export_users_csv(callback_query: CallbackQuery, session: Any): +async def handle_export_users_csv(callback_query: CallbackQuery, session: Any): kb = build_admin_back_kb("stats") try: @@ -144,7 +144,7 @@ async def export_users_csv(callback_query: CallbackQuery, session: Any): AdminPanelCallback.filter(F.action == "stats_export_payments_csv"), IsAdminFilter(), ) -async def export_payments_csv(callback_query: CallbackQuery, session: Any): +async def handle_export_payments_csv(callback_query: CallbackQuery, session: Any): kb = build_admin_back_kb("stats") try: diff --git a/handlers/admin/admin_users.py b/handlers/admin/admin_users.py index 4f48a5ac..cf97d751 100644 --- a/handlers/admin/admin_users.py +++ b/handlers/admin/admin_users.py @@ -38,7 +38,7 @@ class UserEditorState(StatesGroup): AdminPanelCallback.filter(F.action == "search_user"), IsAdminFilter(), ) -async def handle_users_search( +async def handle_search_user( callback_query: CallbackQuery, state: FSMContext ): @@ -59,7 +59,7 @@ async def handle_users_search( AdminPanelCallback.filter(F.action == "search_key"), IsAdminFilter(), ) -async def handle_users_search_key( +async def handle_search_key( callback_query: CallbackQuery, state: FSMContext ): @@ -196,7 +196,7 @@ async def handle_message_text_input( AdminUserEditorCallback.filter(F.action == "users_trial_restore"), IsAdminFilter(), ) -async def handle_restore_trial( +async def handle_trial_restore( callback_query: types.CallbackQuery, callback_data: AdminUserEditorCallback, session: Any @@ -213,7 +213,7 @@ async def handle_restore_trial( AdminUserEditorCallback.filter(F.action == "users_balance_change"), IsAdminFilter() ) -async def process_balance_change( +async def handle_balance_change( callback_query: CallbackQuery, callback_data: AdminUserEditorCallback, state: FSMContext @@ -264,7 +264,7 @@ async def handle_new_balance_input( AdminUserEditorCallback.filter(F.action == "users_key_edit"), IsAdminFilter() ) -async def process_key_edit( +async def handle_key_edit( callback_query: CallbackQuery, callback_data: AdminUserEditorCallback, session: Any @@ -296,7 +296,7 @@ async def process_key_edit( AdminUserEditorCallback.filter(F.action == "users_change_expiry"), IsAdminFilter() ) -async def prompt_expiry_change( +async def handle_change_expiry( callback_query: CallbackQuery, callback_data: AdminUserEditorCallback, state: FSMContext @@ -390,7 +390,7 @@ async def handle_expiry_time_input( AdminUserEditorCallback.filter(F.action == "users_delete_key"), IsAdminFilter() ) -async def process_callback_delete_key( +async def handle_delete_key( callback_query: types.CallbackQuery, callback_data: AdminUserEditorCallback, session: Any @@ -417,7 +417,7 @@ async def process_callback_delete_key( AdminUserEditorCallback.filter(F.action == "users_delete_key_confirm"), IsAdminFilter() ) -async def process_callback_confirm_delete( +async def handle_delete_key_confirm( callback_query: types.CallbackQuery, callback_data: AdminUserEditorCallback, session: Any @@ -459,7 +459,7 @@ async def process_callback_confirm_delete( AdminUserEditorCallback.filter(F.action == "users_delete_user"), IsAdminFilter() ) -async def confirm_delete_user( +async def handle_delete_user( callback_query: types.CallbackQuery, callback_data: AdminUserEditorCallback ): @@ -474,7 +474,7 @@ async def confirm_delete_user( AdminUserEditorCallback.filter(F.action == "users_delete_user_confirm"), IsAdminFilter() ) -async def delete_user( +async def handle_delete_user_confirm( callback_query: types.CallbackQuery, callback_data: AdminUserEditorCallback, session: Any @@ -512,7 +512,7 @@ async def delete_user( AdminUserEditorCallback.filter(F.action == "users_editor"), IsAdminFilter() ) -async def handle_users_editor( +async def handle_editor( callback_query: types.CallbackQuery, callback_data: AdminUserEditorCallback, state: FSMContext,