diff --git a/handlers/admin_commands.py b/handlers/admin_commands.py index 50fac78..636bff4 100644 --- a/handlers/admin_commands.py +++ b/handlers/admin_commands.py @@ -7,6 +7,7 @@ from handlers.message_handlers.info_command import InfoCommand from handlers.message_handlers.newpost_command import (NewPostCommand, NewPostSoloCommand) from handlers.message_handlers.post_command import PostCommand +from handlers.message_handlers.preview_command import PreviewCommand from handlers.message_handlers.reply_to_user import ReplyToUserCommand from handlers.message_handlers.settings_command import SettingsCommand from handlers.message_handlers.update_settings import UpdateSettingsCommand @@ -33,6 +34,7 @@ class AdminCommands(Handler): self.add_handlers([ NewPostCommand, NewPostSoloCommand, + PreviewCommand, DeleteCommand, ReplyToUserCommand ]) diff --git a/handlers/message_handlers/preview_command.py b/handlers/message_handlers/preview_command.py new file mode 100644 index 0000000..805539d --- /dev/null +++ b/handlers/message_handlers/preview_command.py @@ -0,0 +1,32 @@ +from aiogram.filters import Command +from aiogram.types import Message +from aiogram.utils.media_group import MediaGroupBuilder + +import neuroapi.types as neuroTypes +from neuroapi import neuroapi + +from .handler import MessageHandlerABC + + +class PreviewCommand(MessageHandlerABC): + filter = Command('preview') + async def _command(self, message: Message): + text = message.text.split() + if len(text)!=2: + await message.answer('Неверное количество аргументов') + return + try: + post = await neuroapi.post.get_by_order(text[1]) + except Exception as e: + await message.answer(f'Ошибка {e}') + return + 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(message.chat.id, images.build()) + elif message: + await message.answer('Нет постов') \ No newline at end of file diff --git a/neuroapi/_methods/post.py b/neuroapi/_methods/post.py index 59cb520..39d814d 100644 --- a/neuroapi/_methods/post.py +++ b/neuroapi/_methods/post.py @@ -55,6 +55,14 @@ class Post(ApiMethod): if 'statusCode' in data: raise Exception(data['message']) return neuroTypes.Post.from_dict(data) + + async def get_by_order(self, post_order: str): + async with ClientSession() as session: + response = await session.get(self.api_url+f'/post/get-post-by-order/{post_order}') + data = await response.json() + if 'statusCode' in data: + raise Exception(data['message']) + return neuroTypes.Post.from_dict(data) async def get_by_media_group_id(self, media_group_id: str): async with ClientSession() as session: @@ -97,4 +105,10 @@ class Post(ApiMethod): return None else: raise Exception(data['message']) - return neuroTypes.Post.from_dict(data) \ No newline at end of file + return neuroTypes.Post.from_dict(data) + + async def delete_by_order(self, order: str): + response = requests.delete(self.api_url+f"/post/delete-post-by-order/{order}") + data = response.json() + if 'statusCode' in data: + raise Exception(data['message']) \ No newline at end of file