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
This commit is contained in:
Zakhar Izmaylov
2025-01-31 00:08:31 +03:00
parent 838bb0762c
commit c9afe25c52
3 changed files with 5 additions and 22 deletions
+1 -1
View File
@@ -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:
+3 -20
View File
@@ -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}")
+1 -1
View File
@@ -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():