mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-15 05:59:43 +03:00
Refactoring: handlers now implemented as classes. Module structure
This commit is contained in:
31
handlers/message_handlers/post_command.py
Normal file
31
handlers/message_handlers/post_command.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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()
|
||||
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}')
|
||||
Reference in New Issue
Block a user