From c9afe25c5200a757368a8b5443fc06492a16a6ae Mon Sep 17 00:00:00 2001 From: Zakhar Izmaylov Date: Fri, 31 Jan 2025 00:08:31 +0300 Subject: [PATCH] Remove check_online_users function and minor import reorganization - Removed unused check_online_users function from notifications handler - Reorganized imports in notifications.py and utils.py - Fixed TimeoutError import in subscriptions.py --- handlers/keys/subscriptions.py | 2 +- handlers/notifications.py | 23 +++-------------------- handlers/utils.py | 2 +- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/handlers/keys/subscriptions.py b/handlers/keys/subscriptions.py index 6203252b..ca2bea1a 100644 --- a/handlers/keys/subscriptions.py +++ b/handlers/keys/subscriptions.py @@ -36,7 +36,7 @@ async def fetch_url_content(url, tg_id): else: logger.error(f"Не удалось получить {url} для tg_id: {tg_id}, статус: {response.status}") return [] - except asyncio.TimeoutError: + except TimeoutError: logger.error(f"Таймаут при получении {url} для tg_id: {tg_id}") return [] except Exception as e: diff --git a/handlers/notifications.py b/handlers/notifications.py index 0a984556..b051e32a 100644 --- a/handlers/notifications.py +++ b/handlers/notifications.py @@ -10,7 +10,6 @@ from aiogram.exceptions import TelegramForbiddenError from aiogram.types import BufferedInputFile from aiogram.utils.keyboard import InlineKeyboardBuilder from py3xui import AsyncApi -from .utils import format_time_until_deletion from config import ( ADMIN_PASSWORD, @@ -18,12 +17,12 @@ from config import ( AUTO_DELETE_EXPIRED_KEYS, AUTO_RENEW_KEYS, DATABASE_URL, + DELETE_KEYS_DELAY, DEV_MODE, EXPIRED_KEYS_CHECK_INTERVAL, RENEWAL_PLANS, TOTAL_GB, TRIAL_TIME, - DELETE_KEYS_DELAY, ) from database import ( add_notification, @@ -39,6 +38,8 @@ from handlers.keys.key_utils import delete_key_from_cluster, renew_key_in_cluste from handlers.texts import KEY_EXPIRY_10H, KEY_EXPIRY_24H, KEY_RENEWED from logger import logger +from .utils import format_time_until_deletion + router = Router() @@ -74,8 +75,6 @@ async def notify_expiring_keys(bot: Bot): await notify_inactive_trial_users(bot, conn) await asyncio.sleep(0.5) - await check_online_users() - await asyncio.sleep(0.5) await notify_10h_keys(bot, conn, current_time, threshold_time_10h) await asyncio.sleep(0.5) await notify_24h_keys(bot, conn, current_time, threshold_time_24h) @@ -537,19 +536,3 @@ async def process_key(record, bot, conn): except Exception as e: logger.error(f"Ошибка при обработке ключа для клиента {tg_id}: {e}") - - -async def check_online_users(): - servers = await get_servers() - - for _cluster_id, cluster in servers.items(): - for server_id, server in enumerate(cluster): - xui = AsyncApi(server["api_url"], username=ADMIN_USERNAME, password=ADMIN_PASSWORD) - await xui.login() - try: - online_users = len(await xui.client.online()) - logger.info( - f"Сервер '{server['server_name']}' доступен, текущее количество активных пользователей: {online_users}." - ) - except Exception as e: - logger.error(f"Не удалось проверить пользователей на сервере {server_id}: {e}") diff --git a/handlers/utils.py b/handlers/utils.py index e52a17c3..8b4c71a7 100644 --- a/handlers/utils.py +++ b/handlers/utils.py @@ -3,6 +3,7 @@ import random import re import secrets import string +from datetime import datetime, timedelta import aiohttp import asyncpg @@ -11,7 +12,6 @@ from bot import bot from config import DATABASE_URL from database import get_all_keys, get_servers from logger import logger -from datetime import datetime, timedelta async def get_usd_rate():