mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 21:49:42 +03:00
Preview command
This commit is contained in:
@@ -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
|
||||
])
|
||||
|
||||
32
handlers/message_handlers/preview_command.py
Normal file
32
handlers/message_handlers/preview_command.py
Normal 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('Нет постов')
|
||||
Reference in New Issue
Block a user