mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Migrate from Black to Ruff (#1750)
* Migrate from Black to Ruff and reformat code with enabling additional linter checks * Add changelog for migration to Ruff as formatter and linter * Add type ignores for specific attributes and replace tuple with set for chat type check * Remove file from another changes
This commit is contained in:
parent
a4a3f42c71
commit
ec7da0f678
214 changed files with 886 additions and 964 deletions
|
|
@ -2,12 +2,11 @@ from __future__ import annotations
|
|||
|
||||
import io
|
||||
import pathlib
|
||||
from collections.abc import AsyncGenerator, AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
from types import TracebackType
|
||||
from typing import (
|
||||
Any,
|
||||
AsyncGenerator,
|
||||
AsyncIterator,
|
||||
BinaryIO,
|
||||
TypeVar,
|
||||
cast,
|
||||
|
|
@ -283,9 +282,9 @@ class Bot:
|
|||
# Few arguments are completely removed in 3.7.0 version
|
||||
# Temporary solution to raise an error if user passed these arguments
|
||||
# with explanation how to fix it
|
||||
parse_mode = kwargs.get("parse_mode", None)
|
||||
link_preview_is_disabled = kwargs.get("disable_web_page_preview", None)
|
||||
protect_content = kwargs.get("protect_content", None)
|
||||
parse_mode = kwargs.get("parse_mode")
|
||||
link_preview_is_disabled = kwargs.get("disable_web_page_preview")
|
||||
protect_content = kwargs.get("protect_content")
|
||||
if (
|
||||
parse_mode is not None
|
||||
or link_preview_is_disabled is not None
|
||||
|
|
@ -310,7 +309,7 @@ class Bot:
|
|||
self.__token = token
|
||||
self._me: User | None = None
|
||||
|
||||
async def __aenter__(self) -> "Bot":
|
||||
async def __aenter__(self) -> Bot:
|
||||
return self
|
||||
|
||||
async def __aexit__(
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def _prepare_connector(chain_or_plain: _ProxyType) -> tuple[type[TCPConnector],
|
|||
# since tuple is Iterable(compatible with _ProxyChain) object, we assume that
|
||||
# user wants chained proxies if tuple is a pair of string(url) and BasicAuth
|
||||
if isinstance(chain_or_plain, str) or (
|
||||
isinstance(chain_or_plain, tuple) and len(chain_or_plain) == 2
|
||||
isinstance(chain_or_plain, tuple) and len(chain_or_plain) == 2 # noqa: PLR2004
|
||||
):
|
||||
chain_or_plain = cast(_ProxyBasic, chain_or_plain)
|
||||
return ProxyConnector, _retrieve_basic(chain_or_plain)
|
||||
|
|
@ -170,10 +170,10 @@ class AiohttpSession(BaseSession):
|
|||
timeout=self.timeout if timeout is None else timeout,
|
||||
) as resp:
|
||||
raw_result = await resp.text()
|
||||
except asyncio.TimeoutError:
|
||||
raise TelegramNetworkError(method=method, message="Request timeout error")
|
||||
except asyncio.TimeoutError as e:
|
||||
raise TelegramNetworkError(method=method, message="Request timeout error") from e
|
||||
except ClientError as e:
|
||||
raise TelegramNetworkError(method=method, message=f"{type(e).__name__}: {e}")
|
||||
raise TelegramNetworkError(method=method, message=f"{type(e).__name__}: {e}") from e
|
||||
response = self.check_response(
|
||||
bot=bot,
|
||||
method=method,
|
||||
|
|
|
|||
|
|
@ -90,14 +90,14 @@ class BaseSession(abc.ABC):
|
|||
# in due to decoder can be customized and raise any exception
|
||||
|
||||
msg = "Failed to decode object"
|
||||
raise ClientDecodeError(msg, e, content)
|
||||
raise ClientDecodeError(msg, e, content) from e
|
||||
|
||||
try:
|
||||
response_type = Response[method.__returning__] # type: ignore
|
||||
response = response_type.model_validate(json_data, context={"bot": bot})
|
||||
except ValidationError as e:
|
||||
msg = "Failed to deserialize object"
|
||||
raise ClientDecodeError(msg, e, json_data)
|
||||
raise ClientDecodeError(msg, e, json_data) from e
|
||||
|
||||
if HTTPStatus.OK <= status_code <= HTTPStatus.IM_USED and response.ok:
|
||||
return response
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ class FlagDecorator:
|
|||
flag: Flag
|
||||
|
||||
@classmethod
|
||||
def _with_flag(cls, flag: Flag) -> "FlagDecorator":
|
||||
def _with_flag(cls, flag: Flag) -> FlagDecorator:
|
||||
return cls(flag)
|
||||
|
||||
def _with_value(self, value: Any) -> "FlagDecorator":
|
||||
def _with_value(self, value: Any) -> FlagDecorator:
|
||||
new_flag = Flag(self.flag.name, value)
|
||||
return self._with_flag(new_flag)
|
||||
|
||||
|
|
@ -33,11 +33,11 @@ class FlagDecorator:
|
|||
pass
|
||||
|
||||
@overload
|
||||
def __call__(self, value: Any, /) -> "FlagDecorator":
|
||||
def __call__(self, value: Any, /) -> FlagDecorator:
|
||||
pass
|
||||
|
||||
@overload
|
||||
def __call__(self, **kwargs: Any) -> "FlagDecorator":
|
||||
def __call__(self, **kwargs: Any) -> FlagDecorator:
|
||||
pass
|
||||
|
||||
def __call__(
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class _MemberStatusMarker:
|
|||
def __or__(
|
||||
self,
|
||||
other: _MemberStatusMarker | _MemberStatusGroupMarker,
|
||||
) -> "_MemberStatusGroupMarker":
|
||||
) -> _MemberStatusGroupMarker:
|
||||
if isinstance(other, _MemberStatusMarker):
|
||||
return _MemberStatusGroupMarker(self, other)
|
||||
if isinstance(other, _MemberStatusGroupMarker):
|
||||
|
|
@ -53,7 +53,7 @@ class _MemberStatusMarker:
|
|||
def __rshift__(
|
||||
self,
|
||||
other: _MemberStatusMarker | _MemberStatusGroupMarker,
|
||||
) -> "_MemberStatusTransition":
|
||||
) -> _MemberStatusTransition:
|
||||
old = _MemberStatusGroupMarker(self)
|
||||
if isinstance(other, _MemberStatusMarker):
|
||||
return _MemberStatusTransition(old=old, new=_MemberStatusGroupMarker(other))
|
||||
|
|
@ -68,7 +68,7 @@ class _MemberStatusMarker:
|
|||
def __lshift__(
|
||||
self,
|
||||
other: _MemberStatusMarker | _MemberStatusGroupMarker,
|
||||
) -> "_MemberStatusTransition":
|
||||
) -> _MemberStatusTransition:
|
||||
new = _MemberStatusGroupMarker(self)
|
||||
if isinstance(other, _MemberStatusMarker):
|
||||
return _MemberStatusTransition(old=_MemberStatusGroupMarker(other), new=new)
|
||||
|
|
@ -118,7 +118,7 @@ class _MemberStatusGroupMarker:
|
|||
def __rshift__(
|
||||
self,
|
||||
other: _MemberStatusMarker | _MemberStatusGroupMarker,
|
||||
) -> "_MemberStatusTransition":
|
||||
) -> _MemberStatusTransition:
|
||||
if isinstance(other, _MemberStatusMarker):
|
||||
return _MemberStatusTransition(old=self, new=_MemberStatusGroupMarker(other))
|
||||
if isinstance(other, _MemberStatusGroupMarker):
|
||||
|
|
@ -132,7 +132,7 @@ class _MemberStatusGroupMarker:
|
|||
def __lshift__(
|
||||
self,
|
||||
other: _MemberStatusMarker | _MemberStatusGroupMarker,
|
||||
) -> "_MemberStatusTransition":
|
||||
) -> _MemberStatusTransition:
|
||||
if isinstance(other, _MemberStatusMarker):
|
||||
return _MemberStatusTransition(old=_MemberStatusGroupMarker(other), new=self)
|
||||
if isinstance(other, _MemberStatusGroupMarker):
|
||||
|
|
|
|||
|
|
@ -123,14 +123,15 @@ class Command(Filter):
|
|||
result.update(command.magic_result)
|
||||
return result
|
||||
|
||||
def extract_command(self, text: str) -> CommandObject:
|
||||
@classmethod
|
||||
def extract_command(cls, text: str) -> CommandObject:
|
||||
# First step: separate command with arguments
|
||||
# "/command@mention arg1 arg2" -> "/command@mention", ["arg1 arg2"]
|
||||
try:
|
||||
full_command, *args = text.split(maxsplit=1)
|
||||
except ValueError:
|
||||
except ValueError as e:
|
||||
msg = "not enough values to unpack"
|
||||
raise CommandException(msg)
|
||||
raise CommandException(msg) from e
|
||||
|
||||
# Separate command into valuable parts
|
||||
# "/command@mention" -> "/", ("command", "@", "mention")
|
||||
|
|
@ -292,6 +293,6 @@ class CommandStart(Command):
|
|||
args = decode_payload(args)
|
||||
except UnicodeDecodeError as e:
|
||||
msg = f"Failed to decode Base64: {e}"
|
||||
raise CommandException(msg)
|
||||
raise CommandException(msg) from e
|
||||
return replace(command, args=args)
|
||||
return command
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class ObserverDecorator:
|
|||
handlers = getattr(target, "__aiogram_handler__", None)
|
||||
if not handlers:
|
||||
handlers = []
|
||||
setattr(target, "__aiogram_handler__", handlers)
|
||||
target.__aiogram_handler__ = handlers # type: ignore[union-attr]
|
||||
|
||||
handlers.append(
|
||||
HandlerContainer(
|
||||
|
|
@ -137,7 +137,7 @@ class ObserverDecorator:
|
|||
action = getattr(target, "__aiogram_action__", None)
|
||||
if action is None:
|
||||
action = defaultdict(dict)
|
||||
setattr(target, "__aiogram_action__", action)
|
||||
target.__aiogram_action__ = action # type: ignore[attr-defined]
|
||||
action[self.action][self.name] = CallableObject(target)
|
||||
|
||||
def __call__(self, target: CallbackType) -> CallbackType:
|
||||
|
|
@ -865,7 +865,7 @@ class SceneRegistry:
|
|||
return self._scenes[scene]
|
||||
except KeyError:
|
||||
msg = f"Scene {scene!r} is not registered"
|
||||
raise SceneException(msg)
|
||||
raise SceneException(msg) from None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Generator
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
ClassVar,
|
||||
Generator,
|
||||
Generic,
|
||||
TypeVar,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import List, Literal, Optional, Union
|
||||
from typing import Literal, Optional, Union
|
||||
|
||||
from .accepted_gift_types import AcceptedGiftTypes
|
||||
from .affiliate_info import AffiliateInfo
|
||||
|
|
@ -654,7 +654,7 @@ for _entity_name in __all__:
|
|||
continue
|
||||
_entity.model_rebuild(
|
||||
_types_namespace={
|
||||
"List": List,
|
||||
"List": list,
|
||||
"Optional": Optional,
|
||||
"Union": Union,
|
||||
"Literal": Literal,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import PlainSerializer
|
||||
from typing_extensions import Annotated
|
||||
|
||||
if sys.platform == "win32": # pragma: no cover
|
||||
|
||||
|
|
|
|||
|
|
@ -130,9 +130,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMessage(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -208,9 +208,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMessage(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -298,9 +298,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAnimation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAnimation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -391,9 +391,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAnimation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAnimation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -483,9 +483,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAudio
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAudio(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -571,9 +571,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAudio
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAudio(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -652,9 +652,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendContact
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendContact(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -727,9 +727,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendContact
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendContact(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -808,9 +808,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDocument
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDocument(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -889,9 +889,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDocument
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDocument(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -958,9 +958,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendGame
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendGame(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1018,9 +1018,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendGame
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendGame(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1122,9 +1122,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendInvoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendInvoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1245,9 +1245,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendInvoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendInvoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1342,9 +1342,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendLocation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendLocation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1423,9 +1423,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendLocation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendLocation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1492,9 +1492,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMediaGroup
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMediaGroup(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1552,9 +1552,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMediaGroup
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMediaGroup(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1628,9 +1628,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPhoto
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPhoto(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1709,9 +1709,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPhoto
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPhoto(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1804,9 +1804,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPoll
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPoll(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1903,9 +1903,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPoll
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPoll(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1982,9 +1982,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2048,9 +2048,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2118,9 +2118,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendSticker
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendSticker(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2187,9 +2187,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendSticker
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendSticker(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2270,9 +2270,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVenue
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVenue(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2357,9 +2357,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVenue
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVenue(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2456,9 +2456,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideo
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideo(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2558,9 +2558,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideo
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideo(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2644,9 +2644,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideoNote
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideoNote(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2719,9 +2719,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideoNote
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideoNote(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2798,9 +2798,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2876,9 +2876,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2954,9 +2954,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPaidMedia
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPaidMedia(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3031,9 +3031,9 @@ class InaccessibleMessage(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPaidMedia
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPaidMedia(
|
||||
chat_id=self.chat.id,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ from __future__ import annotations
|
|||
import io
|
||||
import os
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import AsyncGenerator
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, AsyncGenerator
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import aiofiles
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ class InputFile(ABC):
|
|||
self.chunk_size = chunk_size
|
||||
|
||||
@abstractmethod
|
||||
async def read(self, bot: "Bot") -> AsyncGenerator[bytes, None]: # pragma: no cover
|
||||
async def read(self, bot: Bot) -> AsyncGenerator[bytes, None]: # pragma: no cover
|
||||
yield b""
|
||||
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ class BufferedInputFile(InputFile):
|
|||
data = f.read()
|
||||
return cls(data, filename=filename, chunk_size=chunk_size)
|
||||
|
||||
async def read(self, bot: "Bot") -> AsyncGenerator[bytes, None]:
|
||||
async def read(self, bot: Bot) -> AsyncGenerator[bytes, None]:
|
||||
buffer = io.BytesIO(self.data)
|
||||
while chunk := buffer.read(self.chunk_size):
|
||||
yield chunk
|
||||
|
|
@ -99,7 +100,7 @@ class FSInputFile(InputFile):
|
|||
|
||||
self.path = path
|
||||
|
||||
async def read(self, bot: "Bot") -> AsyncGenerator[bytes, None]:
|
||||
async def read(self, bot: Bot) -> AsyncGenerator[bytes, None]:
|
||||
async with aiofiles.open(self.path, "rb") as f:
|
||||
while chunk := await f.read(self.chunk_size):
|
||||
yield chunk
|
||||
|
|
@ -135,7 +136,7 @@ class URLInputFile(InputFile):
|
|||
self.timeout = timeout
|
||||
self.bot = bot
|
||||
|
||||
async def read(self, bot: "Bot") -> AsyncGenerator[bytes, None]:
|
||||
async def read(self, bot: Bot) -> AsyncGenerator[bytes, None]:
|
||||
bot = self.bot or bot
|
||||
stream = bot.session.stream_content(
|
||||
url=self.url,
|
||||
|
|
|
|||
|
|
@ -851,9 +851,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAnimation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAnimation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -944,9 +944,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAnimation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAnimation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1032,9 +1032,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAudio
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAudio(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1120,9 +1120,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendAudio
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendAudio(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1197,9 +1197,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendContact
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendContact(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1272,9 +1272,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendContact
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendContact(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1349,9 +1349,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDocument
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDocument(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1430,9 +1430,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDocument
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDocument(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1495,9 +1495,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendGame
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendGame(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1555,9 +1555,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendGame
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendGame(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1657,9 +1657,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendInvoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendInvoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1783,9 +1783,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendInvoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendInvoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1877,9 +1877,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendLocation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendLocation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -1958,9 +1958,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendLocation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendLocation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2023,9 +2023,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMediaGroup
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMediaGroup(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2083,9 +2083,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMediaGroup
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMediaGroup(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2153,9 +2153,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMessage(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2231,9 +2231,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendMessage(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2309,9 +2309,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPhoto
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPhoto(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2390,9 +2390,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPhoto
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPhoto(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2481,9 +2481,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPoll
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPoll(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2580,9 +2580,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPoll
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPoll(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2655,9 +2655,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2721,9 +2721,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendDice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendDice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2787,9 +2787,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendSticker
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendSticker(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2856,9 +2856,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendSticker
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendSticker(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -2935,9 +2935,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVenue
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVenue(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3022,9 +3022,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVenue
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVenue(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3117,9 +3117,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideo
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideo(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3219,9 +3219,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideo
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideo(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3301,9 +3301,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideoNote
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideoNote(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3376,9 +3376,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVideoNote
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVideoNote(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3451,9 +3451,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3529,9 +3529,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendVoice
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendVoice(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3808,9 +3808,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import CopyMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return CopyMessage(
|
||||
from_chat_id=self.chat.id,
|
||||
|
|
@ -3872,9 +3872,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import EditMessageText
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return EditMessageText(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -3928,9 +3928,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import ForwardMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return ForwardMessage(
|
||||
from_chat_id=self.chat.id,
|
||||
|
|
@ -3975,9 +3975,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import EditMessageMedia
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return EditMessageMedia(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4016,9 +4016,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import EditMessageReplyMarkup
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return EditMessageReplyMarkup(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4055,9 +4055,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import EditMessageReplyMarkup
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return EditMessageReplyMarkup(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4107,9 +4107,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import EditMessageLiveLocation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return EditMessageLiveLocation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4153,9 +4153,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import StopMessageLiveLocation
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return StopMessageLiveLocation(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4201,9 +4201,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import EditMessageCaption
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return EditMessageCaption(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4261,9 +4261,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import DeleteMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return DeleteMessage(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4297,9 +4297,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import PinChatMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return PinChatMessage(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4332,9 +4332,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import UnpinChatMessage
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return UnpinChatMessage(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4353,7 +4353,7 @@ class Message(MaybeInaccessibleMessage):
|
|||
:param include_thread_id: if set, adds chat thread id to URL and returns like https://t.me/username/thread_id/message_id
|
||||
:return: string with full message URL
|
||||
"""
|
||||
if self.chat.type in ("private", "group"):
|
||||
if self.chat.type in {"private", "group"}:
|
||||
return None
|
||||
|
||||
chat_value = (
|
||||
|
|
@ -4397,9 +4397,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SetMessageReaction
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SetMessageReaction(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4461,9 +4461,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPaidMedia
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPaidMedia(
|
||||
chat_id=self.chat.id,
|
||||
|
|
@ -4536,9 +4536,9 @@ class Message(MaybeInaccessibleMessage):
|
|||
|
||||
from aiogram.methods import SendPaidMedia
|
||||
|
||||
assert (
|
||||
self.chat is not None
|
||||
), "This method can be used only if chat is present in the message."
|
||||
assert self.chat is not None, (
|
||||
"This method can be used only if chat is present in the message."
|
||||
)
|
||||
|
||||
return SendPaidMedia(
|
||||
chat_id=self.chat.id,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ if TYPE_CHECKING:
|
|||
from aiogram import Bot
|
||||
|
||||
BAD_PATTERN = re.compile(r"[^a-zA-Z0-9-_]")
|
||||
DEEPLINK_PAYLOAD_LENGTH = 64
|
||||
|
||||
|
||||
async def create_start_link(
|
||||
|
|
@ -145,8 +146,8 @@ def create_deep_link(
|
|||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(payload) > 64:
|
||||
msg = "Payload must be up to 64 characters long."
|
||||
if len(payload) > DEEPLINK_PAYLOAD_LENGTH:
|
||||
msg = f"Payload must be up to {DEEPLINK_PAYLOAD_LENGTH} characters long."
|
||||
raise ValueError(msg)
|
||||
|
||||
if not app_name:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class DataMixin:
|
|||
data: dict[str, Any] | None = getattr(self, "_data", None)
|
||||
if data is None:
|
||||
data = {}
|
||||
setattr(self, "_data", data)
|
||||
self._data = data
|
||||
return data
|
||||
|
||||
def __getitem__(self, key: str) -> Any:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue