Dev 13 #15

Merged
KerradKerridi merged 15 commits from dev-13 into master 2026-02-01 21:29:08 +00:00
44 changed files with 416 additions and 207 deletions
Showing only changes of commit 5ff66993fa - Show all commits

View File

@@ -11,9 +11,19 @@
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
# Для обратной совместимости экспортируем старый интерфейс

View File

@@ -3,9 +3,16 @@ 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

View File

@@ -2,8 +2,9 @@ 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

View File

@@ -1,10 +1,20 @@
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",

View File

@@ -4,19 +4,26 @@ 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,
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,
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)
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

View File

@@ -8,14 +8,18 @@ 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

View File

@@ -1,11 +1,16 @@
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,
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)
get_banned_users_list,
)
# Local imports - metrics
from helper_bot.utils.metrics import track_errors, track_time
from logs.custom_logger import logger

View File

@@ -1,8 +1,19 @@
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__ = [

View File

@@ -11,25 +11,45 @@ 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,
from helper_bot.keyboards.keyboards import (
create_keyboard_for_ban_reason,
create_keyboard_with_pagination,
get_reply_keyboard_admin)
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()

View File

@@ -6,27 +6,47 @@ 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,
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)
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:

View File

@@ -6,6 +6,7 @@ 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

View File

@@ -25,8 +25,9 @@ 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"]

View File

@@ -7,8 +7,10 @@ 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

View File

@@ -8,6 +8,7 @@ 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

View File

@@ -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

View File

@@ -25,8 +25,9 @@ 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"]

View File

@@ -12,15 +12,19 @@ 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

View File

@@ -15,17 +15,32 @@ 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,
from helper_bot.utils.metrics import (
db_query_time,
track_errors,
track_file_operations,
track_media_processing, track_time)
track_media_processing,
track_time,
)
from logs.custom_logger import logger

View File

@@ -8,16 +8,23 @@ from typing import List, Optional, Tuple
from aiogram.types import FSInputFile
from helper_bot.handlers.voice.constants import (MESSAGE_DELAY_1,
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,
MESSAGE_DELAY_4,
STICK_DIR,
STICK_PATTERN,
STICKER_DELAY,
VOICE_USERS_DIR,
)
from helper_bot.handlers.voice.exceptions import (
AudioProcessingError,
DatabaseError,
FileOperationError,
VoiceMessageError)
VoiceMessageError,
)
# Local imports - metrics
from helper_bot.utils.metrics import db_query_time, track_errors, track_time
from logs.custom_logger import logger

View File

@@ -11,21 +11,33 @@ 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,
from helper_bot.handlers.voice.utils import (
get_last_message_text,
get_user_emoji_safe,
validate_voice_message)
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

View File

@@ -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(

View File

@@ -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 = {}

View File

@@ -6,8 +6,7 @@ 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

View File

@@ -17,17 +17,29 @@ 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

View File

@@ -10,8 +10,13 @@ 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 теперь создаются в основном классе

View File

@@ -188,8 +188,7 @@ 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:

View File

@@ -68,8 +68,7 @@ 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("Планировщик метрик остановлен")

View File

@@ -4,8 +4,7 @@ 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

View File

@@ -4,8 +4,10 @@ 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:

View File

@@ -5,8 +5,9 @@ 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:

View File

@@ -5,7 +5,9 @@ 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

View File

@@ -10,8 +10,11 @@ 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:

View File

@@ -1,16 +1,22 @@
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,
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)
get_reply_keyboard_leave_chat,
)
class TestKeyboards:

View File

@@ -8,15 +8,20 @@ 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,
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,
record_rate_limit_request,
)
from helper_bot.utils.rate_limiter import (
ChatRateLimiter,
GlobalRateLimiter,
RateLimitConfig,
RetryHandler,
TelegramRateLimiter,
send_with_rate_limit)
send_with_rate_limit,
)
class TestRateLimitConfig:

View File

@@ -4,9 +4,11 @@ import pytest
from aiogram import types
from aiogram.fsm.context import FSMContext
from helper_bot.handlers.admin.exceptions import (InvalidInputError,
from helper_bot.handlers.admin.exceptions import (
InvalidInputError,
UserAlreadyBannedError,
UserNotFoundError)
UserNotFoundError,
)
from helper_bot.handlers.admin.services import AdminService, BannedUser, User

View File

@@ -7,10 +7,14 @@ 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

View File

@@ -8,7 +8,9 @@ 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

View File

@@ -6,18 +6,37 @@ 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

View File

@@ -4,12 +4,13 @@ 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,
from helper_bot.handlers.voice.utils import (
get_last_message_text,
get_user_emoji_safe,
validate_voice_message)
validate_voice_message,
)
class TestVoiceBotService:

View File

@@ -1,15 +1,22 @@
import pytest
from helper_bot.handlers.voice.constants import (BTN_LISTEN, BTN_SPEAK,
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,
CALLBACK_SAVE,
CMD_EMOJI,
CMD_HELP,
CMD_REFRESH,
CMD_RESTART,
CMD_START,
COMMAND_MAPPING,
STATE_STANDUP_WRITE,
STATE_START, VOICE_BOT_NAME)
STATE_START,
VOICE_BOT_NAME,
)
class TestVoiceConstants:

View File

@@ -1,8 +1,10 @@
import pytest
from helper_bot.handlers.voice.exceptions import (AudioProcessingError,
from helper_bot.handlers.voice.exceptions import (
AudioProcessingError,
VoiceBotError,
VoiceMessageError)
VoiceMessageError,
)
class TestVoiceExceptions:

View File

@@ -4,8 +4,7 @@ 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

View File

@@ -4,8 +4,7 @@ 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

View File

@@ -4,10 +4,13 @@ from unittest.mock import Mock, patch
import pytest
from aiogram import types
from helper_bot.handlers.voice.utils import (format_time_ago,
from helper_bot.handlers.voice.utils import (
format_time_ago,
get_last_message_text,
get_user_emoji_safe, plural_time,
validate_voice_message)
get_user_emoji_safe,
plural_time,
validate_voice_message,
)
class TestVoiceUtils: