From fd9986b02ed1caa0d43202d28a0d679e94fd3596 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 24 Jul 2025 19:37:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BC=D0=B5=D0=B4=D0=B8=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maxapi/methods/send_message.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/maxapi/methods/send_message.py b/maxapi/methods/send_message.py index ab39b7e..3d453e2 100644 --- a/maxapi/methods/send_message.py +++ b/maxapi/methods/send_message.py @@ -3,20 +3,14 @@ import asyncio from typing import Any, Dict, List, TYPE_CHECKING, Optional -from json import loads as json_loads - from ..utils.message import process_input_media -from ..exceptions.max import MaxUploadFileFailed - from .types.sended_message import SendedMessage -from ..types.attachments.upload import AttachmentPayload, AttachmentUpload from ..types.errors import Error from ..types.message import NewMessageLink from ..types.input_media import InputMedia, InputMediaBuffer from ..types.attachments.attachment import Attachment -from ..enums.upload_type import UploadType from ..enums.parse_mode import ParseMode from ..enums.http_method import HTTPMethod from ..enums.api_path import ApiPath @@ -29,10 +23,6 @@ if TYPE_CHECKING: from ..bot import Bot -RETRY_DELAY = 2 -ATTEMPTS_COUNT = 5 - - class SendMessage(BaseConnection): """ @@ -109,9 +99,11 @@ class SendMessage(BaseConnection): if not self.link is None: json['link'] = self.link.model_dump() json['notify'] = self.notify if not self.parse_mode is None: json['format'] = self.parse_mode.value + + await asyncio.sleep(self.bot.after_input_media_delay) response = None - for attempt in range(ATTEMPTS_COUNT): + for attempt in range(self.ATTEMPTS_COUNT): response = await super().request( method=HTTPMethod.POST, path=ApiPath.MESSAGES, @@ -122,8 +114,8 @@ class SendMessage(BaseConnection): if isinstance(response, Error): if response.raw.get('code') == 'attachment.not.ready': - logger_bot.info(f'Ошибка при отправке загруженного медиа, попытка {attempt+1}, жду {RETRY_DELAY} секунды') - await asyncio.sleep(RETRY_DELAY) + logger_bot.info(f'Ошибка при отправке загруженного медиа, попытка {attempt+1}, жду {self.RETRY_DELAY} секунды') + await asyncio.sleep(self.RETRY_DELAY) continue return response