mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Small changes in documentation
This commit is contained in:
parent
9f902ef232
commit
74db2c47e6
8 changed files with 88 additions and 52 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||
[](https://pypi.python.org/pypi/aiogram)
|
[](https://pypi.python.org/pypi/aiogram)
|
||||||
[](https://core.telegram.org/bots/api)
|
[](https://core.telegram.org/bots/api)
|
||||||
[](https://pypi.python.org/pypi/aiogram)
|
[](https://pypi.python.org/pypi/aiogram)
|
||||||
[](https://pypi.python.org/pypi/aiogram)
|
[](https://pypi.python.org/pypi/aiogram)
|
||||||
[](https://pypi.python.org/pypi/aiogram)
|
[](https://pypi.python.org/pypi/aiogram)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@ T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
class BaseMiddleware(ABC, Generic[T]):
|
class BaseMiddleware(ABC, Generic[T]):
|
||||||
|
"""
|
||||||
|
Generic middleware class
|
||||||
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def __call__(
|
async def __call__(
|
||||||
self,
|
self,
|
||||||
|
|
@ -12,4 +16,12 @@ class BaseMiddleware(ABC, Generic[T]):
|
||||||
event: T,
|
event: T,
|
||||||
data: Dict[str, Any],
|
data: Dict[str, Any],
|
||||||
) -> Any: # pragma: no cover
|
) -> Any: # pragma: no cover
|
||||||
|
"""
|
||||||
|
Execute middleware
|
||||||
|
|
||||||
|
:param handler: Wrapped handler in middlewares chain
|
||||||
|
:param event: Incoming event (Subclass of :class:`aiogram.types.base.TelegramObject`)
|
||||||
|
:param data: Contextual data. Will be mapped to handler arguments
|
||||||
|
:return: :class:`Any`
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,4 @@ Dispatcher is subclass of router and should be always is root router.
|
||||||
class_based_handlers/index
|
class_based_handlers/index
|
||||||
filters/index
|
filters/index
|
||||||
filters/magic_filters
|
filters/magic_filters
|
||||||
|
middlewares
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ aiogram
|
||||||
:target: https://pypi.python.org/pypi/aiogram
|
:target: https://pypi.python.org/pypi/aiogram
|
||||||
:alt: Supported python versions
|
:alt: Supported python versions
|
||||||
|
|
||||||
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-4.9-blue.svg?logo=telegram
|
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.2-blue.svg?logo=telegram
|
||||||
:target: https://core.telegram.org/bots/api
|
:target: https://core.telegram.org/bots/api
|
||||||
:alt: Telegram Bot API
|
:alt: Telegram Bot API
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,53 +12,31 @@ Using PIP
|
||||||
|
|
||||||
pip install -U aiogram
|
pip install -U aiogram
|
||||||
|
|
||||||
|
Using AUR
|
||||||
|
---------
|
||||||
|
|
||||||
Using poetry
|
*aiogram* 2.x is also available in Arch Linux Repository, so you can install this framework
|
||||||
------------
|
on any Arch-based distribution like Arch Linux, Antergos, Manjaro, etc.
|
||||||
|
|
||||||
|
To do this, just use pacman to install the *python-aiogram* package:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
poetry add aiogram
|
$ pacman -S python-aiogram
|
||||||
|
|
||||||
|
|
||||||
Using Pipenv
|
|
||||||
------------
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
pipenv install aiogram
|
|
||||||
|
|
||||||
Using poetry
|
|
||||||
------------
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
poetry add aiogram
|
|
||||||
|
|
||||||
Using Pacman
|
|
||||||
------------
|
|
||||||
*aiogram* is also available in Arch Linux Repository, so you can install this framework on any
|
|
||||||
Arch-based distribution like Arch Linux, Antergos, Manjaro, etc. To do this, just use pacman
|
|
||||||
to install the `python-aiogram <https://archlinux.org/packages/community/any/python-aiogram/>`_ package:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
pacman -S python-aiogram
|
|
||||||
|
|
||||||
Development build (3.x)
|
Development build (3.x)
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
From private PyPi index
|
From test PyPi index
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
On every push to the `dev-3.x` branch GitHub Actions build the package and publish
|
|
||||||
to the `2038.host <https://aiogram.2038.io/simple>`_ server with seems like official PyPi files structure.
|
|
||||||
That's mean you can always install latest (may be unstable) build via next command:
|
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
pip install --extra-index-url https://dev-docs.aiogram.dev/simple --pre aiogram
|
pip install -U --extra-index-url https://test.pypi.org/simple/ --pre aiogram
|
||||||
|
|
||||||
|
From GitHub
|
||||||
|
-----------
|
||||||
|
|
||||||
In this repository available only last success build. All previous builds is always removes
|
.. code-block:: bash
|
||||||
before uploading new one. Also before building this package all tests is also pass.
|
|
||||||
|
pip install https://github.com/aiogram/aiogram/archive/refs/heads/dev-3.x.zip
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import toml
|
||||||
BASE_PATTERN = r'({variable} = ")[a-z0-9.+]+(")'
|
BASE_PATTERN = r'({variable} = ")[a-z0-9.+]+(")'
|
||||||
PACKAGE_VERSION = re.compile(BASE_PATTERN.format(variable="__version__"))
|
PACKAGE_VERSION = re.compile(BASE_PATTERN.format(variable="__version__"))
|
||||||
API_VERSION = re.compile(BASE_PATTERN.format(variable="__api_version__"))
|
API_VERSION = re.compile(BASE_PATTERN.format(variable="__api_version__"))
|
||||||
|
API_VERSION_BADGE = re.compile(r"(API-)[\d.]+(-blue\.svg)")
|
||||||
|
|
||||||
STAGE_MAPPING = {
|
STAGE_MAPPING = {
|
||||||
"alpha": "a",
|
"alpha": "a",
|
||||||
|
|
@ -37,7 +38,8 @@ def get_telegram_api_version() -> str:
|
||||||
|
|
||||||
|
|
||||||
def replace_line(content: str, pattern: re.Pattern, new_value: str) -> str:
|
def replace_line(content: str, pattern: re.Pattern, new_value: str) -> str:
|
||||||
return pattern.sub(f"\\g<1>{new_value}\\g<2>", content)
|
result = pattern.sub(f"\\g<1>{new_value}\\g<2>", content)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def write_package_meta(package_version: str, api_version: str) -> None:
|
def write_package_meta(package_version: str, api_version: str) -> None:
|
||||||
|
|
@ -51,6 +53,22 @@ def write_package_meta(package_version: str, api_version: str) -> None:
|
||||||
path.write_text(content)
|
path.write_text(content)
|
||||||
|
|
||||||
|
|
||||||
|
def write_readme(package_version: str, api_version: str) -> None:
|
||||||
|
path = Path.cwd() / "README.md"
|
||||||
|
content = path.read_text()
|
||||||
|
content = replace_line(content, API_VERSION_BADGE, api_version)
|
||||||
|
print(f"Write {path}")
|
||||||
|
path.write_text(content)
|
||||||
|
|
||||||
|
|
||||||
|
def write_docs_index(package_version: str, api_version: str) -> None:
|
||||||
|
path = Path.cwd() / "docs2" / "index.rst"
|
||||||
|
content = path.read_text()
|
||||||
|
content = replace_line(content, API_VERSION_BADGE, api_version)
|
||||||
|
print(f"Write {path}")
|
||||||
|
path.write_text(content)
|
||||||
|
|
||||||
|
|
||||||
def write_docs_meta(package_version: str, api_version: str) -> None:
|
def write_docs_meta(package_version: str, api_version: str) -> None:
|
||||||
api_meta = Path.cwd() / "docs" / "_api_version.md"
|
api_meta = Path.cwd() / "docs" / "_api_version.md"
|
||||||
package_meta = Path.cwd() / "docs" / "_package_version.md"
|
package_meta = Path.cwd() / "docs" / "_package_version.md"
|
||||||
|
|
@ -69,6 +87,8 @@ def main():
|
||||||
print(f"Telegram Bot API version: {api_version}")
|
print(f"Telegram Bot API version: {api_version}")
|
||||||
write_package_meta(package_version=package_version, api_version=api_version)
|
write_package_meta(package_version=package_version, api_version=api_version)
|
||||||
write_docs_meta(package_version=package_version, api_version=api_version)
|
write_docs_meta(package_version=package_version, api_version=api_version)
|
||||||
|
write_readme(package_version=package_version, api_version=api_version)
|
||||||
|
write_docs_index(package_version=package_version, api_version=api_version)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import datetime
|
import datetime
|
||||||
from typing import Any, Dict, Type, Union, Optional
|
from typing import Any, Dict, Optional, Type, Union
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.methods import (
|
from aiogram.methods import (
|
||||||
|
CopyMessage,
|
||||||
SendAnimation,
|
SendAnimation,
|
||||||
SendAudio,
|
SendAudio,
|
||||||
SendContact,
|
SendContact,
|
||||||
|
|
@ -21,7 +22,6 @@ from aiogram.methods import (
|
||||||
SendVideo,
|
SendVideo,
|
||||||
SendVideoNote,
|
SendVideoNote,
|
||||||
SendVoice,
|
SendVoice,
|
||||||
CopyMessage,
|
|
||||||
TelegramMethod,
|
TelegramMethod,
|
||||||
)
|
)
|
||||||
from aiogram.types import (
|
from aiogram.types import (
|
||||||
|
|
@ -35,6 +35,7 @@ from aiogram.types import (
|
||||||
Game,
|
Game,
|
||||||
Invoice,
|
Invoice,
|
||||||
Location,
|
Location,
|
||||||
|
MessageAutoDeleteTimerChanged,
|
||||||
PassportData,
|
PassportData,
|
||||||
PhotoSize,
|
PhotoSize,
|
||||||
Poll,
|
Poll,
|
||||||
|
|
@ -46,10 +47,9 @@ from aiogram.types import (
|
||||||
Video,
|
Video,
|
||||||
VideoNote,
|
VideoNote,
|
||||||
Voice,
|
Voice,
|
||||||
MessageAutoDeleteTimerChanged,
|
|
||||||
VoiceChatStarted,
|
|
||||||
VoiceChatEnded,
|
VoiceChatEnded,
|
||||||
VoiceChatParticipantsInvited,
|
VoiceChatParticipantsInvited,
|
||||||
|
VoiceChatStarted,
|
||||||
)
|
)
|
||||||
from aiogram.types.message import ContentType, Message
|
from aiogram.types.message import ContentType, Message
|
||||||
|
|
||||||
|
|
@ -71,7 +71,11 @@ TEST_MESSAGE_ANIMATION = Message(
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
animation=Animation(
|
animation=Animation(
|
||||||
file_id="file id", file_unique_id="file id", width=42, height=42, duration=0,
|
file_id="file id",
|
||||||
|
file_unique_id="file id",
|
||||||
|
width=42,
|
||||||
|
height=42,
|
||||||
|
duration=0,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=Chat(id=42, type="private"),
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||||
|
|
@ -106,7 +110,11 @@ TEST_MESSAGE_STICKER = Message(
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
sticker=Sticker(
|
sticker=Sticker(
|
||||||
file_id="file id", file_unique_id="file id", width=42, height=42, is_animated=False,
|
file_id="file id",
|
||||||
|
file_unique_id="file id",
|
||||||
|
width=42,
|
||||||
|
height=42,
|
||||||
|
is_animated=False,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=Chat(id=42, type="private"),
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||||
|
|
@ -114,7 +122,13 @@ TEST_MESSAGE_STICKER = Message(
|
||||||
TEST_MESSAGE_VIDEO = Message(
|
TEST_MESSAGE_VIDEO = Message(
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
video=Video(file_id="file id", file_unique_id="file id", width=42, height=42, duration=0,),
|
video=Video(
|
||||||
|
file_id="file id",
|
||||||
|
file_unique_id="file id",
|
||||||
|
width=42,
|
||||||
|
height=42,
|
||||||
|
duration=0,
|
||||||
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=Chat(id=42, type="private"),
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||||
)
|
)
|
||||||
|
|
@ -264,7 +278,8 @@ TEST_MESSAGE_PASSPORT_DATA = Message(
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
passport_data=PassportData(
|
passport_data=PassportData(
|
||||||
data=[], credentials=EncryptedCredentials(data="test", hash="test", secret="test"),
|
data=[],
|
||||||
|
credentials=EncryptedCredentials(data="test", hash="test", secret="test"),
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=Chat(id=42, type="private"),
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||||
|
|
@ -275,7 +290,10 @@ TEST_MESSAGE_POLL = Message(
|
||||||
poll=Poll(
|
poll=Poll(
|
||||||
id="QA",
|
id="QA",
|
||||||
question="Q",
|
question="Q",
|
||||||
options=[PollOption(text="A", voter_count=0), PollOption(text="B", voter_count=0),],
|
options=[
|
||||||
|
PollOption(text="A", voter_count=0),
|
||||||
|
PollOption(text="B", voter_count=0),
|
||||||
|
],
|
||||||
is_closed=False,
|
is_closed=False,
|
||||||
is_anonymous=False,
|
is_anonymous=False,
|
||||||
type="quiz",
|
type="quiz",
|
||||||
|
|
@ -410,7 +428,12 @@ class TestMessage:
|
||||||
["sticker", dict(sticker="sticker"), SendSticker],
|
["sticker", dict(sticker="sticker"), SendSticker],
|
||||||
[
|
[
|
||||||
"venue",
|
"venue",
|
||||||
dict(latitude=0.42, longitude=0.42, title="title", address="address",),
|
dict(
|
||||||
|
latitude=0.42,
|
||||||
|
longitude=0.42,
|
||||||
|
title="title",
|
||||||
|
address="address",
|
||||||
|
),
|
||||||
SendVenue,
|
SendVenue,
|
||||||
],
|
],
|
||||||
["video", dict(video="video"), SendVideo],
|
["video", dict(video="video"), SendVideo],
|
||||||
|
|
@ -513,7 +536,9 @@ class TestMessage:
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_send_copy(
|
def test_send_copy(
|
||||||
self, message: Message, expected_method: Optional[Type[TelegramMethod]],
|
self,
|
||||||
|
message: Message,
|
||||||
|
expected_method: Optional[Type[TelegramMethod]],
|
||||||
):
|
):
|
||||||
if expected_method is None:
|
if expected_method is None:
|
||||||
with pytest.raises(TypeError, match="This type of message can't be copied."):
|
with pytest.raises(TypeError, match="This type of message can't be copied."):
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ from aiogram.methods import GetMe, GetUpdates, SendMessage
|
||||||
from aiogram.types import (
|
from aiogram.types import (
|
||||||
CallbackQuery,
|
CallbackQuery,
|
||||||
Chat,
|
Chat,
|
||||||
|
ChatMember,
|
||||||
|
ChatMemberUpdated,
|
||||||
ChosenInlineResult,
|
ChosenInlineResult,
|
||||||
InlineQuery,
|
InlineQuery,
|
||||||
Message,
|
Message,
|
||||||
|
|
@ -26,8 +28,6 @@ from aiogram.types import (
|
||||||
ShippingQuery,
|
ShippingQuery,
|
||||||
Update,
|
Update,
|
||||||
User,
|
User,
|
||||||
ChatMemberUpdated,
|
|
||||||
ChatMember,
|
|
||||||
)
|
)
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue