Refactoring: handlers now implemented as classes. Module structure

This commit is contained in:
2024-02-11 12:40:11 +03:00
parent c2d7fd41d7
commit f3cdeeff3c
15 changed files with 330 additions and 316 deletions

View 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}')