mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Adding new code-generator (Butcher) (#1069)
* Re-generate types * Re-generate methods (only attributes) * Added enums * Base init generator * Added butcher configs * Fixed tests, bump butcher * Added changelog * Added enum docs * Added templates for docs index * Re-generate bot class, remove deprecated methods
This commit is contained in:
parent
c7779abc50
commit
d034c1ba9f
387 changed files with 32036 additions and 3144 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import abc
|
||||
import datetime
|
||||
import json
|
||||
from enum import Enum
|
||||
from http import HTTPStatus
|
||||
from types import TracebackType
|
||||
from typing import TYPE_CHECKING, Any, AsyncGenerator, Callable, Final, Optional, Type, Union, cast
|
||||
|
|
@ -162,6 +163,8 @@ class BaseSession(abc.ABC):
|
|||
return str(round((now + value).timestamp()))
|
||||
if isinstance(value, datetime.datetime):
|
||||
return str(round(value.timestamp()))
|
||||
if isinstance(value, Enum):
|
||||
return self.prepare_value(value.value)
|
||||
else:
|
||||
return str(value)
|
||||
|
||||
|
|
|
|||
13
aiogram/enums/__init__.py
Normal file
13
aiogram/enums/__init__.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from .chat_type import ChatType
|
||||
from .content_type import ContentType
|
||||
from .dice_emoji import DiceEmoji
|
||||
from .topic_icon_color import TopicIconColor
|
||||
from .update_type import UpdateType
|
||||
|
||||
__all__ = (
|
||||
"ChatType",
|
||||
"ContentType",
|
||||
"DiceEmoji",
|
||||
"TopicIconColor",
|
||||
"UpdateType",
|
||||
)
|
||||
12
aiogram/enums/chat_type.py
Normal file
12
aiogram/enums/chat_type.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class ChatType(str, Enum):
|
||||
"""
|
||||
Type of chat
|
||||
"""
|
||||
|
||||
PRIVATE = "private"
|
||||
GROUP = "group"
|
||||
SUPERGROUP = "supergroup"
|
||||
CHANNEL = "channel"
|
||||
50
aiogram/enums/content_type.py
Normal file
50
aiogram/enums/content_type.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class ContentType(str, Enum):
|
||||
"""
|
||||
Message content type
|
||||
"""
|
||||
|
||||
UNKNOWN = "unknown"
|
||||
ANY = "any"
|
||||
TEXT = "text"
|
||||
ANIMATION = "animation"
|
||||
AUDIO = "audio"
|
||||
DOCUMENT = "document"
|
||||
PHOTO = "photo"
|
||||
STICKER = "sticker"
|
||||
VIDEO = "video"
|
||||
VIDEO_NOTE = "video_note"
|
||||
VOICE = "voice"
|
||||
CONTACT = "contact"
|
||||
DICE = "dice"
|
||||
GAME = "game"
|
||||
POLL = "poll"
|
||||
VENUE = "venue"
|
||||
LOCATION = "location"
|
||||
NEW_CHAT_MEMBERS = "new_chat_members"
|
||||
LEFT_CHAT_MEMBER = "left_chat_member"
|
||||
NEW_CHAT_TITLE = "new_chat_title"
|
||||
NEW_CHAT_PHOTO = "new_chat_photo"
|
||||
DELETE_CHAT_PHOTO = "delete_chat_photo"
|
||||
GROUP_CHAT_CREATED = "group_chat_created"
|
||||
SUPERGROUP_CHAT_CREATED = "supergroup_chat_created"
|
||||
CHANNEL_CHAT_CREATED = "channel_chat_created"
|
||||
MESSAGE_AUTO_DELETE_TIMER_CHANGED = "message_auto_delete_timer_changed"
|
||||
MIGRATE_TO_CHAT_ID = "migrate_to_chat_id"
|
||||
MIGRATE_FROM_CHAT_ID = "migrate_from_chat_id"
|
||||
PINNED_MESSAGE = "pinned_message"
|
||||
INVOICE = "invoice"
|
||||
SUCCESSFUL_PAYMENT = "successful_payment"
|
||||
CONNECTED_WEBSITE = "connected_website"
|
||||
PASSPORT_DATA = "passport_data"
|
||||
PROXIMITY_ALERT_TRIGGERED = "proximity_alert_triggered"
|
||||
FORUM_TOPIC_CREATED = "forum_topic_created"
|
||||
FORUM_TOPIC_CLOSED = "forum_topic_closed"
|
||||
FORUM_TOPIC_REOPENED = "forum_topic_reopened"
|
||||
VIDEO_CHAT_SCHEDULED = "video_chat_scheduled"
|
||||
VIDEO_CHAT_STARTED = "video_chat_started"
|
||||
VIDEO_CHAT_ENDED = "video_chat_ended"
|
||||
VIDEO_CHAT_PARTICIPANTS_INVITED = "video_chat_participants_invited"
|
||||
WEB_APP_DATA = "web_app_data"
|
||||
14
aiogram/enums/dice_emoji.py
Normal file
14
aiogram/enums/dice_emoji.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class DiceEmoji(str, Enum):
|
||||
"""
|
||||
Emoji on which the dice throw animation is based
|
||||
"""
|
||||
|
||||
DICE = "🎲"
|
||||
DART = "🎯"
|
||||
BASKETBALL = "🏀"
|
||||
FOOTBALL = "⚽"
|
||||
SLOT_MACHINE = "🎰"
|
||||
BOWLING = "🎳"
|
||||
16
aiogram/enums/topic_icon_color.py
Normal file
16
aiogram/enums/topic_icon_color.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class TopicIconColor(int, Enum):
|
||||
"""
|
||||
Color of the topic icon in RGB format.
|
||||
|
||||
Source: https://github.com/telegramdesktop/tdesktop/blob/991fe491c5ae62705d77aa8fdd44a79caf639c45/Telegram/SourceFiles/data/data_forum_topic.cpp#L51-L56
|
||||
"""
|
||||
|
||||
BLUE = 0x6FB9F0
|
||||
YELLOW = 0xFFD67E
|
||||
VIOLET = 0xCB86DB
|
||||
GREEN = 0x8EEE98
|
||||
ROSE = 0xFF93B2
|
||||
RED = 0xFB6F5F
|
||||
22
aiogram/enums/update_type.py
Normal file
22
aiogram/enums/update_type.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class UpdateType(str, Enum):
|
||||
"""
|
||||
Known update types
|
||||
"""
|
||||
|
||||
MESSAGE = "message"
|
||||
EDITED_MESSAGE = "edited_message"
|
||||
CHANNEL_POST = "channel_post"
|
||||
EDITED_CHANNEL_POST = "edited_channel_post"
|
||||
INLINE_QUERY = "inline_query"
|
||||
CHOSEN_INLINE_RESULT = "chosen_inline_result"
|
||||
CALLBACK_QUERY = "callback_query"
|
||||
SHIPPING_QUERY = "shipping_query"
|
||||
PRE_CHECKOUT_QUERY = "pre_checkout_query"
|
||||
POLL = "poll"
|
||||
POLL_ANSWER = "poll_answer"
|
||||
MY_CHAT_MEMBER = "my_chat_member"
|
||||
CHAT_MEMBER = "chat_member"
|
||||
CHAT_JOIN_REQUEST = "chat_join_request"
|
||||
|
|
@ -36,7 +36,6 @@ from .get_chat import GetChat
|
|||
from .get_chat_administrators import GetChatAdministrators
|
||||
from .get_chat_member import GetChatMember
|
||||
from .get_chat_member_count import GetChatMemberCount
|
||||
from .get_chat_members_count import GetChatMembersCount
|
||||
from .get_chat_menu_button import GetChatMenuButton
|
||||
from .get_custom_emoji_stickers import GetCustomEmojiStickers
|
||||
from .get_file import GetFile
|
||||
|
|
@ -49,7 +48,6 @@ from .get_sticker_set import GetStickerSet
|
|||
from .get_updates import GetUpdates
|
||||
from .get_user_profile_photos import GetUserProfilePhotos
|
||||
from .get_webhook_info import GetWebhookInfo
|
||||
from .kick_chat_member import KickChatMember
|
||||
from .leave_chat import LeaveChat
|
||||
from .log_out import LogOut
|
||||
from .pin_chat_message import PinChatMessage
|
||||
|
|
@ -131,7 +129,6 @@ __all__ = (
|
|||
"GetUserProfilePhotos",
|
||||
"GetFile",
|
||||
"BanChatMember",
|
||||
"KickChatMember",
|
||||
"UnbanChatMember",
|
||||
"RestrictChatMember",
|
||||
"PromoteChatMember",
|
||||
|
|
@ -156,7 +153,6 @@ __all__ = (
|
|||
"GetChat",
|
||||
"GetChatAdministrators",
|
||||
"GetChatMemberCount",
|
||||
"GetChatMembersCount",
|
||||
"GetChatMember",
|
||||
"SetChatStickerSet",
|
||||
"DeleteChatStickerSet",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class CreateForumTopic(TelegramMethod[ForumTopic]):
|
|||
name: str
|
||||
"""Topic name, 1-128 characters"""
|
||||
icon_color: Optional[int] = None
|
||||
"""Color of the topic icon in RGB format. Currently, must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F"""
|
||||
"""Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)"""
|
||||
icon_custom_emoji_id: Optional[str] = None
|
||||
"""Unique identifier of the custom emoji shown as the topic icon. Use :class:`aiogram.methods.get_forum_topic_icon_stickers.GetForumTopicIconStickers` to get all allowed custom emoji identifiers."""
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class EditForumTopic(TelegramMethod[bool]):
|
|||
name: str
|
||||
"""New topic name, 1-128 characters"""
|
||||
icon_custom_emoji_id: str
|
||||
"""New unique identifier of the custom emoji shown as the topic icon. Use :class:`aiogram.methods.get_forum_topic_icon_stickers.GetForumTopicIconStickers` to get all allowed custom emoji identifiers"""
|
||||
"""New unique identifier of the custom emoji shown as the topic icon. Use :class:`aiogram.methods.get_forum_topic_icon_stickers.GetForumTopicIconStickers` to get all allowed custom emoji identifiers."""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Union
|
||||
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class GetChatMembersCount(TelegramMethod[int]):
|
||||
"""
|
||||
.. warning:
|
||||
|
||||
Renamed from :code:`getChatMembersCount` in 5.3 bot API version and can be removed in near future
|
||||
|
||||
Use this method to get the number of members in a chat. Returns *Int* on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getchatmembercount
|
||||
"""
|
||||
|
||||
__returning__ = int
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="getChatMembersCount", data=data)
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
||||
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class KickChatMember(TelegramMethod[bool]):
|
||||
"""
|
||||
.. warning:
|
||||
|
||||
Renamed from :code:`kickChatMember` in 5.3 bot API version and can be removed in near future
|
||||
|
||||
Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless `unbanned <https://core.telegram.org/bots/api#unbanchatmember>`_ first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#banchatmember
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target group or username of the target supergroup or channel (in the format :code:`@channelusername`)"""
|
||||
user_id: int
|
||||
"""Unique identifier of the target user"""
|
||||
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
|
||||
"""Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only."""
|
||||
revoke_messages: Optional[bool] = None
|
||||
"""Pass :code:`True` to delete all messages from the chat for the user that is being removed. If :code:`False`, the user will be able to see messages in the group that were sent before the user was removed. Always :code:`True` for supergroups and channels."""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="kickChatMember", data=data)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ class ChatInviteLink(TelegramObject):
|
|||
""":code:`True`, if the link is revoked"""
|
||||
name: Optional[str] = None
|
||||
"""*Optional*. Invite link name"""
|
||||
expire_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
|
||||
expire_date: Optional[datetime.datetime] = None
|
||||
"""*Optional*. Point in time (Unix timestamp) when the link will expire or has been expired"""
|
||||
member_limit: Optional[int] = None
|
||||
"""*Optional*. The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999"""
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ class ChatMember(TelegramObject):
|
|||
"""
|
||||
|
||||
status: str
|
||||
"""..."""
|
||||
"""The member's status in the chat"""
|
||||
user: Optional[User] = None
|
||||
"""*Optional*. Information about the user"""
|
||||
is_anonymous: Optional[bool] = None
|
||||
|
|
@ -67,5 +67,5 @@ class ChatMember(TelegramObject):
|
|||
"""*Optional*. :code:`True`, if the user is allowed to send animations, games, stickers and use inline bots"""
|
||||
can_add_web_page_previews: Optional[bool] = None
|
||||
"""*Optional*. :code:`True`, if the user is allowed to add web page previews to their messages"""
|
||||
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
|
||||
until_date: Optional[datetime.datetime] = None
|
||||
"""*Optional*. Date when restrictions will be lifted for this user; unix time. If 0, then the user is restricted forever"""
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Union
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
|
|
@ -22,5 +22,5 @@ class ChatMemberBanned(ChatMember):
|
|||
"""The member's status in the chat, always 'kicked'"""
|
||||
user: User
|
||||
"""Information about the user"""
|
||||
until_date: Union[datetime.datetime, datetime.timedelta, int]
|
||||
until_date: datetime.datetime
|
||||
"""Date when restrictions will be lifted for this user; unix time. If 0, then the user is banned forever"""
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Union
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
|
|
@ -42,5 +42,5 @@ class ChatMemberRestricted(ChatMember):
|
|||
""":code:`True`, if the user is allowed to send animations, games, stickers and use inline bots"""
|
||||
can_add_web_page_previews: bool
|
||||
""":code:`True`, if the user is allowed to add web page previews to their messages"""
|
||||
until_date: Union[datetime.datetime, datetime.timedelta, int]
|
||||
until_date: datetime.datetime
|
||||
"""Date when restrictions will be lifted for this user; unix time. If 0, then the user is restricted forever"""
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
|
||||
class InputMessageContent(TelegramObject):
|
||||
class InputMessageContent(MutableTelegramObject):
|
||||
"""
|
||||
This object represents the content of a message to be sent as a result of an inline query. Telegram clients currently support the following 5 types:
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
from .base import MutableTelegramObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .web_app_info import WebAppInfo
|
||||
|
||||
|
||||
class MenuButton(TelegramObject):
|
||||
class MenuButton(MutableTelegramObject):
|
||||
"""
|
||||
This object describes the bot's menu button in a private chat. It should be one of
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ class MenuButton(TelegramObject):
|
|||
"""
|
||||
|
||||
type: str
|
||||
"""..."""
|
||||
"""Type of the button"""
|
||||
text: Optional[str] = None
|
||||
"""*Optional*. Text on the button"""
|
||||
web_app: Optional[WebAppInfo] = None
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ class MessageEntity(MutableTelegramObject):
|
|||
type: str
|
||||
"""Type of the entity. Currently, can be 'mention' (:code:`@username`), 'hashtag' (:code:`#hashtag`), 'cashtag' (:code:`$USD`), 'bot_command' (:code:`/start@jobs_bot`), 'url' (:code:`https://telegram.org`), 'email' (:code:`do-not-reply@telegram.org`), 'phone_number' (:code:`+1-212-555-0123`), 'bold' (**bold text**), 'italic' (*italic text*), 'underline' (underlined text), 'strikethrough' (strikethrough text), 'spoiler' (spoiler message), 'code' (monowidth string), 'pre' (monowidth block), 'text_link' (for clickable text URLs), 'text_mention' (for users `without usernames <https://telegram.org/blog/edit#new-mentions>`_), 'custom_emoji' (for inline custom emoji stickers)"""
|
||||
offset: int
|
||||
"""Offset in UTF-16 code units to the start of the entity"""
|
||||
"""Offset in `UTF-16 code units <https://core.telegram.org/api/entities#entity-length>`_ to the start of the entity"""
|
||||
length: int
|
||||
"""Length of the entity in UTF-16 code units"""
|
||||
"""Length of the entity in `UTF-16 code units <https://core.telegram.org/api/entities#entity-length>`_"""
|
||||
url: Optional[str] = None
|
||||
"""*Optional*. For 'text_link' only, URL that will be opened after user taps on the text"""
|
||||
user: Optional[User] = None
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, List, Optional, Union
|
||||
from typing import TYPE_CHECKING, List, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
|
|
@ -41,5 +41,5 @@ class Poll(TelegramObject):
|
|||
"""*Optional*. Special entities like usernames, URLs, bot commands, etc. that appear in the *explanation*"""
|
||||
open_period: Optional[int] = None
|
||||
"""*Optional*. Amount of time in seconds the poll will be active after creation"""
|
||||
close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
|
||||
close_date: Optional[datetime.datetime] = None
|
||||
"""*Optional*. Point in time (Unix timestamp) when the poll will be automatically closed"""
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
|||
|
||||
class ReplyKeyboardMarkup(MutableTelegramObject):
|
||||
"""
|
||||
This object represents a `custom keyboard <https://core.telegram.org/bots#keyboards>`_ with reply options (see `Introduction to bots <https://core.telegram.org/bots#keyboards>`_ for details and examples).
|
||||
This object represents a `custom keyboard <https://core.telegram.org/bots/features#keyboards>`_ with reply options (see `Introduction to bots <https://core.telegram.org/bots/features#keyboards>`_ for details and examples).
|
||||
|
||||
Source: https://core.telegram.org/bots/api#replykeyboardmarkup
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue