diff --git a/handlers/admin_commands.py b/handlers/admin_commands.py index 2641225..7ebbbcb 100644 --- a/handlers/admin_commands.py +++ b/handlers/admin_commands.py @@ -178,17 +178,19 @@ class AdminCommands(Handler): @self.router.message(Command('post')) async def post(message: types.Message): - posts = await neuroapi.post.get_will_post() - if (posts): - post = await neuroapi.post.get(str(posts[0].uuid)) - images = MediaGroupBuilder(caption=post.text) - 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 message.answer_media_group(images.build()) - else: - await message.answer('Нет постов') + try: + post = await neuroapi.post.get_post_to_post() + if (post): + images = MediaGroupBuilder(caption=post.text) + 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 message.answer_media_group(images.build()) + else: + await message.answer('Нет постов') + except Exception as e: + await message.answer(f'Ошибка {e}') @self.router.message(NewSoloPostFilter()) async def post_solo(message: types.Message): diff --git a/neuroapi/_methods/post.py b/neuroapi/_methods/post.py index f60fa3f..2bf4489 100644 --- a/neuroapi/_methods/post.py +++ b/neuroapi/_methods/post.py @@ -59,3 +59,13 @@ class Post(ApiMethod): if 'statusCode' in data: raise Exception(data['message']) 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) \ No newline at end of file