Доработана загрузка медиа
This commit is contained in:
parent
48b480ff9e
commit
fd9986b02e
@ -3,20 +3,14 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from typing import Any, Dict, List, TYPE_CHECKING, Optional
|
from typing import Any, Dict, List, TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from json import loads as json_loads
|
|
||||||
|
|
||||||
from ..utils.message import process_input_media
|
from ..utils.message import process_input_media
|
||||||
|
|
||||||
from ..exceptions.max import MaxUploadFileFailed
|
|
||||||
|
|
||||||
from .types.sended_message import SendedMessage
|
from .types.sended_message import SendedMessage
|
||||||
from ..types.attachments.upload import AttachmentPayload, AttachmentUpload
|
|
||||||
from ..types.errors import Error
|
from ..types.errors import Error
|
||||||
from ..types.message import NewMessageLink
|
from ..types.message import NewMessageLink
|
||||||
from ..types.input_media import InputMedia, InputMediaBuffer
|
from ..types.input_media import InputMedia, InputMediaBuffer
|
||||||
from ..types.attachments.attachment import Attachment
|
from ..types.attachments.attachment import Attachment
|
||||||
|
|
||||||
from ..enums.upload_type import UploadType
|
|
||||||
from ..enums.parse_mode import ParseMode
|
from ..enums.parse_mode import ParseMode
|
||||||
from ..enums.http_method import HTTPMethod
|
from ..enums.http_method import HTTPMethod
|
||||||
from ..enums.api_path import ApiPath
|
from ..enums.api_path import ApiPath
|
||||||
@ -29,10 +23,6 @@ if TYPE_CHECKING:
|
|||||||
from ..bot import Bot
|
from ..bot import Bot
|
||||||
|
|
||||||
|
|
||||||
RETRY_DELAY = 2
|
|
||||||
ATTEMPTS_COUNT = 5
|
|
||||||
|
|
||||||
|
|
||||||
class SendMessage(BaseConnection):
|
class SendMessage(BaseConnection):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -110,8 +100,10 @@ class SendMessage(BaseConnection):
|
|||||||
json['notify'] = self.notify
|
json['notify'] = self.notify
|
||||||
if not self.parse_mode is None: json['format'] = self.parse_mode.value
|
if not self.parse_mode is None: json['format'] = self.parse_mode.value
|
||||||
|
|
||||||
|
await asyncio.sleep(self.bot.after_input_media_delay)
|
||||||
|
|
||||||
response = None
|
response = None
|
||||||
for attempt in range(ATTEMPTS_COUNT):
|
for attempt in range(self.ATTEMPTS_COUNT):
|
||||||
response = await super().request(
|
response = await super().request(
|
||||||
method=HTTPMethod.POST,
|
method=HTTPMethod.POST,
|
||||||
path=ApiPath.MESSAGES,
|
path=ApiPath.MESSAGES,
|
||||||
@ -122,8 +114,8 @@ class SendMessage(BaseConnection):
|
|||||||
|
|
||||||
if isinstance(response, Error):
|
if isinstance(response, Error):
|
||||||
if response.raw.get('code') == 'attachment.not.ready':
|
if response.raw.get('code') == 'attachment.not.ready':
|
||||||
logger_bot.info(f'Ошибка при отправке загруженного медиа, попытка {attempt+1}, жду {RETRY_DELAY} секунды')
|
logger_bot.info(f'Ошибка при отправке загруженного медиа, попытка {attempt+1}, жду {self.RETRY_DELAY} секунды')
|
||||||
await asyncio.sleep(RETRY_DELAY)
|
await asyncio.sleep(self.RETRY_DELAY)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
Loading…
x
Reference in New Issue
Block a user