Add promo management action to admin panel and remove panel statistics retrieval

- Introduced a new action for managing promo codes within the admin panel, enhancing admin capabilities.
- Removed the panel statistics retrieval code from the statistics handler to streamline functionality and reduce complexity.
- Updated localization files to reflect changes related to promo management.
This commit is contained in:
machka-pasla
2025-08-03 21:27:46 +03:00
parent a5b408d204
commit ebca408227
2 changed files with 4 additions and 57 deletions
+4
View File
@@ -105,6 +105,10 @@ async def admin_panel_actions_callback_handler(
elif action == "view_logs_menu":
await admin_logs_handlers.display_logs_menu(callback, i18n_data,
settings, session)
elif action == "promo_management":
from . import promo_codes as admin_promo_handlers
await admin_promo_handlers.promo_management_handler(
callback, i18n_data, settings, session)
elif action == "sync_panel":
await admin_sync_handlers.sync_command_handler(
-57
View File
@@ -208,63 +208,6 @@ async def show_statistics_handler(callback: types.CallbackQuery,
else:
stats_text_parts.append(f"\n{_('admin_sync_status_never_run')}")
# Panel Statistics
stats_text_parts.append(f"\n<b>🖥 {_('admin_panel_stats_header', default='Статистика панели')}</b>")
try:
async with PanelApiService(settings) as panel_service:
# Get panel system statistics
logging.info("Fetching panel statistics...")
panel_stats = await panel_service.get_panel_statistics()
nodes_stats = await panel_service.get_nodes_statistics()
online_count = await panel_service.get_online_users_count()
users_activity = await panel_service.get_users_activity_stats()
logging.info(f"Panel stats response: panel_stats={panel_stats}, nodes_stats={nodes_stats}, online_count={online_count}, users_activity={users_activity}")
# Online users
if online_count is not None:
stats_text_parts.append(f"🟢 Онлайн сейчас: <b>{online_count}</b>")
else:
stats_text_parts.append(f"🟢 Онлайн сейчас: <b>N/A</b>")
# Users activity
if users_activity:
today_connected = users_activity.get('today_connected', 'N/A')
week_connected = users_activity.get('week_connected', 'N/A')
never_connected = users_activity.get('never_connected', 'N/A')
stats_text_parts.append(f"📅 Подключались сегодня: <b>{today_connected}</b>")
stats_text_parts.append(f"📅 Подключались за неделю: <b>{week_connected}</b>")
stats_text_parts.append(f"❌ Никогда не подключались: <b>{never_connected}</b>")
else:
stats_text_parts.append(f"📅 Активность пользователей: <b>N/A</b>")
# Nodes statistics
if nodes_stats:
active_nodes = len([node for node in nodes_stats if node.get('status') == 'active'])
total_nodes = len(nodes_stats)
stats_text_parts.append(f"🔗 Активных нод: <b>{active_nodes}/{total_nodes}</b>")
else:
stats_text_parts.append(f"🔗 Ноды: <b>N/A</b>")
# System statistics
if panel_stats:
system_info = panel_stats.get('system', {})
if system_info:
memory_usage = system_info.get('memory_usage_percent', 'N/A')
cpu_usage = system_info.get('cpu_usage_percent', 'N/A')
stats_text_parts.append(f"💾 Использование RAM: <b>{memory_usage}%</b>")
stats_text_parts.append(f"🔄 Загрузка CPU: <b>{cpu_usage}%</b>")
else:
stats_text_parts.append(f"💾 Системная информация: <b>N/A</b>")
else:
stats_text_parts.append(f"💾 Системная статистика: <b>N/A</b>")
except Exception as e:
logging.error(f"Failed to fetch panel statistics: {e}", exc_info=True)
stats_text_parts.append("❌ Ошибка получения данных с панели")
stats_text_parts.append(f"⚠️ Детали: {str(e)}")
final_text = "\n".join(stats_text_parts)
try: