Method for post/post

This commit is contained in:
2023-11-28 22:28:15 +03:00
parent a46a6c659f
commit 8081fbd77c
2 changed files with 23 additions and 11 deletions

View File

@@ -178,17 +178,19 @@ class AdminCommands(Handler):
@self.router.message(Command('post')) @self.router.message(Command('post'))
async def post(message: types.Message): async def post(message: types.Message):
posts = await neuroapi.post.get_will_post() try:
if (posts): post = await neuroapi.post.get_post_to_post()
post = await neuroapi.post.get(str(posts[0].uuid)) if (post):
images = MediaGroupBuilder(caption=post.text) images = MediaGroupBuilder(caption=post.text)
image: neuroTypes.Image image: neuroTypes.Image
for image in sorted(post.images, key=lambda x: x.message_id): for image in sorted(post.images, key=lambda x: x.message_id):
images.add_photo(image.file_id, images.add_photo(image.file_id,
has_spoiler=image.has_spoiler) has_spoiler=image.has_spoiler)
await message.answer_media_group(images.build()) await message.answer_media_group(images.build())
else: else:
await message.answer('Нет постов') await message.answer('Нет постов')
except Exception as e:
await message.answer(f'Ошибка {e}')
@self.router.message(NewSoloPostFilter()) @self.router.message(NewSoloPostFilter())
async def post_solo(message: types.Message): async def post_solo(message: types.Message):

View File

@@ -59,3 +59,13 @@ class Post(ApiMethod):
if 'statusCode' in data: if 'statusCode' in data:
raise Exception(data['message']) raise Exception(data['message'])
return neuroTypes.Post.from_dict(data) return neuroTypes.Post.from_dict(data)
async def get_post_to_post(self):
response = requests.get(self.api_url+f"/post/post")
data = response.json()
if 'statusCode' in data:
if response.status_code==404:
return None
else:
raise Exception(data['message'])
return neuroTypes.Post.from_dict(data)