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,
|
from handlers.message_handlers.newpost_command import (NewPostCommand,
|
||||||
NewPostSoloCommand)
|
NewPostSoloCommand)
|
||||||
from handlers.message_handlers.post_command import PostCommand
|
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.reply_to_user import ReplyToUserCommand
|
||||||
from handlers.message_handlers.settings_command import SettingsCommand
|
from handlers.message_handlers.settings_command import SettingsCommand
|
||||||
from handlers.message_handlers.update_settings import UpdateSettingsCommand
|
from handlers.message_handlers.update_settings import UpdateSettingsCommand
|
||||||
@@ -33,6 +34,7 @@ class AdminCommands(Handler):
|
|||||||
self.add_handlers([
|
self.add_handlers([
|
||||||
NewPostCommand,
|
NewPostCommand,
|
||||||
NewPostSoloCommand,
|
NewPostSoloCommand,
|
||||||
|
PreviewCommand,
|
||||||
DeleteCommand,
|
DeleteCommand,
|
||||||
ReplyToUserCommand
|
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('Нет постов')
|
||||||
@@ -56,6 +56,14 @@ class Post(ApiMethod):
|
|||||||
raise Exception(data['message'])
|
raise Exception(data['message'])
|
||||||
return neuroTypes.Post.from_dict(data)
|
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 def get_by_media_group_id(self, media_group_id: str):
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
response = await session.get(self.api_url+f'/post/get-by-media-group-id/{media_group_id}')
|
response = await session.get(self.api_url+f'/post/get-by-media-group-id/{media_group_id}')
|
||||||
@@ -98,3 +106,9 @@ class Post(ApiMethod):
|
|||||||
else:
|
else:
|
||||||
raise Exception(data['message'])
|
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'])
|
||||||
Reference in New Issue
Block a user