mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 21:49:42 +03:00
Restore post command
This commit is contained in:
@@ -10,6 +10,7 @@ from handlers.message_handlers.newpost_command import (NewPostCommand,
|
||||
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.restore_command import RestoreCommand
|
||||
from handlers.message_handlers.settings_command import SettingsCommand
|
||||
from handlers.message_handlers.update_settings import UpdateSettingsCommand
|
||||
from handlers.middlewares.media_group import MediaGroupMiddleware
|
||||
@@ -29,6 +30,7 @@ class AdminCommands(Handler):
|
||||
(UpdateSettingsCommand, PostCommand(self.bot).handler),
|
||||
EditCommand,
|
||||
PostCommand,
|
||||
RestoreCommand,
|
||||
SettingsCommand,
|
||||
])
|
||||
self.router.message.middleware(MediaGroupMiddleware())
|
||||
|
||||
20
handlers/message_handlers/restore_command.py
Normal file
20
handlers/message_handlers/restore_command.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from aiogram.filters import Command
|
||||
from aiogram.types import Message
|
||||
|
||||
from neuroapi import neuroapi
|
||||
|
||||
from .handler import MessageHandlerABC
|
||||
|
||||
|
||||
class RestoreCommand(MessageHandlerABC):
|
||||
filter = Command('restore')
|
||||
async def _command(self, message: Message):
|
||||
try:
|
||||
command = message.text.split()
|
||||
if len(command) != 2:
|
||||
raise Exception('Неверное количество аргументов')
|
||||
order = command[1]
|
||||
await neuroapi.post.restore_post(order)
|
||||
await message.answer('Пост восстановлен')
|
||||
except Exception as e:
|
||||
await message.answer(f'Ошибка: {e}')
|
||||
@@ -119,3 +119,11 @@ class Post(ApiMethod):
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
return [neuroTypes.Post.from_dict(post) for post in data]
|
||||
|
||||
async def restore_post(self, order: str):
|
||||
async with ClientSession() as session:
|
||||
response = await session.put(self.api_url+f'/post/restore-post-by-order/{order}')
|
||||
data = await response.json()
|
||||
if 'statusCode' in data:
|
||||
raise Exception(data['message'])
|
||||
return neuroTypes.Post.from_dict(data)
|
||||
|
||||
Reference in New Issue
Block a user