From 33e0d58e4d7f7048340367acdc76b4f802c3ae01 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 25 Sep 2025 18:03:48 +0300 Subject: [PATCH] Revert "Improve admin bot configuration menu grouping and labels" --- app/handlers/admin/bot_configuration.py | 117 ++++-------------------- 1 file changed, 17 insertions(+), 100 deletions(-) diff --git a/app/handlers/admin/bot_configuration.py b/app/handlers/admin/bot_configuration.py index 2d227e03..76120f61 100644 --- a/app/handlers/admin/bot_configuration.py +++ b/app/handlers/admin/bot_configuration.py @@ -1,5 +1,5 @@ import math -from typing import List, Sequence, Tuple, TypeVar +from typing import Tuple from aiogram import Dispatcher, F, types from aiogram.fsm.context import FSMContext @@ -7,10 +7,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from app.database.models import User from app.localization.texts import get_texts -from app.services.system_settings_service import ( - SettingDefinition, - bot_configuration_service, -) +from app.services.system_settings_service import bot_configuration_service from app.states import BotConfigStates from app.utils.decorators import admin_required, error_handler @@ -19,73 +16,6 @@ CATEGORY_PAGE_SIZE = 10 SETTINGS_PAGE_SIZE = 8 -_CATEGORY_ICONS: dict[str, str] = { - "PAYMENT": "💳", - "YOOKASSA": "🇷🇺", - "CRYPTOBOT": "🪙", - "MULENPAY": "💸", - "PAL24": "🏦", - "TELEGRAM": "⭐", - "REFERRAL": "🤝", - "PRICE": "💰", - "TRAFFIC": "📡", - "TRIAL": "🧪", - "DEFAULT": "🧷", - "REMNAWAVE": "🌊", - "ADMIN": "🛡️", - "SUPPORT": "🆘", - "CHANNEL": "📣", - "AUTOPAY": "🔁", - "MONITORING": "📈", - "SERVER": "🖥️", - "MAINTENANCE": "🛠️", - "WEBHOOK": "🔗", - "BACKUP": "🗄️", - "VERSION": "🧾", - "LOG": "📄", - "DEBUG": "🐞", - "DATABASE": "🗃️", - "POSTGRES": "🐘", - "SQLITE": "💾", - "REDIS": "🧠", - "CONNECT": "🔌", - "TRIBUTE": "🎁", - "HAPP": "📲", -} - -_SETTING_TYPE_ICONS: dict[type, str] = { - bool: "🔘", - int: "🔢", - float: "🔢", - str: "📝", -} - -_DEFAULT_CATEGORY_ICON = "🗂️" -_DEFAULT_SETTING_ICON = "⚙️" - -_ChunkItem = TypeVar("_ChunkItem") - - -def _chunk(items: Sequence[_ChunkItem], size: int) -> List[List[_ChunkItem]]: - if size <= 0: - raise ValueError("size must be greater than zero") - return [list(items[index : index + size]) for index in range(0, len(items), size)] - - -def _format_category_button(label: str, count: int, category_key: str) -> str: - icon = _CATEGORY_ICONS.get(category_key.upper(), _DEFAULT_CATEGORY_ICON) - return f"{icon} {label} ({count})" - - -def _format_setting_button( - definition: SettingDefinition, value_preview: str -) -> str: - icon = _SETTING_TYPE_ICONS.get(definition.python_type, _DEFAULT_SETTING_ICON) - if value_preview == "—": - value_preview = "по умолчанию" - return f"{icon} {definition.display_name} · {value_preview}" - - def _parse_category_payload(payload: str) -> Tuple[str, int]: parts = payload.split(":") if len(parts) == 3: @@ -110,17 +40,14 @@ def _build_categories_keyboard(language: str, page: int = 1) -> types.InlineKeyb sliced = categories[start:end] rows: list[list[types.InlineKeyboardButton]] = [] - for chunk in _chunk(sliced, 2): - row: list[types.InlineKeyboardButton] = [] - for category_key, label, count in chunk: - button_text = _format_category_button(label, count, category_key) - row.append( - types.InlineKeyboardButton( - text=button_text, - callback_data=f"botcfg_cat:{category_key}:1", - ) + for category_key, label, count in sliced: + button_text = f"{label} ({count})" + rows.append([ + types.InlineKeyboardButton( + text=button_text, + callback_data=f"botcfg_cat:{category_key}:1", ) - rows.append(row) + ]) if total_pages > 1: nav_row: list[types.InlineKeyboardButton] = [] @@ -165,20 +92,15 @@ def _build_settings_keyboard( rows: list[list[types.InlineKeyboardButton]] = [] - for chunk in _chunk(sliced, 2): - row: list[types.InlineKeyboardButton] = [] - for definition in chunk: - value_preview = bot_configuration_service.format_value_for_list( - definition.key + for definition in sliced: + value_preview = bot_configuration_service.format_value_for_list(definition.key) + button_text = f"{definition.key} = {value_preview}" + rows.append([ + types.InlineKeyboardButton( + text=button_text, + callback_data=f"botcfg_setting:{definition.key}", ) - button_text = _format_setting_button(definition, value_preview) - row.append( - types.InlineKeyboardButton( - text=button_text, - callback_data=f"botcfg_setting:{definition.key}", - ) - ) - rows.append(row) + ]) if total_pages > 1: nav_row: list[types.InlineKeyboardButton] = [] @@ -251,15 +173,12 @@ def _build_setting_keyboard(key: str) -> types.InlineKeyboardMarkup: def _render_setting_text(key: str) -> str: - definition = bot_configuration_service.get_definition(key) summary = bot_configuration_service.get_setting_summary(key) lines = [ "🧩 Настройка", - f"Название: {definition.display_name}", f"Ключ: {summary['key']}", f"Тип: {summary['type']}", - f"Категория: {definition.category_label}", f"Текущее значение: {summary['current']}", f"Значение по умолчанию: {summary['original']}", f"Переопределено в БД: {'✅ Да' if summary['has_override'] else '❌ Нет'}", @@ -353,12 +272,10 @@ async def start_edit_setting( definition = bot_configuration_service.get_definition(key) summary = bot_configuration_service.get_setting_summary(key) - display_name = definition.display_name texts = get_texts(db_user.language) instructions = [ "✏️ Редактирование настройки", - f"Название: {display_name}", f"Ключ: {summary['key']}", f"Тип: {summary['type']}", f"Текущее значение: {summary['current']}",