diff --git a/handlers/admin_commands.py b/handlers/admin_commands.py index f6bb7fa..e4b3a9b 100644 --- a/handlers/admin_commands.py +++ b/handlers/admin_commands.py @@ -76,7 +76,6 @@ class AdminCommands(Handler): "_", "\_").replace('.', '\.').replace(',', '\,').replace('!', '\!').replace('-', '\-').replace(':', '\:').replace('+', '\+'), parse_mode='markdownv2') await message.answer(res2, entities=posts_entities) - #TODO: Сделать изменение Message Entities @self.router.message(Command('edit')) async def edit_post_by_order_num(message: types.Message): command = message.text.split(' ', 2) @@ -84,7 +83,8 @@ class AdminCommands(Handler): await message.reply('Недостаточно аргументов!') return try: - await neuroapi.post.edit_text_by_order_num(command[1], command[2]) + await neuroapi.post.edit_text_by_order_num(command[1], command[2], message.entities) + #TODO: Message Entities для уведомления об изменении поста await message.reply(f'Текст поста успешно изменен на: {command[2]}') except Exception as e: await message.reply(f'Ошибка: {e}') diff --git a/neuroapi/_methods/post.py b/neuroapi/_methods/post.py index 7c91add..d2d58ef 100644 --- a/neuroapi/_methods/post.py +++ b/neuroapi/_methods/post.py @@ -72,8 +72,19 @@ class Post(ApiMethod): raise Exception(data['message']) return neuroTypes.Post.from_dict(data) - async def edit_text_by_order_num(self, order: str, text: str): - response = requests.post(self.api_url + f"/post/edit-post-by-order-num/{order}", data={"text": text}) + async def edit_text_by_order_num(self, order: str, text: str, message_entities: Optional[List[MessageEntity]] = None): + payload = {"text": text} + if message_entities is not None: + if message_entities is not None: + mes_ent = list(map(lambda x: x.model_dump(), message_entities)) + arr =[] + print(mes_ent) + for item in mes_ent: + if item['type'] == 'bot_command': continue + item['offset'] -= 7+len(order) + arr.append(item) + payload['message_entities'] = json.dumps(arr) + response = requests.post(self.api_url + f"/post/edit-post-by-order-num/{order}", data=payload) data = response.json() if 'statusCode' in data: raise Exception(data['message'])