From 95313ad3dc968b52dea5800cd51e29a4cba1cca1 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 31 Jul 2025 23:38:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D0=B4=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maxapi/bot.py | 9 ++++--- maxapi/methods/get_message.py | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 maxapi/methods/get_message.py diff --git a/maxapi/bot.py b/maxapi/bot.py index eca8ffe..691adf4 100644 --- a/maxapi/bot.py +++ b/maxapi/bot.py @@ -3,6 +3,8 @@ from __future__ import annotations from datetime import datetime from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING +from maxapi.methods.get_message import GetMessage + from .client.default import DefaultConnectionProperties from .types.errors import Error @@ -310,9 +312,10 @@ class Bot(BaseConnection): :return: Объект сообщения """ - return await self.get_messages( - message_ids=[message_id] - ) + return await GetMessage( + bot=self, + message_id=message_id + ).fetch() async def get_me(self) -> User: diff --git a/maxapi/methods/get_message.py b/maxapi/methods/get_message.py new file mode 100644 index 0000000..1d6fdc7 --- /dev/null +++ b/maxapi/methods/get_message.py @@ -0,0 +1,49 @@ +from datetime import datetime +from typing import TYPE_CHECKING, List, Optional, Union + +from ..types.message import Message +from ..enums.http_method import HTTPMethod +from ..enums.api_path import ApiPath +from ..connection.base import BaseConnection + + +if TYPE_CHECKING: + from ..bot import Bot + + +class GetMessage(BaseConnection): + + """ + Класс для получения сообщения. + + Args: + bot (Bot): Экземпляр бота для выполнения запроса. + message_id (str, optional): ID сообщения (mid), чтобы получить одно сообщение в чате. + """ + + def __init__( + self, + bot: 'Bot', + message_id: Optional[str] = None, + ): + self.bot = bot + self.message_id = message_id + + async def fetch(self) -> Message: + + """ + Выполняет GET-запрос для получения сообщения. + + Returns: + Message: Объект с полученным сообщением. + """ + + if self.bot is None: + raise RuntimeError('Bot не инициализирован') + + return await super().request( + method=HTTPMethod.GET, + path=ApiPath.MESSAGES + '/' + self.message_id, + model=Message, + params=self.bot.params + ) \ No newline at end of file