Preview command

This commit is contained in:
2024-02-14 22:41:08 +03:00
parent 0c6a2a2432
commit 0babe084ad
3 changed files with 49 additions and 1 deletions

View File

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

View File

@@ -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('Нет постов')

View File

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