diff --git a/database/__init__.py b/database/__init__.py index ae0cdc6..766c4da 100644 --- a/database/__init__.py +++ b/database/__init__.py @@ -11,19 +11,9 @@ from .async_db import AsyncBotDB from .base import DatabaseConnection -from .models import ( - Admin, - AudioListenRecord, - AudioMessage, - AudioModerate, - BlacklistUser, - MessageContentLink, - Migration, - PostContent, - TelegramPost, - User, - UserMessage, -) +from .models import (Admin, AudioListenRecord, AudioMessage, AudioModerate, + BlacklistUser, MessageContentLink, Migration, PostContent, + TelegramPost, User, UserMessage) from .repository_factory import RepositoryFactory # Для обратной совместимости экспортируем старый интерфейс diff --git a/database/async_db.py b/database/async_db.py index 086204d..83057bc 100644 --- a/database/async_db.py +++ b/database/async_db.py @@ -3,16 +3,9 @@ from typing import Any, Dict, List, Optional, Tuple import aiosqlite -from database.models import ( - Admin, - AudioMessage, - BlacklistHistoryRecord, - BlacklistUser, - PostContent, - TelegramPost, - User, - UserMessage, -) +from database.models import (Admin, AudioMessage, BlacklistHistoryRecord, + BlacklistUser, PostContent, TelegramPost, User, + UserMessage) from database.repository_factory import RepositoryFactory diff --git a/database/repository_factory.py b/database/repository_factory.py index 18c3aae..5d4ce65 100644 --- a/database/repository_factory.py +++ b/database/repository_factory.py @@ -2,9 +2,8 @@ from typing import Optional from database.repositories.admin_repository import AdminRepository from database.repositories.audio_repository import AudioRepository -from database.repositories.blacklist_history_repository import ( - BlacklistHistoryRepository, -) +from database.repositories.blacklist_history_repository import \ + BlacklistHistoryRepository from database.repositories.blacklist_repository import BlacklistRepository from database.repositories.message_repository import MessageRepository from database.repositories.post_repository import PostRepository diff --git a/helper_bot/handlers/admin/__init__.py b/helper_bot/handlers/admin/__init__.py index 4b9d6f2..dbcf322 100644 --- a/helper_bot/handlers/admin/__init__.py +++ b/helper_bot/handlers/admin/__init__.py @@ -1,20 +1,10 @@ from .admin_handlers import admin_router from .dependencies import AdminAccessMiddleware, BotDB, Settings -from .exceptions import ( - AdminAccessDeniedError, - AdminError, - InvalidInputError, - UserAlreadyBannedError, - UserNotFoundError, -) +from .exceptions import (AdminAccessDeniedError, AdminError, InvalidInputError, + UserAlreadyBannedError, UserNotFoundError) from .services import AdminService, BannedUser, User -from .utils import ( - escape_html, - format_ban_confirmation, - format_user_info, - handle_admin_error, - return_to_admin_menu, -) +from .utils import (escape_html, format_ban_confirmation, format_user_info, + handle_admin_error, return_to_admin_menu) __all__ = [ "admin_router", diff --git a/helper_bot/handlers/admin/admin_handlers.py b/helper_bot/handlers/admin/admin_handlers.py index e711abb..1bbafb6 100644 --- a/helper_bot/handlers/admin/admin_handlers.py +++ b/helper_bot/handlers/admin/admin_handlers.py @@ -4,26 +4,19 @@ from aiogram.fsm.context import FSMContext from helper_bot.filters.main import ChatTypeFilter from helper_bot.handlers.admin.dependencies import AdminAccessMiddleware -from helper_bot.handlers.admin.exceptions import ( - InvalidInputError, - UserAlreadyBannedError, -) +from helper_bot.handlers.admin.exceptions import (InvalidInputError, + UserAlreadyBannedError) from helper_bot.handlers.admin.services import AdminService -from helper_bot.handlers.admin.utils import ( - escape_html, - format_ban_confirmation, - format_user_info, - handle_admin_error, - return_to_admin_menu, -) -from helper_bot.keyboards.keyboards import ( - create_keyboard_for_approve_ban, - create_keyboard_for_ban_days, - create_keyboard_for_ban_reason, - create_keyboard_with_pagination, - get_reply_keyboard_admin, -) - +from helper_bot.handlers.admin.utils import (escape_html, + format_ban_confirmation, + format_user_info, + handle_admin_error, + return_to_admin_menu) +from helper_bot.keyboards.keyboards import (create_keyboard_for_approve_ban, + create_keyboard_for_ban_days, + create_keyboard_for_ban_reason, + create_keyboard_with_pagination, + get_reply_keyboard_admin) # Local imports - metrics from helper_bot.utils.metrics import db_query_time, track_errors, track_time from logs.custom_logger import logger diff --git a/helper_bot/handlers/admin/rate_limit_handlers.py b/helper_bot/handlers/admin/rate_limit_handlers.py index 2837121..1358a12 100644 --- a/helper_bot/handlers/admin/rate_limit_handlers.py +++ b/helper_bot/handlers/admin/rate_limit_handlers.py @@ -8,18 +8,14 @@ from aiogram.fsm.context import FSMContext from aiogram.types import FSInputFile from helper_bot.filters.main import ChatTypeFilter -from helper_bot.middlewares.dependencies_middleware import DependenciesMiddleware - +from helper_bot.middlewares.dependencies_middleware import \ + DependenciesMiddleware # Local imports - metrics from helper_bot.utils.metrics import track_errors, track_time from helper_bot.utils.rate_limit_metrics import ( - get_rate_limit_metrics_summary, - update_rate_limit_gauges, -) -from helper_bot.utils.rate_limit_monitor import ( - get_rate_limit_summary, - rate_limit_monitor, -) + get_rate_limit_metrics_summary, update_rate_limit_gauges) +from helper_bot.utils.rate_limit_monitor import (get_rate_limit_summary, + rate_limit_monitor) from logs.custom_logger import logger diff --git a/helper_bot/handlers/admin/services.py b/helper_bot/handlers/admin/services.py index 6eb625e..e8b760f 100644 --- a/helper_bot/handlers/admin/services.py +++ b/helper_bot/handlers/admin/services.py @@ -1,16 +1,11 @@ from datetime import datetime from typing import List, Optional -from helper_bot.handlers.admin.exceptions import ( - InvalidInputError, - UserAlreadyBannedError, -) -from helper_bot.utils.helper_func import ( - add_days_to_date, - get_banned_users_buttons, - get_banned_users_list, -) - +from helper_bot.handlers.admin.exceptions import (InvalidInputError, + UserAlreadyBannedError) +from helper_bot.utils.helper_func import (add_days_to_date, + get_banned_users_buttons, + get_banned_users_list) # Local imports - metrics from helper_bot.utils.metrics import track_errors, track_time from logs.custom_logger import logger diff --git a/helper_bot/handlers/callback/__init__.py b/helper_bot/handlers/callback/__init__.py index ccb7ddd..0feae62 100644 --- a/helper_bot/handlers/callback/__init__.py +++ b/helper_bot/handlers/callback/__init__.py @@ -1,19 +1,8 @@ from .callback_handlers import callback_router -from .constants import ( - CALLBACK_BAN, - CALLBACK_DECLINE, - CALLBACK_PAGE, - CALLBACK_PUBLISH, - CALLBACK_RETURN, - CALLBACK_UNLOCK, -) -from .exceptions import ( - BanError, - PostNotFoundError, - PublishError, - UserBlockedBotError, - UserNotFoundError, -) +from .constants import (CALLBACK_BAN, CALLBACK_DECLINE, CALLBACK_PAGE, + CALLBACK_PUBLISH, CALLBACK_RETURN, CALLBACK_UNLOCK) +from .exceptions import (BanError, PostNotFoundError, PublishError, + UserBlockedBotError, UserNotFoundError) from .services import BanService, PostPublishService __all__ = [ diff --git a/helper_bot/handlers/callback/callback_handlers.py b/helper_bot/handlers/callback/callback_handlers.py index d156184..ab8551a 100644 --- a/helper_bot/handlers/callback/callback_handlers.py +++ b/helper_bot/handlers/callback/callback_handlers.py @@ -11,45 +11,25 @@ from aiogram.types import CallbackQuery from helper_bot.handlers.admin.utils import format_user_info from helper_bot.handlers.voice.constants import CALLBACK_DELETE, CALLBACK_SAVE from helper_bot.handlers.voice.services import AudioFileService -from helper_bot.keyboards.keyboards import ( - create_keyboard_for_ban_reason, - create_keyboard_with_pagination, - get_reply_keyboard_admin, -) +from helper_bot.keyboards.keyboards import (create_keyboard_for_ban_reason, + create_keyboard_with_pagination, + get_reply_keyboard_admin) from helper_bot.utils.base_dependency_factory import get_global_instance -from helper_bot.utils.helper_func import get_banned_users_buttons, get_banned_users_list - +from helper_bot.utils.helper_func import (get_banned_users_buttons, + get_banned_users_list) # Local imports - metrics -from helper_bot.utils.metrics import ( - db_query_time, - track_errors, - track_file_operations, - track_time, -) +from helper_bot.utils.metrics import (db_query_time, track_errors, + track_file_operations, track_time) from logs.custom_logger import logger -from .constants import ( - CALLBACK_BAN, - CALLBACK_DECLINE, - CALLBACK_PAGE, - CALLBACK_PUBLISH, - CALLBACK_RETURN, - CALLBACK_UNLOCK, - ERROR_BOT_BLOCKED, - MESSAGE_DECLINED, - MESSAGE_ERROR, - MESSAGE_PUBLISHED, - MESSAGE_USER_BANNED, - MESSAGE_USER_UNLOCKED, -) +from .constants import (CALLBACK_BAN, CALLBACK_DECLINE, CALLBACK_PAGE, + CALLBACK_PUBLISH, CALLBACK_RETURN, CALLBACK_UNLOCK, + ERROR_BOT_BLOCKED, MESSAGE_DECLINED, MESSAGE_ERROR, + MESSAGE_PUBLISHED, MESSAGE_USER_BANNED, + MESSAGE_USER_UNLOCKED) from .dependency_factory import get_ban_service, get_post_publish_service -from .exceptions import ( - BanError, - PostNotFoundError, - PublishError, - UserBlockedBotError, - UserNotFoundError, -) +from .exceptions import (BanError, PostNotFoundError, PublishError, + UserBlockedBotError, UserNotFoundError) callback_router = Router() diff --git a/helper_bot/handlers/callback/services.py b/helper_bot/handlers/callback/services.py index 140ba90..b4c2253 100644 --- a/helper_bot/handlers/callback/services.py +++ b/helper_bot/handlers/callback/services.py @@ -6,47 +6,27 @@ from aiogram import Bot, types from aiogram.types import CallbackQuery from helper_bot.keyboards.keyboards import create_keyboard_for_ban_reason -from helper_bot.utils.helper_func import ( - delete_user_blacklist, - get_text_message, - send_audio_message, - send_media_group_to_channel, - send_photo_message, - send_text_message, - send_video_message, - send_video_note_message, - send_voice_message, -) - +from helper_bot.utils.helper_func import (delete_user_blacklist, + get_text_message, send_audio_message, + send_media_group_to_channel, + send_photo_message, + send_text_message, + send_video_message, + send_video_note_message, + send_voice_message) # Local imports - metrics -from helper_bot.utils.metrics import ( - db_query_time, - track_errors, - track_media_processing, - track_time, -) +from helper_bot.utils.metrics import (db_query_time, track_errors, + track_media_processing, track_time) from logs.custom_logger import logger -from .constants import ( - CONTENT_TYPE_AUDIO, - CONTENT_TYPE_MEDIA_GROUP, - CONTENT_TYPE_PHOTO, - CONTENT_TYPE_TEXT, - CONTENT_TYPE_VIDEO, - CONTENT_TYPE_VIDEO_NOTE, - CONTENT_TYPE_VOICE, - ERROR_BOT_BLOCKED, - MESSAGE_POST_DECLINED, - MESSAGE_POST_PUBLISHED, - MESSAGE_USER_BANNED_SPAM, -) -from .exceptions import ( - BanError, - PostNotFoundError, - PublishError, - UserBlockedBotError, - UserNotFoundError, -) +from .constants import (CONTENT_TYPE_AUDIO, CONTENT_TYPE_MEDIA_GROUP, + CONTENT_TYPE_PHOTO, CONTENT_TYPE_TEXT, + CONTENT_TYPE_VIDEO, CONTENT_TYPE_VIDEO_NOTE, + CONTENT_TYPE_VOICE, ERROR_BOT_BLOCKED, + MESSAGE_POST_DECLINED, MESSAGE_POST_PUBLISHED, + MESSAGE_USER_BANNED_SPAM) +from .exceptions import (BanError, PostNotFoundError, PublishError, + UserBlockedBotError, UserNotFoundError) class PostPublishService: diff --git a/helper_bot/handlers/group/__init__.py b/helper_bot/handlers/group/__init__.py index a060f32..e838c10 100644 --- a/helper_bot/handlers/group/__init__.py +++ b/helper_bot/handlers/group/__init__.py @@ -6,7 +6,6 @@ from .constants import ERROR_MESSAGES, FSM_STATES from .decorators import error_handler from .exceptions import NoReplyToMessageError, UserNotFoundError from .group_handlers import GroupHandlers, create_group_handlers, group_router - # Local imports - services from .services import AdminReplyService, DatabaseProtocol diff --git a/helper_bot/handlers/group/decorators.py b/helper_bot/handlers/group/decorators.py index b1511a0..0d298ca 100644 --- a/helper_bot/handlers/group/decorators.py +++ b/helper_bot/handlers/group/decorators.py @@ -25,9 +25,8 @@ def error_handler(func: Callable[..., Any]) -> Callable[..., Any]: (arg for arg in args if isinstance(arg, types.Message)), None ) if message and hasattr(message, "bot"): - from helper_bot.utils.base_dependency_factory import ( - get_global_instance, - ) + from helper_bot.utils.base_dependency_factory import \ + get_global_instance bdf = get_global_instance() important_logs = bdf.settings["Telegram"]["important_logs"] diff --git a/helper_bot/handlers/group/group_handlers.py b/helper_bot/handlers/group/group_handlers.py index c21fddc..d3f0709 100644 --- a/helper_bot/handlers/group/group_handlers.py +++ b/helper_bot/handlers/group/group_handlers.py @@ -7,10 +7,8 @@ from aiogram.fsm.context import FSMContext # Local imports - filters from database.async_db import AsyncBotDB from helper_bot.filters.main import ChatTypeFilter - # Local imports - metrics from helper_bot.utils.metrics import metrics, track_errors, track_time - # Local imports - utilities from logs.custom_logger import logger diff --git a/helper_bot/handlers/group/services.py b/helper_bot/handlers/group/services.py index 934887b..9a0ee77 100644 --- a/helper_bot/handlers/group/services.py +++ b/helper_bot/handlers/group/services.py @@ -8,7 +8,6 @@ from aiogram import types # Local imports from helper_bot.utils.helper_func import send_text_message - # Local imports - metrics from helper_bot.utils.metrics import db_query_time, track_errors, track_time from logs.custom_logger import logger diff --git a/helper_bot/handlers/private/__init__.py b/helper_bot/handlers/private/__init__.py index 0a8be50..e5c549b 100644 --- a/helper_bot/handlers/private/__init__.py +++ b/helper_bot/handlers/private/__init__.py @@ -4,8 +4,8 @@ # Local imports - constants and utilities from .constants import BUTTON_TEXTS, ERROR_MESSAGES, FSM_STATES from .decorators import error_handler -from .private_handlers import PrivateHandlers, create_private_handlers, private_router - +from .private_handlers import (PrivateHandlers, create_private_handlers, + private_router) # Local imports - services from .services import BotSettings, PostService, StickerService, UserService diff --git a/helper_bot/handlers/private/decorators.py b/helper_bot/handlers/private/decorators.py index 1adabc0..2546567 100644 --- a/helper_bot/handlers/private/decorators.py +++ b/helper_bot/handlers/private/decorators.py @@ -25,9 +25,8 @@ def error_handler(func: Callable[..., Any]) -> Callable[..., Any]: (arg for arg in args if isinstance(arg, types.Message)), None ) if message and hasattr(message, "bot"): - from helper_bot.utils.base_dependency_factory import ( - get_global_instance, - ) + from helper_bot.utils.base_dependency_factory import \ + get_global_instance bdf = get_global_instance() important_logs = bdf.settings["Telegram"]["important_logs"] diff --git a/helper_bot/handlers/private/private_handlers.py b/helper_bot/handlers/private/private_handlers.py index e69d681..72d7c71 100644 --- a/helper_bot/handlers/private/private_handlers.py +++ b/helper_bot/handlers/private/private_handlers.py @@ -12,19 +12,15 @@ from aiogram.fsm.context import FSMContext # Local imports - filters and middlewares from database.async_db import AsyncBotDB from helper_bot.filters.main import ChatTypeFilter - # Local imports - utilities -from helper_bot.keyboards import get_reply_keyboard, get_reply_keyboard_for_post +from helper_bot.keyboards import (get_reply_keyboard, + get_reply_keyboard_for_post) from helper_bot.keyboards.keyboards import get_reply_keyboard_leave_chat from helper_bot.middlewares.album_middleware import AlbumMiddleware from helper_bot.middlewares.blacklist_middleware import BlacklistMiddleware from helper_bot.utils import messages -from helper_bot.utils.helper_func import ( - check_user_emoji, - get_first_name, - update_user_info, -) - +from helper_bot.utils.helper_func import (check_user_emoji, get_first_name, + update_user_info) # Local imports - metrics from helper_bot.utils.metrics import db_query_time, track_errors, track_time diff --git a/helper_bot/handlers/private/services.py b/helper_bot/handlers/private/services.py index cda68b2..42be11e 100644 --- a/helper_bot/handlers/private/services.py +++ b/helper_bot/handlers/private/services.py @@ -15,32 +15,17 @@ from aiogram.types import FSInputFile from database.models import TelegramPost, User from helper_bot.keyboards import get_reply_keyboard_for_post - # Local imports - utilities from helper_bot.utils.helper_func import ( - add_in_db_media, - check_username_and_full_name, - determine_anonymity, - get_first_name, - get_text_message, - prepare_media_group_from_middlewares, - send_audio_message, - send_media_group_message_to_private_chat, - send_photo_message, - send_text_message, - send_video_message, - send_video_note_message, - send_voice_message, -) - + add_in_db_media, check_username_and_full_name, determine_anonymity, + get_first_name, get_text_message, prepare_media_group_from_middlewares, + send_audio_message, send_media_group_message_to_private_chat, + send_photo_message, send_text_message, send_video_message, + send_video_note_message, send_voice_message) # Local imports - metrics -from helper_bot.utils.metrics import ( - db_query_time, - track_errors, - track_file_operations, - track_media_processing, - track_time, -) +from helper_bot.utils.metrics import (db_query_time, track_errors, + track_file_operations, + track_media_processing, track_time) from logs.custom_logger import logger diff --git a/helper_bot/handlers/voice/services.py b/helper_bot/handlers/voice/services.py index 36808ee..e1d8140 100644 --- a/helper_bot/handlers/voice/services.py +++ b/helper_bot/handlers/voice/services.py @@ -8,23 +8,16 @@ from typing import List, Optional, Tuple from aiogram.types import FSInputFile -from helper_bot.handlers.voice.constants import ( - MESSAGE_DELAY_1, - MESSAGE_DELAY_2, - MESSAGE_DELAY_3, - MESSAGE_DELAY_4, - STICK_DIR, - STICK_PATTERN, - STICKER_DELAY, - VOICE_USERS_DIR, -) -from helper_bot.handlers.voice.exceptions import ( - AudioProcessingError, - DatabaseError, - FileOperationError, - VoiceMessageError, -) - +from helper_bot.handlers.voice.constants import (MESSAGE_DELAY_1, + MESSAGE_DELAY_2, + MESSAGE_DELAY_3, + MESSAGE_DELAY_4, STICK_DIR, + STICK_PATTERN, STICKER_DELAY, + VOICE_USERS_DIR) +from helper_bot.handlers.voice.exceptions import (AudioProcessingError, + DatabaseError, + FileOperationError, + VoiceMessageError) # Local imports - metrics from helper_bot.utils.metrics import db_query_time, track_errors, track_time from logs.custom_logger import logger diff --git a/helper_bot/handlers/voice/voice_handler.py b/helper_bot/handlers/voice/voice_handler.py index 3ea223e..fc24b2d 100644 --- a/helper_bot/handlers/voice/voice_handler.py +++ b/helper_bot/handlers/voice/voice_handler.py @@ -11,33 +11,21 @@ from helper_bot.filters.main import ChatTypeFilter from helper_bot.handlers.private.constants import BUTTON_TEXTS, FSM_STATES from helper_bot.handlers.voice.constants import * from helper_bot.handlers.voice.services import VoiceBotService -from helper_bot.handlers.voice.utils import ( - get_last_message_text, - get_user_emoji_safe, - validate_voice_message, -) +from helper_bot.handlers.voice.utils import (get_last_message_text, + get_user_emoji_safe, + validate_voice_message) from helper_bot.keyboards import get_reply_keyboard -from helper_bot.keyboards.keyboards import ( - get_main_keyboard, - get_reply_keyboard_for_voice, -) +from helper_bot.keyboards.keyboards import (get_main_keyboard, + get_reply_keyboard_for_voice) from helper_bot.middlewares.blacklist_middleware import BlacklistMiddleware -from helper_bot.middlewares.dependencies_middleware import DependenciesMiddleware +from helper_bot.middlewares.dependencies_middleware import \ + DependenciesMiddleware from helper_bot.utils import messages -from helper_bot.utils.helper_func import ( - check_user_emoji, - get_first_name, - send_voice_message, - update_user_info, -) - +from helper_bot.utils.helper_func import (check_user_emoji, get_first_name, + send_voice_message, update_user_info) # Local imports - metrics -from helper_bot.utils.metrics import ( - db_query_time, - track_errors, - track_file_operations, - track_time, -) +from helper_bot.utils.metrics import (db_query_time, track_errors, + track_file_operations, track_time) from logs.custom_logger import logger diff --git a/helper_bot/main.py b/helper_bot/main.py index 6066604..1b637a5 100644 --- a/helper_bot/main.py +++ b/helper_bot/main.py @@ -13,13 +13,13 @@ from helper_bot.handlers.group import group_router from helper_bot.handlers.private import private_router from helper_bot.handlers.voice import VoiceHandlers from helper_bot.middlewares.blacklist_middleware import BlacklistMiddleware -from helper_bot.middlewares.dependencies_middleware import DependenciesMiddleware -from helper_bot.middlewares.metrics_middleware import ( - ErrorMetricsMiddleware, - MetricsMiddleware, -) +from helper_bot.middlewares.dependencies_middleware import \ + DependenciesMiddleware +from helper_bot.middlewares.metrics_middleware import (ErrorMetricsMiddleware, + MetricsMiddleware) from helper_bot.middlewares.rate_limit_middleware import RateLimitMiddleware -from helper_bot.server_prometheus import start_metrics_server, stop_metrics_server +from helper_bot.server_prometheus import (start_metrics_server, + stop_metrics_server) async def start_bot_with_retry( diff --git a/helper_bot/middlewares/metrics_middleware.py b/helper_bot/middlewares/metrics_middleware.py index 2564b86..b5465a9 100644 --- a/helper_bot/middlewares/metrics_middleware.py +++ b/helper_bot/middlewares/metrics_middleware.py @@ -16,16 +16,16 @@ from ..utils.metrics import metrics # Import button command mapping try: - from ..handlers.admin.constants import ADMIN_BUTTON_COMMAND_MAPPING, ADMIN_COMMANDS + from ..handlers.admin.constants import (ADMIN_BUTTON_COMMAND_MAPPING, + ADMIN_COMMANDS) from ..handlers.callback.constants import CALLBACK_COMMAND_MAPPING from ..handlers.private.constants import BUTTON_COMMAND_MAPPING - from ..handlers.voice.constants import ( - BUTTON_COMMAND_MAPPING as VOICE_BUTTON_COMMAND_MAPPING, - ) - from ..handlers.voice.constants import ( - CALLBACK_COMMAND_MAPPING as VOICE_CALLBACK_COMMAND_MAPPING, - ) - from ..handlers.voice.constants import COMMAND_MAPPING as VOICE_COMMAND_MAPPING + from ..handlers.voice.constants import \ + BUTTON_COMMAND_MAPPING as VOICE_BUTTON_COMMAND_MAPPING + from ..handlers.voice.constants import \ + CALLBACK_COMMAND_MAPPING as VOICE_CALLBACK_COMMAND_MAPPING + from ..handlers.voice.constants import \ + COMMAND_MAPPING as VOICE_COMMAND_MAPPING except ImportError: # Fallback if constants not available BUTTON_COMMAND_MAPPING = {} diff --git a/helper_bot/middlewares/rate_limit_middleware.py b/helper_bot/middlewares/rate_limit_middleware.py index c50ef88..4e8be94 100644 --- a/helper_bot/middlewares/rate_limit_middleware.py +++ b/helper_bot/middlewares/rate_limit_middleware.py @@ -6,7 +6,8 @@ from typing import Any, Awaitable, Callable, Dict, Union from aiogram import BaseMiddleware from aiogram.exceptions import TelegramAPIError, TelegramRetryAfter -from aiogram.types import CallbackQuery, ChatMemberUpdated, InlineQuery, Message, Update +from aiogram.types import (CallbackQuery, ChatMemberUpdated, InlineQuery, + Message, Update) from helper_bot.utils.rate_limiter import telegram_rate_limiter from logs.custom_logger import logger diff --git a/helper_bot/utils/helper_func.py b/helper_bot/utils/helper_func.py index dac4040..4e5dc4c 100644 --- a/helper_bot/utils/helper_func.py +++ b/helper_bot/utils/helper_func.py @@ -17,29 +17,17 @@ except ImportError: _emoji_lib_available = False from aiogram import types -from aiogram.types import ( - FSInputFile, - InputMediaAudio, - InputMediaDocument, - InputMediaPhoto, - InputMediaVideo, -) +from aiogram.types import (FSInputFile, InputMediaAudio, InputMediaDocument, + InputMediaPhoto, InputMediaVideo) from database.models import TelegramPost -from helper_bot.utils.base_dependency_factory import ( - BaseDependencyFactory, - get_global_instance, -) +from helper_bot.utils.base_dependency_factory import (BaseDependencyFactory, + get_global_instance) from logs.custom_logger import logger # Local imports - metrics -from .metrics import ( - db_query_time, - track_errors, - track_file_operations, - track_media_processing, - track_time, -) +from .metrics import (db_query_time, track_errors, track_file_operations, + track_media_processing, track_time) bdf = get_global_instance() # TODO: поменять архитектуру и подключить правильный BotDB diff --git a/helper_bot/utils/metrics.py b/helper_bot/utils/metrics.py index b416b8c..18c2f42 100644 --- a/helper_bot/utils/metrics.py +++ b/helper_bot/utils/metrics.py @@ -10,13 +10,8 @@ from contextlib import asynccontextmanager from functools import wraps from typing import Any, Dict, Optional -from prometheus_client import ( - CONTENT_TYPE_LATEST, - Counter, - Gauge, - Histogram, - generate_latest, -) +from prometheus_client import (CONTENT_TYPE_LATEST, Counter, Gauge, Histogram, + generate_latest) from prometheus_client.core import CollectorRegistry # Метрики rate limiter теперь создаются в основном классе diff --git a/helper_bot/utils/rate_limiter.py b/helper_bot/utils/rate_limiter.py index 78d891f..f80c963 100644 --- a/helper_bot/utils/rate_limiter.py +++ b/helper_bot/utils/rate_limiter.py @@ -188,7 +188,8 @@ class TelegramRateLimiter: # Глобальный экземпляр rate limiter -from helper_bot.config.rate_limit_config import RateLimitSettings, get_rate_limit_config +from helper_bot.config.rate_limit_config import (RateLimitSettings, + get_rate_limit_config) def _create_rate_limit_config(settings: RateLimitSettings) -> RateLimitConfig: diff --git a/run_helper.py b/run_helper.py index 8715db1..98222fa 100644 --- a/run_helper.py +++ b/run_helper.py @@ -68,7 +68,8 @@ async def main(): # Останавливаем планировщик метрик try: - from helper_bot.utils.metrics_scheduler import stop_metrics_scheduler + from helper_bot.utils.metrics_scheduler import \ + stop_metrics_scheduler stop_metrics_scheduler() logger.info("Планировщик метрик остановлен") diff --git a/tests/test_audio_file_service.py b/tests/test_audio_file_service.py index 7d298ed..a4441f5 100644 --- a/tests/test_audio_file_service.py +++ b/tests/test_audio_file_service.py @@ -4,7 +4,8 @@ from unittest.mock import AsyncMock, MagicMock, Mock, mock_open, patch import pytest -from helper_bot.handlers.voice.exceptions import DatabaseError, FileOperationError +from helper_bot.handlers.voice.exceptions import (DatabaseError, + FileOperationError) from helper_bot.handlers.voice.services import AudioFileService diff --git a/tests/test_auto_unban_scheduler.py b/tests/test_auto_unban_scheduler.py index 7f64bef..df5a9dd 100644 --- a/tests/test_auto_unban_scheduler.py +++ b/tests/test_auto_unban_scheduler.py @@ -4,10 +4,8 @@ from unittest.mock import AsyncMock, Mock, patch import pytest -from helper_bot.utils.auto_unban_scheduler import ( - AutoUnbanScheduler, - get_auto_unban_scheduler, -) +from helper_bot.utils.auto_unban_scheduler import (AutoUnbanScheduler, + get_auto_unban_scheduler) class TestAutoUnbanScheduler: diff --git a/tests/test_blacklist_history_repository.py b/tests/test_blacklist_history_repository.py index 828a222..da43184 100644 --- a/tests/test_blacklist_history_repository.py +++ b/tests/test_blacklist_history_repository.py @@ -5,9 +5,8 @@ from unittest.mock import AsyncMock, Mock, patch import pytest from database.models import BlacklistHistoryRecord -from database.repositories.blacklist_history_repository import ( - BlacklistHistoryRepository, -) +from database.repositories.blacklist_history_repository import \ + BlacklistHistoryRepository class TestBlacklistHistoryRepository: diff --git a/tests/test_callback_handlers.py b/tests/test_callback_handlers.py index 2cf6125..8c59703 100644 --- a/tests/test_callback_handlers.py +++ b/tests/test_callback_handlers.py @@ -5,9 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch import pytest from helper_bot.handlers.callback.callback_handlers import ( - delete_voice_message, - save_voice_message, -) + delete_voice_message, save_voice_message) from helper_bot.handlers.voice.constants import CALLBACK_DELETE, CALLBACK_SAVE diff --git a/tests/test_improved_media_processing.py b/tests/test_improved_media_processing.py index 05d78e7..46caa80 100644 --- a/tests/test_improved_media_processing.py +++ b/tests/test_improved_media_processing.py @@ -10,11 +10,8 @@ import pytest from aiogram import types from helper_bot.utils.helper_func import ( - add_in_db_media, - add_in_db_media_mediagroup, - download_file, - send_media_group_message_to_private_chat, -) + add_in_db_media, add_in_db_media_mediagroup, download_file, + send_media_group_message_to_private_chat) class TestDownloadFile: diff --git a/tests/test_keyboards_and_filters.py b/tests/test_keyboards_and_filters.py index cb25041..0068702 100644 --- a/tests/test_keyboards_and_filters.py +++ b/tests/test_keyboards_and_filters.py @@ -1,22 +1,16 @@ from unittest.mock import AsyncMock, Mock, patch import pytest -from aiogram.types import ( - InlineKeyboardButton, - InlineKeyboardMarkup, - KeyboardButton, - ReplyKeyboardMarkup, -) +from aiogram.types import (InlineKeyboardButton, InlineKeyboardMarkup, + KeyboardButton, ReplyKeyboardMarkup) from database.async_db import AsyncBotDB from helper_bot.filters.main import ChatTypeFilter -from helper_bot.keyboards.keyboards import ( - create_keyboard_with_pagination, - get_reply_keyboard, - get_reply_keyboard_admin, - get_reply_keyboard_for_post, - get_reply_keyboard_leave_chat, -) +from helper_bot.keyboards.keyboards import (create_keyboard_with_pagination, + get_reply_keyboard, + get_reply_keyboard_admin, + get_reply_keyboard_for_post, + get_reply_keyboard_leave_chat) class TestKeyboards: diff --git a/tests/test_rate_limiter.py b/tests/test_rate_limiter.py index ed3e7bd..b6ea61f 100644 --- a/tests/test_rate_limiter.py +++ b/tests/test_rate_limiter.py @@ -8,20 +8,15 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest -from helper_bot.config.rate_limit_config import RateLimitSettings, get_rate_limit_config -from helper_bot.utils.rate_limit_monitor import ( - RateLimitMonitor, - RateLimitStats, - record_rate_limit_request, -) -from helper_bot.utils.rate_limiter import ( - ChatRateLimiter, - GlobalRateLimiter, - RateLimitConfig, - RetryHandler, - TelegramRateLimiter, - send_with_rate_limit, -) +from helper_bot.config.rate_limit_config import (RateLimitSettings, + get_rate_limit_config) +from helper_bot.utils.rate_limit_monitor import (RateLimitMonitor, + RateLimitStats, + record_rate_limit_request) +from helper_bot.utils.rate_limiter import (ChatRateLimiter, GlobalRateLimiter, + RateLimitConfig, RetryHandler, + TelegramRateLimiter, + send_with_rate_limit) class TestRateLimitConfig: diff --git a/tests/test_refactored_admin_handlers.py b/tests/test_refactored_admin_handlers.py index 0ed8a43..1f77055 100644 --- a/tests/test_refactored_admin_handlers.py +++ b/tests/test_refactored_admin_handlers.py @@ -4,11 +4,9 @@ import pytest from aiogram import types from aiogram.fsm.context import FSMContext -from helper_bot.handlers.admin.exceptions import ( - InvalidInputError, - UserAlreadyBannedError, - UserNotFoundError, -) +from helper_bot.handlers.admin.exceptions import (InvalidInputError, + UserAlreadyBannedError, + UserNotFoundError) from helper_bot.handlers.admin.services import AdminService, BannedUser, User diff --git a/tests/test_refactored_group_handlers.py b/tests/test_refactored_group_handlers.py index 464c95f..bee38fb 100644 --- a/tests/test_refactored_group_handlers.py +++ b/tests/test_refactored_group_handlers.py @@ -7,14 +7,10 @@ from aiogram import types from aiogram.fsm.context import FSMContext from helper_bot.handlers.group.constants import ERROR_MESSAGES, FSM_STATES -from helper_bot.handlers.group.exceptions import ( - NoReplyToMessageError, - UserNotFoundError, -) -from helper_bot.handlers.group.group_handlers import ( - GroupHandlers, - create_group_handlers, -) +from helper_bot.handlers.group.exceptions import (NoReplyToMessageError, + UserNotFoundError) +from helper_bot.handlers.group.group_handlers import (GroupHandlers, + create_group_handlers) from helper_bot.handlers.group.services import AdminReplyService diff --git a/tests/test_refactored_private_handlers.py b/tests/test_refactored_private_handlers.py index abfca8d..b9d35c3 100644 --- a/tests/test_refactored_private_handlers.py +++ b/tests/test_refactored_private_handlers.py @@ -8,9 +8,7 @@ from aiogram.fsm.context import FSMContext from helper_bot.handlers.private.constants import BUTTON_TEXTS, FSM_STATES from helper_bot.handlers.private.private_handlers import ( - PrivateHandlers, - create_private_handlers, -) + PrivateHandlers, create_private_handlers) from helper_bot.handlers.private.services import BotSettings diff --git a/tests/test_utils.py b/tests/test_utils.py index d511122..fe89ab0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -6,37 +6,18 @@ import pytest import helper_bot.utils.messages as messages # Import for patching constants from database.async_db import AsyncBotDB -from helper_bot.utils.base_dependency_factory import ( - BaseDependencyFactory, - get_global_instance, -) +from helper_bot.utils.base_dependency_factory import (BaseDependencyFactory, + get_global_instance) from helper_bot.utils.helper_func import ( - add_days_to_date, - add_in_db_media, - add_in_db_media_mediagroup, - check_access, - check_user_emoji, - check_username_and_full_name, - delete_user_blacklist, - determine_anonymity, - download_file, - get_banned_users_buttons, - get_banned_users_list, - get_first_name, - get_random_emoji, - get_text_message, - prepare_media_group_from_middlewares, - safe_html_escape, - send_audio_message, - send_media_group_message_to_private_chat, - send_media_group_to_channel, - send_photo_message, - send_text_message, - send_video_message, - send_video_note_message, - send_voice_message, - update_user_info, -) + add_days_to_date, add_in_db_media, add_in_db_media_mediagroup, + check_access, check_user_emoji, check_username_and_full_name, + delete_user_blacklist, determine_anonymity, download_file, + get_banned_users_buttons, get_banned_users_list, get_first_name, + get_random_emoji, get_text_message, prepare_media_group_from_middlewares, + safe_html_escape, send_audio_message, + send_media_group_message_to_private_chat, send_media_group_to_channel, + send_photo_message, send_text_message, send_video_message, + send_video_note_message, send_voice_message, update_user_info) from helper_bot.utils.messages import get_message diff --git a/tests/test_voice_bot_architecture.py b/tests/test_voice_bot_architecture.py index 9f7b7bc..e956b46 100644 --- a/tests/test_voice_bot_architecture.py +++ b/tests/test_voice_bot_architecture.py @@ -4,13 +4,12 @@ from unittest.mock import AsyncMock, Mock, patch import pytest -from helper_bot.handlers.voice.exceptions import AudioProcessingError, VoiceMessageError +from helper_bot.handlers.voice.exceptions import (AudioProcessingError, + VoiceMessageError) from helper_bot.handlers.voice.services import VoiceBotService -from helper_bot.handlers.voice.utils import ( - get_last_message_text, - get_user_emoji_safe, - validate_voice_message, -) +from helper_bot.handlers.voice.utils import (get_last_message_text, + get_user_emoji_safe, + validate_voice_message) class TestVoiceBotService: diff --git a/tests/test_voice_constants.py b/tests/test_voice_constants.py index b6774ef..744b2d7 100644 --- a/tests/test_voice_constants.py +++ b/tests/test_voice_constants.py @@ -1,22 +1,15 @@ import pytest -from helper_bot.handlers.voice.constants import ( - BTN_LISTEN, - BTN_SPEAK, - BUTTON_COMMAND_MAPPING, - CALLBACK_COMMAND_MAPPING, - CALLBACK_DELETE, - CALLBACK_SAVE, - CMD_EMOJI, - CMD_HELP, - CMD_REFRESH, - CMD_RESTART, - CMD_START, - COMMAND_MAPPING, - STATE_STANDUP_WRITE, - STATE_START, - VOICE_BOT_NAME, -) +from helper_bot.handlers.voice.constants import (BTN_LISTEN, BTN_SPEAK, + BUTTON_COMMAND_MAPPING, + CALLBACK_COMMAND_MAPPING, + CALLBACK_DELETE, + CALLBACK_SAVE, CMD_EMOJI, + CMD_HELP, CMD_REFRESH, + CMD_RESTART, CMD_START, + COMMAND_MAPPING, + STATE_STANDUP_WRITE, + STATE_START, VOICE_BOT_NAME) class TestVoiceConstants: diff --git a/tests/test_voice_exceptions.py b/tests/test_voice_exceptions.py index 38d8150..5dd4f7f 100644 --- a/tests/test_voice_exceptions.py +++ b/tests/test_voice_exceptions.py @@ -1,10 +1,8 @@ import pytest -from helper_bot.handlers.voice.exceptions import ( - AudioProcessingError, - VoiceBotError, - VoiceMessageError, -) +from helper_bot.handlers.voice.exceptions import (AudioProcessingError, + VoiceBotError, + VoiceMessageError) class TestVoiceExceptions: diff --git a/tests/test_voice_handler.py b/tests/test_voice_handler.py index beaf8eb..e5f9914 100644 --- a/tests/test_voice_handler.py +++ b/tests/test_voice_handler.py @@ -4,7 +4,8 @@ import pytest from aiogram import types from aiogram.fsm.context import FSMContext -from helper_bot.handlers.voice.constants import STATE_STANDUP_WRITE, STATE_START +from helper_bot.handlers.voice.constants import (STATE_STANDUP_WRITE, + STATE_START) from helper_bot.handlers.voice.voice_handler import VoiceHandlers diff --git a/tests/test_voice_services.py b/tests/test_voice_services.py index dfd37fd..7301806 100644 --- a/tests/test_voice_services.py +++ b/tests/test_voice_services.py @@ -4,7 +4,8 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patch import pytest -from helper_bot.handlers.voice.exceptions import AudioProcessingError, VoiceMessageError +from helper_bot.handlers.voice.exceptions import (AudioProcessingError, + VoiceMessageError) from helper_bot.handlers.voice.services import VoiceBotService diff --git a/tests/test_voice_utils.py b/tests/test_voice_utils.py index 50de559..8ab862c 100644 --- a/tests/test_voice_utils.py +++ b/tests/test_voice_utils.py @@ -4,13 +4,10 @@ from unittest.mock import Mock, patch import pytest from aiogram import types -from helper_bot.handlers.voice.utils import ( - format_time_ago, - get_last_message_text, - get_user_emoji_safe, - plural_time, - validate_voice_message, -) +from helper_bot.handlers.voice.utils import (format_time_ago, + get_last_message_text, + get_user_emoji_safe, plural_time, + validate_voice_message) class TestVoiceUtils: