diff --git a/handlers/admin_commands.py b/handlers/admin_commands.py index 636bff4..edb5d92 100644 --- a/handlers/admin_commands.py +++ b/handlers/admin_commands.py @@ -2,6 +2,7 @@ from aiogram import Bot from handlers.handler import Handler from handlers.message_handlers.delete_command import DeleteCommand +from handlers.message_handlers.deleted_posts_command import DeletedPostsCommand from handlers.message_handlers.edit_command import EditCommand from handlers.message_handlers.info_command import InfoCommand from handlers.message_handlers.newpost_command import (NewPostCommand, @@ -36,5 +37,6 @@ class AdminCommands(Handler): NewPostSoloCommand, PreviewCommand, DeleteCommand, + DeletedPostsCommand, ReplyToUserCommand ]) diff --git a/handlers/message_handlers/deleted_posts_command.py b/handlers/message_handlers/deleted_posts_command.py new file mode 100644 index 0000000..a39d560 --- /dev/null +++ b/handlers/message_handlers/deleted_posts_command.py @@ -0,0 +1,22 @@ +from aiogram.filters import Command +from aiogram.types import Message + +from neuroapi import neuroapi + +from .handler import MessageHandlerABC + + +class DeletedPostsCommand(MessageHandlerABC): + filter = Command('deleted') + async def _command(self, message: Message): + try: + deleted_posts = await neuroapi.post.get_deleted_posts() + if len(deleted_posts): + s = "Удаленные посты:\n" + for i, post in enumerate(deleted_posts): + s += f"{i+1}. {post.text}\n" + else: + s = "Нет удаленных постов" + await message.answer(s) + except Exception as e: + await message.answer(f'Ошибка: {e}') \ No newline at end of file diff --git a/neuroapi/_methods/post.py b/neuroapi/_methods/post.py index 39d814d..99b1189 100644 --- a/neuroapi/_methods/post.py +++ b/neuroapi/_methods/post.py @@ -111,4 +111,11 @@ class Post(ApiMethod): 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 + raise Exception(data['message']) + async def get_deleted_posts(self) -> List[neuroTypes.Post]: + async with ClientSession() as session: + response = await session.get(self.api_url+f'/post/get-deleted') + data = await response.json() + if 'statusCode' in data: + raise Exception(data['message']) + return [neuroTypes.Post.from_dict(post) for post in data]