Deleted posts command

This commit is contained in:
2024-02-15 12:16:47 +03:00
parent f1d1fa1914
commit 77a916dc0b
3 changed files with 32 additions and 1 deletions

View File

@@ -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
])

View File

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

View File

@@ -112,3 +112,10 @@ class Post(ApiMethod):
data = response.json()
if 'statusCode' in data:
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]