Files
neuro-reply-bot-reworked/handlers/message_handlers/post_command.py
2024-02-13 16:04:47 +03:00

32 lines
1.3 KiB
Python

from aiogram import types
from aiogram.filters import Command
from aiogram.utils.media_group import MediaGroupBuilder
import neuroapi.types as neuroTypes
from neuroapi import neuroapi
from .handler import MessageHandlerABC
class PostCommand(MessageHandlerABC):
filter = Command('post')
async def _command(self, message: types.Message):
settings = neuroTypes.BotSettings.get_instance()
try:
post = await neuroapi.post.get_post_to_post()
print(post)
if (post):
images = MediaGroupBuilder(
caption=post.text + '\n\nПредложка: @neur0w0men_reply_bot', caption_entities=post.message_entities)
image: neuroTypes.Image
for image in sorted(post.images, key=lambda x: x.message_id):
images.add_photo(image.file_id,
has_spoiler=image.has_spoiler)
await self.bot.send_media_group(settings.channel, images.build())
if message:
await message.answer('Пост успешно опубликован!')
elif message:
await message.answer('Нет постов')
except Exception as e:
if message:
await message.answer(f'Ошибка {e}')