This commit is contained in:
Mikan
2025-08-07 00:38:19 +03:00
parent 500b6f60a2
commit a7346ac17f
6 changed files with 123 additions and 90 deletions

50
handlers/media_handler.py Normal file
View File

@@ -0,0 +1,50 @@
import logging
from aiogram import types
from aiogram.dispatcher import Dispatcher
from config import MODERATORS_CHAT_ID
# Логирование
logger = logging.getLogger(__name__)
# Обработчик медиа-сообщений
async def handle_media_message(message: types.Message):
user_id = message.from_user.id
content_type = message.content_type
logger.info(f"Получено медиа-сообщение типа {content_type} от пользователя {user_id}")
try:
if content_type == "photo":
await message.bot.send_photo(chat_id=MODERATORS_CHAT_ID, photo=message.photo[-1].file_id)
elif content_type == "video":
await message.bot.send_video(chat_id=MODERATORS_CHAT_ID, video=message.video.file_id)
elif content_type == "audio":
await message.bot.send_audio(chat_id=MODERATORS_CHAT_ID, audio=message.audio.file_id)
elif content_type == "document":
await message.bot.send_document(chat_id=MODERATORS_CHAT_ID, document=message.document.file_id)
elif content_type == "sticker":
await message.bot.send_sticker(chat_id=MODERATORS_CHAT_ID, sticker=message.sticker.file_id)
elif content_type == "voice":
await message.bot.send_voice(chat_id=MODERATORS_CHAT_ID, voice=message.voice.file_id)
elif content_type == "video_note":
await message.bot.send_video_note(chat_id=MODERATORS_CHAT_ID, video_note=message.video_note.file_id)
await message.answer("Ваше медиа-сообщение успешно отправлено администраторам!")
except Exception as e:
logger.error(f"Ошибка при отправке медиа-сообщения: {e}")
await message.answer("Произошла ошибка при отправке сообщения. Попробуйте позже.")
# Регистрация обработчика медиа-сообщений
def register_media_handler(dp: Dispatcher):
dp.register_message_handler(
handle_media_message,
content_types=[
types.ContentType.PHOTO,
types.ContentType.VIDEO,
types.ContentType.AUDIO,
types.ContentType.DOCUMENT,
types.ContentType.STICKER,
types.ContentType.VOICE,
types.ContentType.VIDEO_NOTE
]
)