Add missing shortcuts, new enums, reworked old stuff (#1070)

* Render shortcuts

* Render docs

* Added enumerations

* Added docs

* Use enums, removed Helper

* Bump butcher

* Added InputMediaType enum

* Added MaskPositionPoint, InlineQueryResultType enums

* Update texts

* Added StickerType enum

* Cover tests

* Update docs

* Fixed imports

* Re-enabled all pre-commit hooks
This commit is contained in:
Alex Root Junior 2022-12-04 03:05:49 +02:00 committed by GitHub
parent 3438d2446d
commit 3ea73fbbbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
370 changed files with 19735 additions and 8380 deletions

View file

@ -0,0 +1,16 @@
name: BotCommandScopeType
description: |
This object represents the scope to which bot commands are applied.
Source: https://core.telegram.org/bots/api#botcommandscope
multi_parse:
attribute: type
regexp: "must be ([a-z_]+)"
entities:
- BotCommandScopeDefault
- BotCommandScopeAllPrivateChats
- BotCommandScopeAllGroupChats
- BotCommandScopeAllChatAdministrators
- BotCommandScopeChat
- BotCommandScopeChatAdministrators
- BotCommandScopeChatMember

View file

@ -0,0 +1,22 @@
name: ChatAction
description: |
This object represents bot actions.
Choose one, depending on what the user is about to receive:
- typing for text messages,
- upload_photo for photos,
- record_video or upload_video for videos,
- record_voice or upload_voice for voice notes,
- upload_document for general files,
- choose_sticker for stickers,
- find_location for location data,
- record_video_note or upload_video_note for video notes.
Source: https://core.telegram.org/bots/api#sendchataction
parse:
format: rst
entity: sendChatAction
category: methods
attribute: action
regexp: '\*([a-z_]+)\*'

View file

@ -0,0 +1,15 @@
name: ChatMemberStatus
description: |
This object represents chat member status.
Source: https://core.telegram.org/bots/api#chatmember
multi_parse:
attribute: status
regexp: "'([a-z_]+)'"
entities:
- ChatMemberOwner
- ChatMemberAdministrator
- ChatMemberMember
- ChatMemberRestricted
- ChatMemberLeft
- ChatMemberBanned

View file

@ -0,0 +1,11 @@
name: ChatType
description: |
This object represents a chat type
Source: https://core.telegram.org/bots/api#chat
parse:
entity: Chat
attribute: type
regexp: "'([a-z]+)'"
static:
SENDER: sender

View file

@ -1,5 +1,6 @@
name: ContentType name: ContentType
description: "Message content type" description:
This object represents a type of content in message
static: static:
UNKNOWN: unknown UNKNOWN: unknown
ANY: any ANY: any

View file

@ -1,5 +1,8 @@
name: DiceEmoji name: DiceEmoji
description: "Emoji on which the dice throw animation is based" description: |
Emoji on which the dice throw animation is based
Source: https://core.telegram.org/bots/api#dice
static: static:
DICE: 🎲 DICE: 🎲
DART: 🎯 DART: 🎯

View file

@ -0,0 +1,29 @@
name: InlineQueryResultType
description: |
The part of the face relative to which the mask should be placed.
Source: https://core.telegram.org/bots/api#maskposition
multi_parse:
attribute: type
regexp: "must be ([a-z_]+)"
entities:
- InlineQueryResultCachedAudio
- InlineQueryResultCachedDocument
- InlineQueryResultCachedGif
- InlineQueryResultCachedMpeg4Gif
- InlineQueryResultCachedPhoto
- InlineQueryResultCachedSticker
- InlineQueryResultCachedVideo
- InlineQueryResultCachedVoice
- InlineQueryResultArticle
- InlineQueryResultAudio
- InlineQueryResultContact
- InlineQueryResultGame
- InlineQueryResultDocument
- InlineQueryResultGif
- InlineQueryResultLocation
- InlineQueryResultMpeg4Gif
- InlineQueryResultPhoto
- InlineQueryResultVenue
- InlineQueryResultVideo
- InlineQueryResultVoice

View file

@ -0,0 +1,14 @@
name: InputMediaType
description: |
This object represents input media type
Source: https://core.telegram.org/bots/api#inputmedia
multi_parse:
attribute: type
regexp: 'must be ([a-z_]+)'
entities:
- InputMediaAnimation
- InputMediaAudio
- InputMediaDocument
- InputMediaPhoto
- InputMediaVideo

View file

@ -0,0 +1,9 @@
name: MaskPositionPoint
description: |
The part of the face relative to which the mask should be placed.
Source: https://core.telegram.org/bots/api#maskposition
parse:
entity: MaskPosition
attribute: point
regexp: "'([a-z_]+)'"

View file

@ -0,0 +1,13 @@
name: MenuButtonType
description: |
This object represents an type of Menu button
Source: https://core.telegram.org/bots/api#menubuttondefault
multi_parse:
format: rst
attribute: type
regexp: '\*([a-z_]+)\*'
entities:
- MenuButtonDefault
- MenuButtonCommands
- MenuButtonWebApp

View file

@ -0,0 +1,10 @@
name: MessageEntityType
description: |
This object represents type of message entity
Source: https://core.telegram.org/bots/api#messageentity
parse:
entity: MessageEntity
category: types
attribute: type
regexp: "'([a-z_]+)'"

View file

@ -0,0 +1,9 @@
name: ParseMode
description: |
Formatting options
Source: https://core.telegram.org/bots/api#formatting-options
static:
MARKDOWN_V2: MarkdownV2
MARKDOWN: Markdown
HTML: HTML

View file

@ -0,0 +1,9 @@
name: PollType
description: |
This object represents poll type
Source: https://core.telegram.org/bots/api#poll
parse:
entity: Poll
attribute: type
regexp: "'([a-z]+)'"

View file

@ -0,0 +1,9 @@
name: StickerType
description: |
The part of the face relative to which the mask should be placed.
Source: https://core.telegram.org/bots/api#maskposition
parse:
entity: Sticker
attribute: type
regexp: "'([a-z_]+)'"

View file

@ -0,0 +1,9 @@
name: UpdateType
description: |
This object represents the complete list of allowed update types
Source: https://core.telegram.org/bots/api#update
extract:
entity: Update
exclude:
- update_id

View file

@ -1,6 +0,0 @@
name: ChatType
description: "Type of chat"
parse:
entity: Chat
attribute: type
regexp: "'([a-z]+)'"

View file

@ -1,6 +0,0 @@
name: UpdateType
description: Known update types
extract:
entity: Update
exclude:
- update_id

View file

@ -1,5 +1,5 @@
##### #####
Types Enums
##### #####
Here is list of all available enums: Here is list of all available enums:

View file

@ -47,7 +47,7 @@ As reply into Webhook in handler
{% if aliased %} {% if aliased %}
As shortcut from received object As shortcut from received object
------------------- --------------------------------
{% for alias in aliased %} {% for alias in aliased %}
- :meth:`aiogram.types.{{ alias.type|pythonize_name }}.{{ alias.type|pythonize_class_name }}.{{ alias.name }}` - :meth:`aiogram.types.{{ alias.type|pythonize_name }}.{{ alias.type|pythonize_class_name }}.{{ alias.name }}`
{%- endfor %} {%- endfor %}

View file

@ -0,0 +1,4 @@
answer:
method: answerCallbackQuery
fill:
callback_query_id: self.id

View file

@ -1,108 +1,108 @@
#ban_sender_chat: ban_sender_chat:
# method: banChatSenderChat method: banChatSenderChat
# fill: &self fill: &self
# chat_id: self.id chat_id: self.id
#
#unban_sender_chat: unban_sender_chat:
# method: unbanChatSenderChat method: unbanChatSenderChat
# fill: *self fill: *self
#
#get_administrators: get_administrators:
# method: getChatAdministrators method: getChatAdministrators
# fill: *self fill: *self
#
#delete_message: delete_message:
# method: deleteMessage method: deleteMessage
# fill: *self fill: *self
#
#revoke_invite_link: revoke_invite_link:
# method: revokeChatInviteLink method: revokeChatInviteLink
# fill: *self fill: *self
#
#edit_invite_link: edit_invite_link:
# method: editChatInviteLink method: editChatInviteLink
# fill: *self fill: *self
#
#create_invite_link: create_invite_link:
# method: createChatInviteLink method: createChatInviteLink
# fill: *self fill: *self
#
#export_invite_link: export_invite_link:
# method: exportChatInviteLink method: exportChatInviteLink
# fill: *self fill: *self
#
#do: do:
# method: sendChatAction method: sendChatAction
# fill: *self fill: *self
#
#delete_sticker_set: delete_sticker_set:
# method: deleteChatStickerSet method: deleteChatStickerSet
# fill: *self fill: *self
#
#set_sticker_set: set_sticker_set:
# method: setChatStickerSet method: setChatStickerSet
# fill: *self fill: *self
#
#get_member: get_member:
# method: getChatMember method: getChatMember
# fill: *self fill: *self
#
#get_member_count: get_member_count:
# method: getChatMemberCount method: getChatMemberCount
# fill: *self fill: *self
#
#leave: leave:
# method: leaveChat method: leaveChat
# fill: *self fill: *self
#
#unpin_all_messages: unpin_all_messages:
# method: unpinAllChatMessages method: unpinAllChatMessages
# fill: *self fill: *self
#
#unpin_message: unpin_message:
# method: unpinChatMessage method: unpinChatMessage
# fill: *self fill: *self
#
#pin_message: pin_message:
# method: pinChatMessage method: pinChatMessage
# fill: *self fill: *self
#
#set_administrator_custom_title: set_administrator_custom_title:
# method: setChatAdministratorCustomTitle method: setChatAdministratorCustomTitle
# fill: *self fill: *self
#
#set_permissions: set_permissions:
# method: setChatPermissions method: setChatPermissions
# fill: *self fill: *self
#
#promote: promote:
# method: promoteChatMember method: promoteChatMember
# fill: *self fill: *self
#
#restrict: restrict:
# method: restrictChatMember method: restrictChatMember
# fill: *self fill: *self
#
#unban: unban:
# method: unbanChatMember method: unbanChatMember
# fill: *self fill: *self
#
#ban: ban:
# method: banChatMember method: banChatMember
# fill: *self fill: *self
#
#set_description: set_description:
# method: setChatDescription method: setChatDescription
# fill: *self fill: *self
#
#set_title: set_title:
# method: setChatTitle method: setChatTitle
# fill: *self fill: *self
#
#delete_photo: delete_photo:
# method: deleteChatPhoto method: deleteChatPhoto
# fill: *self fill: *self
#
#set_photo: set_photo:
# method: setChatPhoto method: setChatPhoto
# fill: *self fill: *self

View file

@ -0,0 +1,8 @@
approve:
method: approveChatJoinRequest
fill: &request-target
chat_id: self.chat.id
user_id: self.from_user.id
decline:
method: declineChatJoinRequest
fill: *request-target

View file

@ -0,0 +1,2 @@
bases:
- _ErrorEvent

View file

@ -0,0 +1,4 @@
answer:
method: answerInlineQuery
fill:
inline_query_id: self.id

View file

@ -1,139 +1,189 @@
#answer: answer:
# method: sendMessage method: sendMessage
# fill: &fill-answer fill: &fill-answer
# chat_id: self.chat.id chat_id: self.chat.id
# message_thread_id: self.message_thread_id if self.is_topic_message else None message_thread_id: self.message_thread_id if self.is_topic_message else None
#
#reply: reply:
# method: sendMessage method: sendMessage
# fill: &fill-reply fill: &fill-reply
# <<: *fill-answer <<: *fill-answer
# reply_to_message_id: self.message_id reply_to_message_id: self.message_id
#
#answer_animation: answer_animation:
# method: sendAnimation method: sendAnimation
# fill: *fill-answer fill: *fill-answer
#
#reply_animation: reply_animation:
# method: sendAnimation method: sendAnimation
# fill: *fill-reply fill: *fill-reply
#
#answer_audio: answer_audio:
# method: sendAudio method: sendAudio
# fill: *fill-answer fill: *fill-answer
#
#reply_audio: reply_audio:
# method: sendAudio method: sendAudio
# fill: *fill-reply fill: *fill-reply
#
#answer_contact: answer_contact:
# method: sendContact method: sendContact
# fill: *fill-answer fill: *fill-answer
#
#reply_contact: reply_contact:
# method: sendContact method: sendContact
# fill: *fill-reply fill: *fill-reply
#
#answer_document: answer_document:
# method: sendDocument method: sendDocument
# fill: *fill-answer fill: *fill-answer
#
#reply_document: reply_document:
# method: sendDocument method: sendDocument
# fill: *fill-reply fill: *fill-reply
#
#answer_game: answer_game:
# method: sendGame method: sendGame
# fill: *fill-answer fill: *fill-answer
#
#reply_game: reply_game:
# method: sendGame method: sendGame
# fill: *fill-reply fill: *fill-reply
#
#answer_invoice: answer_invoice:
# method: sendInvoice method: sendInvoice
# fill: *fill-answer fill: *fill-answer
#
#reply_invoice: reply_invoice:
# method: sendInvoice method: sendInvoice
# fill: *fill-reply fill: *fill-reply
#
#answer_location: answer_location:
# method: sendLocation method: sendLocation
# fill: *fill-answer fill: *fill-answer
#
#reply_location: reply_location:
# method: sendLocation method: sendLocation
# fill: *fill-reply fill: *fill-reply
#
#answer_media_group: answer_media_group:
# method: sendMediaGroup method: sendMediaGroup
# fill: *fill-answer fill: *fill-answer
#
#reply_media_group: reply_media_group:
# method: sendMediaGroup method: sendMediaGroup
# fill: *fill-reply fill: *fill-reply
#
#answer_photo: answer_photo:
# method: sendPhoto method: sendPhoto
# fill: *fill-answer fill: *fill-answer
#
#reply_photo: reply_photo:
# method: sendPhoto method: sendPhoto
# fill: *fill-reply fill: *fill-reply
#
#answer_poll: answer_poll:
# method: sendPoll method: sendPoll
# fill: *fill-answer fill: *fill-answer
#
#reply_poll: reply_poll:
# method: sendPoll method: sendPoll
# fill: *fill-reply fill: *fill-reply
#
#answer_dice: answer_dice:
# method: sendDice method: sendDice
# fill: *fill-answer fill: *fill-answer
#
#reply_dice: reply_dice:
# method: sendDice method: sendDice
# fill: *fill-reply fill: *fill-reply
#
#answer_sticker: answer_sticker:
# method: sendSticker method: sendSticker
# fill: *fill-answer fill: *fill-answer
#
#reply_sticker: reply_sticker:
# method: sendSticker method: sendSticker
# fill: *fill-reply fill: *fill-reply
#
#answer_venue: answer_venue:
# method: sendVenue method: sendVenue
# fill: *fill-answer fill: *fill-answer
#
#reply_venue: reply_venue:
# method: sendVenue method: sendVenue
# fill: *fill-reply fill: *fill-reply
#
#answer_video: answer_video:
# method: sendVideo method: sendVideo
# fill: *fill-answer fill: *fill-answer
#
#reply_video: reply_video:
# method: sendVideo method: sendVideo
# fill: *fill-reply fill: *fill-reply
#
#answer_video_note: answer_video_note:
# method: sendVideoNote method: sendVideoNote
# fill: *fill-answer fill: *fill-answer
#
#reply_video_note: reply_video_note:
# method: sendVideoNote method: sendVideoNote
# fill: *fill-reply fill: *fill-reply
#
#answer_voice: answer_voice:
# method: sendVoice method: sendVoice
# fill: *fill-answer fill: *fill-answer
#
#reply_voice: reply_voice:
# method: sendVoice method: sendVoice
# fill: *fill-reply fill: *fill-reply
copy_to:
method: copyMessage
fill:
from_chat_id: self.chat.id
message_id: self.message_id
edit_text:
method: editMessageText
fill: &message-target
chat_id: self.chat.id
message_id: self.message_id
forward:
method: forwardMessage
fill:
from_chat_id: self.chat.id
message_id: self.message_id
edit_media:
method: editMessageMedia
fill: *message-target
edit_reply_markup:
method: editMessageReplyMarkup
fill: *message-target
edit_live_location:
method: editMessageLiveLocation
fill: *message-target
stop_live_location:
method: stopMessageLiveLocation
fill: *message-target
edit_caption:
method: editMessageCaption
fill: *message-target
delete:
method: deleteMessage
fill: *message-target
pin:
method: pinChatMessage
fill: *message-target
unpin:
method: unpinChatMessage
fill: *message-target

View file

@ -0,0 +1,8 @@
set_position_in_set:
method: setStickerPositionInSet
fill: &set-target
sticker: self.file_id
delete_from_set:
method: deleteStickerFromSet
fill: *set-target

View file

@ -0,0 +1,4 @@
get_profile_photos:
method: getUserProfilePhotos
fill:
user_id: self.id

52
CHANGES/952.feature.rst Normal file
View file

@ -0,0 +1,52 @@
Added missing shortcuts, new enums, reworked old stuff
**Breaking**
All previously added enums is re-generated in new place - `aiogram.enums` instead of `aiogram.types`
**Added enums:** :class:`aiogram.enums.bot_command_scope_type.BotCommandScopeType`,
:class:`aiogram.enums.chat_action.ChatActions`,
:class:`aiogram.enums.chat_member_status.ChatMemberStatus`,
:class:`aiogram.enums.chat_type.ChatType`,
:class:`aiogram.enums.content_type.ContentType`,
:class:`aiogram.enums.dice_emoji.DiceEmoji`,
:class:`aiogram.enums.inline_query_result_type.InlineQueryResultType`,
:class:`aiogram.enums.input_media_type.InputMediaType`,
:class:`aiogram.enums.mask_position_point.MaskPositionPoint`,
:class:`aiogram.enums.menu_button_type.MenuButtonType`,
:class:`aiogram.enums.message_entity_type.MessageEntityType`,
:class:`aiogram.enums.parse_mode.ParseMode`,
:class:`aiogram.enums.poll_type.PollType`,
:class:`aiogram.enums.sticker_type.StickerType`,
:class:`aiogram.enums.topic_icon_color.TopicIconColor`,
:class:`aiogram.enums.update_type.UpdateType`,
**Added shortcuts**:
- *Chat* :meth:`aiogram.types.chat.Chat.get_administrators`,
:meth:`aiogram.types.chat.Chat.delete_message`,
:meth:`aiogram.types.chat.Chat.revoke_invite_link`,
:meth:`aiogram.types.chat.Chat.edit_invite_link`,
:meth:`aiogram.types.chat.Chat.create_invite_link`,
:meth:`aiogram.types.chat.Chat.export_invite_link`,
:meth:`aiogram.types.chat.Chat.do`,
:meth:`aiogram.types.chat.Chat.delete_sticker_set`,
:meth:`aiogram.types.chat.Chat.set_sticker_set`,
:meth:`aiogram.types.chat.Chat.get_member`,
:meth:`aiogram.types.chat.Chat.get_member_count`,
:meth:`aiogram.types.chat.Chat.leave`,
:meth:`aiogram.types.chat.Chat.unpin_all_messages`,
:meth:`aiogram.types.chat.Chat.unpin_message`,
:meth:`aiogram.types.chat.Chat.pin_message`,
:meth:`aiogram.types.chat.Chat.set_administrator_custom_title`,
:meth:`aiogram.types.chat.Chat.set_permissions`,
:meth:`aiogram.types.chat.Chat.promote`,
:meth:`aiogram.types.chat.Chat.restrict`,
:meth:`aiogram.types.chat.Chat.unban`,
:meth:`aiogram.types.chat.Chat.ban`,
:meth:`aiogram.types.chat.Chat.set_description`,
:meth:`aiogram.types.chat.Chat.set_title`,
:meth:`aiogram.types.chat.Chat.delete_photo`,
:meth:`aiogram.types.chat.Chat.set_photo`,
- *Sticker*: :meth:`aiogram.types.sticker.Sticker.set_position_in_set`,
:meth:`aiogram.types.sticker.Sticker.delete_from_set`,
- *User*: :meth:`aiogram.types.user.User.get_profile_photos`

View file

@ -175,10 +175,6 @@ T = TypeVar("T")
class Bot(ContextInstanceMixin["Bot"]): class Bot(ContextInstanceMixin["Bot"]):
"""
Bot class
"""
def __init__( def __init__(
self, self,
token: str, token: str,
@ -186,6 +182,8 @@ class Bot(ContextInstanceMixin["Bot"]):
parse_mode: Optional[str] = None, parse_mode: Optional[str] = None,
) -> None: ) -> None:
""" """
Bot class
:param token: Telegram Bot token `Obtained from @BotFather <https://t.me/BotFather>`_ :param token: Telegram Bot token `Obtained from @BotFather <https://t.me/BotFather>`_
:param session: HTTP Client session (For example AiohttpSession). :param session: HTTP Client session (For example AiohttpSession).
If not specified it will be automatically created. If not specified it will be automatically created.
@ -234,6 +232,11 @@ class Bot(ContextInstanceMixin["Bot"]):
self.reset_current(token) self.reset_current(token)
async def me(self) -> User: async def me(self) -> User:
"""
Cached alias for getMe method
:return:
"""
if self._me is None: # pragma: no cover if self._me is None: # pragma: no cover
self._me = await self.get_me() self._me = await self.get_me()
return self._me return self._me

View file

@ -1,13 +1,35 @@
from .bot_command_scope_type import BotCommandScopeType
from .chat_action import ChatAction
from .chat_member_status import ChatMemberStatus
from .chat_type import ChatType from .chat_type import ChatType
from .content_type import ContentType from .content_type import ContentType
from .dice_emoji import DiceEmoji from .dice_emoji import DiceEmoji
from .inline_query_result_type import InlineQueryResultType
from .input_media_type import InputMediaType
from .mask_position_point import MaskPositionPoint
from .menu_button_type import MenuButtonType
from .message_entity_type import MessageEntityType
from .parse_mode import ParseMode
from .poll_type import PollType
from .sticker_type import StickerType
from .topic_icon_color import TopicIconColor from .topic_icon_color import TopicIconColor
from .update_type import UpdateType from .update_type import UpdateType
__all__ = ( __all__ = (
"BotCommandScopeType",
"ChatAction",
"ChatMemberStatus",
"ChatType", "ChatType",
"ContentType", "ContentType",
"DiceEmoji", "DiceEmoji",
"InlineQueryResultType",
"InputMediaType",
"MaskPositionPoint",
"MenuButtonType",
"MessageEntityType",
"ParseMode",
"PollType",
"StickerType",
"TopicIconColor", "TopicIconColor",
"UpdateType", "UpdateType",
) )

View file

@ -0,0 +1,17 @@
from enum import Enum
class BotCommandScopeType(str, Enum):
"""
This object represents the scope to which bot commands are applied.
Source: https://core.telegram.org/bots/api#botcommandscope
"""
DEFAULT = "default"
ALL_PRIVATE_CHATS = "all_private_chats"
ALL_GROUP_CHATS = "all_group_chats"
ALL_CHAT_ADMINISTRATORS = "all_chat_administrators"
CHAT = "chat"
CHAT_ADMINISTRATORS = "chat_administrators"
CHAT_MEMBER = "chat_member"

View file

@ -0,0 +1,32 @@
from enum import Enum
class ChatAction(str, Enum):
"""
This object represents bot actions.
Choose one, depending on what the user is about to receive:
- typing for text messages,
- upload_photo for photos,
- record_video or upload_video for videos,
- record_voice or upload_voice for voice notes,
- upload_document for general files,
- choose_sticker for stickers,
- find_location for location data,
- record_video_note or upload_video_note for video notes.
Source: https://core.telegram.org/bots/api#sendchataction
"""
TYPING = "typing"
UPLOAD_PHOTO = "upload_photo"
RECORD_VIDEO = "record_video"
UPLOAD_VIDEO = "upload_video"
RECORD_VOICE = "record_voice"
UPLOAD_VOICE = "upload_voice"
UPLOAD_DOCUMENT = "upload_document"
CHOOSE_STICKER = "choose_sticker"
FIND_LOCATION = "find_location"
RECORD_VIDEO_NOTE = "record_video_note"
UPLOAD_VIDEO_NOTE = "upload_video_note"

View file

@ -0,0 +1,16 @@
from enum import Enum
class ChatMemberStatus(str, Enum):
"""
This object represents chat member status.
Source: https://core.telegram.org/bots/api#chatmember
"""
CREATOR = "creator"
ADMINISTRATOR = "administrator"
MEMBER = "member"
RESTRICTED = "restricted"
LEFT = "left"
KICKED = "kicked"

View file

@ -3,9 +3,12 @@ from enum import Enum
class ChatType(str, Enum): class ChatType(str, Enum):
""" """
Type of chat This object represents a chat type
Source: https://core.telegram.org/bots/api#chat
""" """
SENDER = "sender"
PRIVATE = "private" PRIVATE = "private"
GROUP = "group" GROUP = "group"
SUPERGROUP = "supergroup" SUPERGROUP = "supergroup"

View file

@ -3,7 +3,7 @@ from enum import Enum
class ContentType(str, Enum): class ContentType(str, Enum):
""" """
Message content type This object represents a type of content in message
""" """
UNKNOWN = "unknown" UNKNOWN = "unknown"

View file

@ -4,6 +4,8 @@ from enum import Enum
class DiceEmoji(str, Enum): class DiceEmoji(str, Enum):
""" """
Emoji on which the dice throw animation is based Emoji on which the dice throw animation is based
Source: https://core.telegram.org/bots/api#dice
""" """
DICE = "🎲" DICE = "🎲"

View file

@ -0,0 +1,23 @@
from enum import Enum
class InlineQueryResultType(str, Enum):
"""
The part of the face relative to which the mask should be placed.
Source: https://core.telegram.org/bots/api#maskposition
"""
AUDIO = "audio"
DOCUMENT = "document"
GIF = "gif"
MPEG = "mpeg"
PHOTO = "photo"
STICKER = "sticker"
VIDEO = "video"
VOICE = "voice"
ARTICLE = "article"
CONTACT = "contact"
GAME = "game"
LOCATION = "location"
VENUE = "venue"

View file

@ -0,0 +1,15 @@
from enum import Enum
class InputMediaType(str, Enum):
"""
This object represents input media type
Source: https://core.telegram.org/bots/api#inputmedia
"""
ANIMATION = "animation"
AUDIO = "audio"
DOCUMENT = "document"
PHOTO = "photo"
VIDEO = "video"

View file

@ -0,0 +1,14 @@
from enum import Enum
class MaskPositionPoint(str, Enum):
"""
The part of the face relative to which the mask should be placed.
Source: https://core.telegram.org/bots/api#maskposition
"""
FOREHEAD = "forehead"
EYES = "eyes"
MOUTH = "mouth"
CHIN = "chin"

View file

@ -0,0 +1,13 @@
from enum import Enum
class MenuButtonType(str, Enum):
"""
This object represents an type of Menu button
Source: https://core.telegram.org/bots/api#menubuttondefault
"""
DEFAULT = "default"
COMMANDS = "commands"
WEB_APP = "web_app"

View file

@ -0,0 +1,27 @@
from enum import Enum
class MessageEntityType(str, Enum):
"""
This object represents type of message entity
Source: https://core.telegram.org/bots/api#messageentity
"""
MENTION = "mention"
HASHTAG = "hashtag"
CASHTAG = "cashtag"
BOT_COMMAND = "bot_command"
URL = "url"
EMAIL = "email"
PHONE_NUMBER = "phone_number"
BOLD = "bold"
ITALIC = "italic"
UNDERLINE = "underline"
STRIKETHROUGH = "strikethrough"
SPOILER = "spoiler"
CODE = "code"
PRE = "pre"
TEXT_LINK = "text_link"
TEXT_MENTION = "text_mention"
CUSTOM_EMOJI = "custom_emoji"

View file

@ -0,0 +1,13 @@
from enum import Enum
class ParseMode(str, Enum):
"""
Formatting options
Source: https://core.telegram.org/bots/api#formatting-options
"""
MARKDOWN_V2 = "MarkdownV2"
MARKDOWN = "Markdown"
HTML = "HTML"

View file

@ -0,0 +1,12 @@
from enum import Enum
class PollType(str, Enum):
"""
This object represents poll type
Source: https://core.telegram.org/bots/api#poll
"""
REGULAR = "regular"
QUIZ = "quiz"

View file

@ -0,0 +1,13 @@
from enum import Enum
class StickerType(str, Enum):
"""
The part of the face relative to which the mask should be placed.
Source: https://core.telegram.org/bots/api#maskposition
"""
REGULAR = "regular"
MASK = "mask"
CUSTOM_EMOJI = "custom_emoji"

View file

@ -3,7 +3,9 @@ from enum import Enum
class UpdateType(str, Enum): class UpdateType(str, Enum):
""" """
Known update types This object represents the complete list of allowed update types
Source: https://core.telegram.org/bots/api#update
""" """
MESSAGE = "message" MESSAGE = "message"

View file

@ -15,7 +15,6 @@ from .bot_command_scope_default import BotCommandScopeDefault
from .callback_game import CallbackGame from .callback_game import CallbackGame
from .callback_query import CallbackQuery from .callback_query import CallbackQuery
from .chat import Chat from .chat import Chat
from .chat_action import ChatAction
from .chat_administrator_rights import ChatAdministratorRights from .chat_administrator_rights import ChatAdministratorRights
from .chat_invite_link import ChatInviteLink from .chat_invite_link import ChatInviteLink
from .chat_join_request import ChatJoinRequest from .chat_join_request import ChatJoinRequest
@ -37,6 +36,7 @@ from .document import Document
from .downloadable import Downloadable from .downloadable import Downloadable
from .encrypted_credentials import EncryptedCredentials from .encrypted_credentials import EncryptedCredentials
from .encrypted_passport_element import EncryptedPassportElement from .encrypted_passport_element import EncryptedPassportElement
from .error_event import ErrorEvent
from .file import File from .file import File
from .force_reply import ForceReply from .force_reply import ForceReply
from .forum_topic import ForumTopic from .forum_topic import ForumTopic
@ -142,151 +142,151 @@ from .web_app_info import WebAppInfo
from .webhook_info import WebhookInfo from .webhook_info import WebhookInfo
__all__ = ( __all__ = (
"TelegramObject",
"Downloadable",
"UNSET",
"BufferedInputFile",
"FSInputFile",
"URLInputFile",
"Update",
"WebhookInfo",
"User",
"Chat",
"Message",
"ContentType",
"MessageId",
"MessageEntity",
"PhotoSize",
"Animation", "Animation",
"Audio", "Audio",
"Document",
"Video",
"VideoNote",
"Voice",
"Contact",
"Dice",
"PollOption",
"PollAnswer",
"Poll",
"Location",
"Venue",
"WebAppData",
"ProximityAlertTriggered",
"MessageAutoDeleteTimerChanged",
"ForumTopicCreated",
"ForumTopicClosed",
"ForumTopicReopened",
"VideoChatScheduled",
"VideoChatStarted",
"VideoChatEnded",
"VideoChatParticipantsInvited",
"UserProfilePhotos",
"File",
"WebAppInfo",
"ReplyKeyboardMarkup",
"KeyboardButton",
"KeyboardButtonPollType",
"ReplyKeyboardRemove",
"InlineKeyboardMarkup",
"InlineKeyboardButton",
"LoginUrl",
"CallbackQuery",
"ForceReply",
"ChatPhoto",
"ChatInviteLink",
"ChatAdministratorRights",
"ChatMember",
"ChatMemberOwner",
"ChatMemberAdministrator",
"ChatMemberMember",
"ChatMemberRestricted",
"ChatMemberLeft",
"ChatMemberBanned",
"ChatMemberUpdated",
"ChatJoinRequest",
"ChatPermissions",
"ChatLocation",
"ForumTopic",
"BotCommand", "BotCommand",
"BotCommandScope", "BotCommandScope",
"BotCommandScopeDefault",
"BotCommandScopeAllPrivateChats",
"BotCommandScopeAllGroupChats",
"BotCommandScopeAllChatAdministrators", "BotCommandScopeAllChatAdministrators",
"BotCommandScopeAllGroupChats",
"BotCommandScopeAllPrivateChats",
"BotCommandScopeChat", "BotCommandScopeChat",
"BotCommandScopeChatAdministrators", "BotCommandScopeChatAdministrators",
"BotCommandScopeChatMember", "BotCommandScopeChatMember",
"MenuButton", "BotCommandScopeDefault",
"MenuButtonCommands", "BufferedInputFile",
"MenuButtonWebApp", "CallbackGame",
"MenuButtonDefault", "CallbackQuery",
"ResponseParameters", "Chat",
"InputMedia", "ChatAdministratorRights",
"InputMediaPhoto", "ChatInviteLink",
"InputMediaVideo", "ChatJoinRequest",
"InputMediaAnimation", "ChatLocation",
"InputMediaAudio", "ChatMember",
"InputMediaDocument", "ChatMemberAdministrator",
"InputFile", "ChatMemberBanned",
"Sticker", "ChatMemberLeft",
"StickerSet", "ChatMemberMember",
"MaskPosition", "ChatMemberOwner",
"ChatMemberRestricted",
"ChatMemberUpdated",
"ChatPermissions",
"ChatPhoto",
"ChosenInlineResult",
"Contact",
"ContentType",
"Dice",
"Document",
"Downloadable",
"EncryptedCredentials",
"EncryptedPassportElement",
"ErrorEvent",
"FSInputFile",
"File",
"ForceReply",
"ForumTopic",
"ForumTopicClosed",
"ForumTopicCreated",
"ForumTopicReopened",
"Game",
"GameHighScore",
"InlineKeyboardButton",
"InlineKeyboardMarkup",
"InlineQuery", "InlineQuery",
"InlineQueryResult", "InlineQueryResult",
"InlineQueryResultArticle", "InlineQueryResultArticle",
"InlineQueryResultPhoto",
"InlineQueryResultGif",
"InlineQueryResultMpeg4Gif",
"InlineQueryResultVideo",
"InlineQueryResultAudio", "InlineQueryResultAudio",
"InlineQueryResultVoice", "InlineQueryResultCachedAudio",
"InlineQueryResultDocument", "InlineQueryResultCachedDocument",
"InlineQueryResultLocation",
"InlineQueryResultVenue",
"InlineQueryResultContact",
"InlineQueryResultGame",
"InlineQueryResultCachedPhoto",
"InlineQueryResultCachedGif", "InlineQueryResultCachedGif",
"InlineQueryResultCachedMpeg4Gif", "InlineQueryResultCachedMpeg4Gif",
"InlineQueryResultCachedPhoto",
"InlineQueryResultCachedSticker", "InlineQueryResultCachedSticker",
"InlineQueryResultCachedDocument",
"InlineQueryResultCachedVideo", "InlineQueryResultCachedVideo",
"InlineQueryResultCachedVoice", "InlineQueryResultCachedVoice",
"InlineQueryResultCachedAudio", "InlineQueryResultContact",
"InlineQueryResultDocument",
"InlineQueryResultGame",
"InlineQueryResultGif",
"InlineQueryResultLocation",
"InlineQueryResultMpeg4Gif",
"InlineQueryResultPhoto",
"InlineQueryResultVenue",
"InlineQueryResultVideo",
"InlineQueryResultVoice",
"InputContactMessageContent",
"InputFile",
"InputInvoiceMessageContent",
"InputLocationMessageContent",
"InputMedia",
"InputMediaAnimation",
"InputMediaAudio",
"InputMediaDocument",
"InputMediaPhoto",
"InputMediaVideo",
"InputMessageContent", "InputMessageContent",
"InputTextMessageContent", "InputTextMessageContent",
"InputLocationMessageContent",
"InputVenueMessageContent", "InputVenueMessageContent",
"InputContactMessageContent",
"InputInvoiceMessageContent",
"ChosenInlineResult",
"SentWebAppMessage",
"LabeledPrice",
"Invoice", "Invoice",
"ShippingAddress", "KeyboardButton",
"KeyboardButtonPollType",
"LabeledPrice",
"Location",
"LoginUrl",
"MaskPosition",
"MenuButton",
"MenuButtonCommands",
"MenuButtonDefault",
"MenuButtonWebApp",
"Message",
"MessageAutoDeleteTimerChanged",
"MessageEntity",
"MessageId",
"OrderInfo", "OrderInfo",
"ShippingOption",
"SuccessfulPayment",
"ShippingQuery",
"PreCheckoutQuery",
"PassportData", "PassportData",
"PassportFile",
"EncryptedPassportElement",
"EncryptedCredentials",
"PassportElementError", "PassportElementError",
"PassportElementErrorDataField", "PassportElementErrorDataField",
"PassportElementErrorFile",
"PassportElementErrorFiles",
"PassportElementErrorFrontSide", "PassportElementErrorFrontSide",
"PassportElementErrorReverseSide", "PassportElementErrorReverseSide",
"PassportElementErrorSelfie", "PassportElementErrorSelfie",
"PassportElementErrorFile",
"PassportElementErrorFiles",
"PassportElementErrorTranslationFile", "PassportElementErrorTranslationFile",
"PassportElementErrorTranslationFiles", "PassportElementErrorTranslationFiles",
"PassportElementErrorUnspecified", "PassportElementErrorUnspecified",
"Game", "PassportFile",
"CallbackGame", "PhotoSize",
"GameHighScore", "Poll",
"ChatAction", "PollAnswer",
"PollOption",
"PreCheckoutQuery",
"ProximityAlertTriggered",
"ReplyKeyboardMarkup",
"ReplyKeyboardRemove",
"ResponseParameters",
"SentWebAppMessage",
"ShippingAddress",
"ShippingOption",
"ShippingQuery",
"Sticker",
"StickerSet",
"SuccessfulPayment",
"TelegramObject",
"UNSET",
"URLInputFile",
"Update",
"User",
"UserProfilePhotos",
"Venue",
"Video",
"VideoChatEnded",
"VideoChatParticipantsInvited",
"VideoChatScheduled",
"VideoChatStarted",
"VideoNote",
"Voice",
"WebAppData",
"WebAppInfo",
"WebhookInfo",
) )
# Load typing forward refs for every TelegramObject # Load typing forward refs for every TelegramObject

View file

@ -2,6 +2,7 @@ from __future__ import annotations
from pydantic import Field from pydantic import Field
from ..enums import BotCommandScopeType
from .bot_command_scope import BotCommandScope from .bot_command_scope import BotCommandScope
@ -12,5 +13,5 @@ class BotCommandScopeAllChatAdministrators(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopeallchatadministrators Source: https://core.telegram.org/bots/api#botcommandscopeallchatadministrators
""" """
type: str = Field("all_chat_administrators", const=True) type: str = Field(BotCommandScopeType.ALL_CHAT_ADMINISTRATORS, const=True)
"""Scope type, must be *all_chat_administrators*""" """Scope type, must be *all_chat_administrators*"""

View file

@ -2,6 +2,7 @@ from __future__ import annotations
from pydantic import Field from pydantic import Field
from ..enums import BotCommandScopeType
from .bot_command_scope import BotCommandScope from .bot_command_scope import BotCommandScope
@ -12,5 +13,5 @@ class BotCommandScopeAllGroupChats(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopeallgroupchats Source: https://core.telegram.org/bots/api#botcommandscopeallgroupchats
""" """
type: str = Field("all_group_chats", const=True) type: str = Field(BotCommandScopeType.ALL_GROUP_CHATS, const=True)
"""Scope type, must be *all_group_chats*""" """Scope type, must be *all_group_chats*"""

View file

@ -2,6 +2,7 @@ from __future__ import annotations
from pydantic import Field from pydantic import Field
from ..enums import BotCommandScopeType
from .bot_command_scope import BotCommandScope from .bot_command_scope import BotCommandScope
@ -12,5 +13,5 @@ class BotCommandScopeAllPrivateChats(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopeallprivatechats Source: https://core.telegram.org/bots/api#botcommandscopeallprivatechats
""" """
type: str = Field("all_private_chats", const=True) type: str = Field(BotCommandScopeType.ALL_PRIVATE_CHATS, const=True)
"""Scope type, must be *all_private_chats*""" """Scope type, must be *all_private_chats*"""

View file

@ -4,6 +4,7 @@ from typing import Union
from pydantic import Field from pydantic import Field
from ..enums import BotCommandScopeType
from .bot_command_scope import BotCommandScope from .bot_command_scope import BotCommandScope
@ -14,7 +15,7 @@ class BotCommandScopeChat(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopechat Source: https://core.telegram.org/bots/api#botcommandscopechat
""" """
type: str = Field("chat", const=True) type: str = Field(BotCommandScopeType.CHAT, const=True)
"""Scope type, must be *chat*""" """Scope type, must be *chat*"""
chat_id: Union[int, str] chat_id: Union[int, str]
"""Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)"""

View file

@ -4,6 +4,7 @@ from typing import Union
from pydantic import Field from pydantic import Field
from ..enums import BotCommandScopeType
from .bot_command_scope import BotCommandScope from .bot_command_scope import BotCommandScope
@ -14,7 +15,7 @@ class BotCommandScopeChatAdministrators(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopechatadministrators Source: https://core.telegram.org/bots/api#botcommandscopechatadministrators
""" """
type: str = Field("chat_administrators", const=True) type: str = Field(BotCommandScopeType.CHAT_ADMINISTRATORS, const=True)
"""Scope type, must be *chat_administrators*""" """Scope type, must be *chat_administrators*"""
chat_id: Union[int, str] chat_id: Union[int, str]
"""Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)"""

View file

@ -4,6 +4,7 @@ from typing import Union
from pydantic import Field from pydantic import Field
from ..enums import BotCommandScopeType
from .bot_command_scope import BotCommandScope from .bot_command_scope import BotCommandScope
@ -14,7 +15,7 @@ class BotCommandScopeChatMember(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopechatmember Source: https://core.telegram.org/bots/api#botcommandscopechatmember
""" """
type: str = Field("chat_member", const=True) type: str = Field(BotCommandScopeType.CHAT_MEMBER, const=True)
"""Scope type, must be *chat_member*""" """Scope type, must be *chat_member*"""
chat_id: Union[int, str] chat_id: Union[int, str]
"""Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)"""

View file

@ -2,6 +2,7 @@ from __future__ import annotations
from pydantic import Field from pydantic import Field
from ..enums import BotCommandScopeType
from .bot_command_scope import BotCommandScope from .bot_command_scope import BotCommandScope
@ -12,5 +13,5 @@ class BotCommandScopeDefault(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopedefault Source: https://core.telegram.org/bots/api#botcommandscopedefault
""" """
type: str = Field("default", const=True) type: str = Field(BotCommandScopeType.DEFAULT, const=True)
"""Scope type, must be *default*""" """Scope type, must be *default*"""

View file

@ -1,6 +1,6 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Optional from typing import TYPE_CHECKING, Any, Optional
from pydantic import Field from pydantic import Field
@ -42,17 +42,30 @@ class CallbackQuery(TelegramObject):
show_alert: Optional[bool] = None, show_alert: Optional[bool] = None,
url: Optional[str] = None, url: Optional[str] = None,
cache_time: Optional[int] = None, cache_time: Optional[int] = None,
**kwargs: Any,
) -> AnswerCallbackQuery: ) -> AnswerCallbackQuery:
""" """
Answer to callback query Shortcut for method :class:`aiogram.methods.answer_callback_query.AnswerCallbackQuery`
will automatically fill method attributes:
:param text: - :code:`callback_query_id`
:param show_alert:
:param url: Use this method to send answers to callback queries sent from `inline keyboards <https://core.telegram.org/bots/features#inline-keyboards>`_. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, :code:`True` is returned.
:param cache_time:
:return: Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via `@BotFather <https://t.me/botfather>`_ and accept the terms. Otherwise, you may use links like :code:`t.me/your_bot?start=XXXX` that open your bot with a parameter.
Source: https://core.telegram.org/bots/api#answercallbackquery
:param text: Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
:param show_alert: If :code:`True`, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to *false*.
:param url: URL that will be opened by the user's client. If you have created a :class:`aiogram.types.game.Game` and accepted the conditions via `@BotFather <https://t.me/botfather>`_, specify the URL that opens your game - note that this will only work if the query comes from a `https://core.telegram.org/bots/api#inlinekeyboardbutton <https://core.telegram.org/bots/api#inlinekeyboardbutton>`_ *callback_game* button.
:param cache_time: The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
:return: instance of method :class:`aiogram.methods.answer_callback_query.AnswerCallbackQuery`
""" """
from ..methods import AnswerCallbackQuery # DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import AnswerCallbackQuery
return AnswerCallbackQuery( return AnswerCallbackQuery(
callback_query_id=self.id, callback_query_id=self.id,
@ -60,4 +73,5 @@ class CallbackQuery(TelegramObject):
show_alert=show_alert, show_alert=show_alert,
url=url, url=url,
cache_time=cache_time, cache_time=cache_time,
**kwargs,
) )

View file

@ -1,14 +1,44 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, List, Optional import datetime
from typing import TYPE_CHECKING, Any, List, Optional, Union
from .base import TelegramObject from .base import TelegramObject
if TYPE_CHECKING: if TYPE_CHECKING:
from ..methods import BanChatSenderChat, UnbanChatSenderChat from ..methods import (
BanChatMember,
BanChatSenderChat,
CreateChatInviteLink,
DeleteChatPhoto,
DeleteChatStickerSet,
DeleteMessage,
EditChatInviteLink,
ExportChatInviteLink,
GetChatAdministrators,
GetChatMember,
GetChatMemberCount,
LeaveChat,
PinChatMessage,
PromoteChatMember,
RestrictChatMember,
RevokeChatInviteLink,
SendChatAction,
SetChatAdministratorCustomTitle,
SetChatDescription,
SetChatPermissions,
SetChatPhoto,
SetChatStickerSet,
SetChatTitle,
UnbanChatMember,
UnbanChatSenderChat,
UnpinAllChatMessages,
UnpinChatMessage,
)
from .chat_location import ChatLocation from .chat_location import ChatLocation
from .chat_permissions import ChatPermissions from .chat_permissions import ChatPermissions
from .chat_photo import ChatPhoto from .chat_photo import ChatPhoto
from .input_file import InputFile
from .message import Message from .message import Message
@ -103,18 +133,866 @@ class Chat(TelegramObject):
return f"{self.first_name}" return f"{self.first_name}"
def ban_sender_chat(self, sender_chat_id: int) -> BanChatSenderChat: def ban_sender_chat(
from ..methods import BanChatSenderChat self,
sender_chat_id: int,
**kwargs: Any,
) -> BanChatSenderChat:
"""
Shortcut for method :class:`aiogram.methods.ban_chat_sender_chat.BanChatSenderChat`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to ban a channel chat in a supergroup or a channel. Until the chat is `unbanned <https://core.telegram.org/bots/api#unbanchatsenderchat>`_, the owner of the banned chat won't be able to send messages on behalf of **any of their channels**. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#banchatsenderchat
:param sender_chat_id: Unique identifier of the target sender chat
:return: instance of method :class:`aiogram.methods.ban_chat_sender_chat.BanChatSenderChat`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import BanChatSenderChat
return BanChatSenderChat( return BanChatSenderChat(
chat_id=self.id, chat_id=self.id,
sender_chat_id=sender_chat_id, sender_chat_id=sender_chat_id,
**kwargs,
) )
def unban_sender_chat(self, sender_chat_id: int) -> UnbanChatSenderChat: def unban_sender_chat(
from ..methods import UnbanChatSenderChat self,
sender_chat_id: int,
**kwargs: Any,
) -> UnbanChatSenderChat:
"""
Shortcut for method :class:`aiogram.methods.unban_chat_sender_chat.UnbanChatSenderChat`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#unbanchatsenderchat
:param sender_chat_id: Unique identifier of the target sender chat
:return: instance of method :class:`aiogram.methods.unban_chat_sender_chat.UnbanChatSenderChat`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import UnbanChatSenderChat
return UnbanChatSenderChat( return UnbanChatSenderChat(
chat_id=self.id, chat_id=self.id,
sender_chat_id=sender_chat_id, sender_chat_id=sender_chat_id,
**kwargs,
)
def get_administrators(
self,
**kwargs: Any,
) -> GetChatAdministrators:
"""
Shortcut for method :class:`aiogram.methods.get_chat_administrators.GetChatAdministrators`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of :class:`aiogram.types.chat_member.ChatMember` objects.
Source: https://core.telegram.org/bots/api#getchatadministrators
:return: instance of method :class:`aiogram.methods.get_chat_administrators.GetChatAdministrators`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import GetChatAdministrators
return GetChatAdministrators(
chat_id=self.id,
**kwargs,
)
def delete_message(
self,
message_id: int,
**kwargs: Any,
) -> DeleteMessage:
"""
Shortcut for method :class:`aiogram.methods.delete_message.DeleteMessage`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to delete a message, including service messages, with the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago.
- Service messages about a supergroup, channel, or forum topic creation can't be deleted.
- A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
- Bots can delete outgoing messages in private chats, groups, and supergroups.
- Bots can delete incoming messages in private chats.
- Bots granted *can_post_messages* permissions can delete outgoing messages in channels.
- If the bot is an administrator of a group, it can delete any message there.
- If the bot has *can_delete_messages* permission in a supergroup or a channel, it can delete any message there.
Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#deletemessage
:param message_id: Identifier of the message to delete
:return: instance of method :class:`aiogram.methods.delete_message.DeleteMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import DeleteMessage
return DeleteMessage(
chat_id=self.id,
message_id=message_id,
**kwargs,
)
def revoke_invite_link(
self,
invite_link: str,
**kwargs: Any,
) -> RevokeChatInviteLink:
"""
Shortcut for method :class:`aiogram.methods.revoke_chat_invite_link.RevokeChatInviteLink`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as :class:`aiogram.types.chat_invite_link.ChatInviteLink` object.
Source: https://core.telegram.org/bots/api#revokechatinvitelink
:param invite_link: The invite link to revoke
:return: instance of method :class:`aiogram.methods.revoke_chat_invite_link.RevokeChatInviteLink`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import RevokeChatInviteLink
return RevokeChatInviteLink(
chat_id=self.id,
invite_link=invite_link,
**kwargs,
)
def edit_invite_link(
self,
invite_link: str,
name: Optional[str] = None,
expire_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
member_limit: Optional[int] = None,
creates_join_request: Optional[bool] = None,
**kwargs: Any,
) -> EditChatInviteLink:
"""
Shortcut for method :class:`aiogram.methods.edit_chat_invite_link.EditChatInviteLink`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the edited invite link as a :class:`aiogram.types.chat_invite_link.ChatInviteLink` object.
Source: https://core.telegram.org/bots/api#editchatinvitelink
:param invite_link: The invite link to edit
:param name: Invite link name; 0-32 characters
:param expire_date: Point in time (Unix timestamp) when the link will expire
:param member_limit: The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
:param creates_join_request: :code:`True`, if users joining the chat via the link need to be approved by chat administrators. If :code:`True`, *member_limit* can't be specified
:return: instance of method :class:`aiogram.methods.edit_chat_invite_link.EditChatInviteLink`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import EditChatInviteLink
return EditChatInviteLink(
chat_id=self.id,
invite_link=invite_link,
name=name,
expire_date=expire_date,
member_limit=member_limit,
creates_join_request=creates_join_request,
**kwargs,
)
def create_invite_link(
self,
name: Optional[str] = None,
expire_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
member_limit: Optional[int] = None,
creates_join_request: Optional[bool] = None,
**kwargs: Any,
) -> CreateChatInviteLink:
"""
Shortcut for method :class:`aiogram.methods.create_chat_invite_link.CreateChatInviteLink`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method :class:`aiogram.methods.revoke_chat_invite_link.RevokeChatInviteLink`. Returns the new invite link as :class:`aiogram.types.chat_invite_link.ChatInviteLink` object.
Source: https://core.telegram.org/bots/api#createchatinvitelink
:param name: Invite link name; 0-32 characters
:param expire_date: Point in time (Unix timestamp) when the link will expire
:param member_limit: The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
:param creates_join_request: :code:`True`, if users joining the chat via the link need to be approved by chat administrators. If :code:`True`, *member_limit* can't be specified
:return: instance of method :class:`aiogram.methods.create_chat_invite_link.CreateChatInviteLink`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import CreateChatInviteLink
return CreateChatInviteLink(
chat_id=self.id,
name=name,
expire_date=expire_date,
member_limit=member_limit,
creates_join_request=creates_join_request,
**kwargs,
)
def export_invite_link(
self,
**kwargs: Any,
) -> ExportChatInviteLink:
"""
Shortcut for method :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the new invite link as *String* on success.
Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink` or by calling the :class:`aiogram.methods.get_chat.GetChat` method. If your bot needs to generate a new primary invite link replacing its previous one, use :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink` again.
Source: https://core.telegram.org/bots/api#exportchatinvitelink
:return: instance of method :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import ExportChatInviteLink
return ExportChatInviteLink(
chat_id=self.id,
**kwargs,
)
def do(
self,
action: str,
**kwargs: Any,
) -> SendChatAction:
"""
Shortcut for method :class:`aiogram.methods.send_chat_action.SendChatAction`
will automatically fill method attributes:
- :code:`chat_id`
Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns :code:`True` on success.
Example: The `ImageBot <https://t.me/imagebot>`_ needs some time to process a request and upload the image. Instead of sending a text message along the lines of 'Retrieving image, please wait…', the bot may use :class:`aiogram.methods.send_chat_action.SendChatAction` with *action* = *upload_photo*. The user will see a 'sending photo' status for the bot.
We only recommend using this method when a response from the bot will take a **noticeable** amount of time to arrive.
Source: https://core.telegram.org/bots/api#sendchataction
:param action: Type of action to broadcast. Choose one, depending on what the user is about to receive: *typing* for `text messages <https://core.telegram.org/bots/api#sendmessage>`_, *upload_photo* for `photos <https://core.telegram.org/bots/api#sendphoto>`_, *record_video* or *upload_video* for `videos <https://core.telegram.org/bots/api#sendvideo>`_, *record_voice* or *upload_voice* for `voice notes <https://core.telegram.org/bots/api#sendvoice>`_, *upload_document* for `general files <https://core.telegram.org/bots/api#senddocument>`_, *choose_sticker* for `stickers <https://core.telegram.org/bots/api#sendsticker>`_, *find_location* for `location data <https://core.telegram.org/bots/api#sendlocation>`_, *record_video_note* or *upload_video_note* for `video notes <https://core.telegram.org/bots/api#sendvideonote>`_.
:return: instance of method :class:`aiogram.methods.send_chat_action.SendChatAction`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SendChatAction
return SendChatAction(
chat_id=self.id,
action=action,
**kwargs,
)
def delete_sticker_set(
self,
**kwargs: Any,
) -> DeleteChatStickerSet:
"""
Shortcut for method :class:`aiogram.methods.delete_chat_sticker_set.DeleteChatStickerSet`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field *can_set_sticker_set* optionally returned in :class:`aiogram.methods.get_chat.GetChat` requests to check if the bot can use this method. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#deletechatstickerset
:return: instance of method :class:`aiogram.methods.delete_chat_sticker_set.DeleteChatStickerSet`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import DeleteChatStickerSet
return DeleteChatStickerSet(
chat_id=self.id,
**kwargs,
)
def set_sticker_set(
self,
sticker_set_name: str,
**kwargs: Any,
) -> SetChatStickerSet:
"""
Shortcut for method :class:`aiogram.methods.set_chat_sticker_set.SetChatStickerSet`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field *can_set_sticker_set* optionally returned in :class:`aiogram.methods.get_chat.GetChat` requests to check if the bot can use this method. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#setchatstickerset
:param sticker_set_name: Name of the sticker set to be set as the group sticker set
:return: instance of method :class:`aiogram.methods.set_chat_sticker_set.SetChatStickerSet`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetChatStickerSet
return SetChatStickerSet(
chat_id=self.id,
sticker_set_name=sticker_set_name,
**kwargs,
)
def get_member(
self,
user_id: int,
**kwargs: Any,
) -> GetChatMember:
"""
Shortcut for method :class:`aiogram.methods.get_chat_member.GetChatMember`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to get information about a member of a chat. Returns a :class:`aiogram.types.chat_member.ChatMember` object on success.
Source: https://core.telegram.org/bots/api#getchatmember
:param user_id: Unique identifier of the target user
:return: instance of method :class:`aiogram.methods.get_chat_member.GetChatMember`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import GetChatMember
return GetChatMember(
chat_id=self.id,
user_id=user_id,
**kwargs,
)
def get_member_count(
self,
**kwargs: Any,
) -> GetChatMemberCount:
"""
Shortcut for method :class:`aiogram.methods.get_chat_member_count.GetChatMemberCount`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to get the number of members in a chat. Returns *Int* on success.
Source: https://core.telegram.org/bots/api#getchatmembercount
:return: instance of method :class:`aiogram.methods.get_chat_member_count.GetChatMemberCount`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import GetChatMemberCount
return GetChatMemberCount(
chat_id=self.id,
**kwargs,
)
def leave(
self,
**kwargs: Any,
) -> LeaveChat:
"""
Shortcut for method :class:`aiogram.methods.leave_chat.LeaveChat`
will automatically fill method attributes:
- :code:`chat_id`
Use this method for your bot to leave a group, supergroup or channel. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#leavechat
:return: instance of method :class:`aiogram.methods.leave_chat.LeaveChat`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import LeaveChat
return LeaveChat(
chat_id=self.id,
**kwargs,
)
def unpin_all_messages(
self,
**kwargs: Any,
) -> UnpinAllChatMessages:
"""
Shortcut for method :class:`aiogram.methods.unpin_all_chat_messages.UnpinAllChatMessages`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#unpinallchatmessages
:return: instance of method :class:`aiogram.methods.unpin_all_chat_messages.UnpinAllChatMessages`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import UnpinAllChatMessages
return UnpinAllChatMessages(
chat_id=self.id,
**kwargs,
)
def unpin_message(
self,
message_id: Optional[int] = None,
**kwargs: Any,
) -> UnpinChatMessage:
"""
Shortcut for method :class:`aiogram.methods.unpin_chat_message.UnpinChatMessage`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#unpinchatmessage
:param message_id: Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.
:return: instance of method :class:`aiogram.methods.unpin_chat_message.UnpinChatMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import UnpinChatMessage
return UnpinChatMessage(
chat_id=self.id,
message_id=message_id,
**kwargs,
)
def pin_message(
self,
message_id: int,
disable_notification: Optional[bool] = None,
**kwargs: Any,
) -> PinChatMessage:
"""
Shortcut for method :class:`aiogram.methods.pin_chat_message.PinChatMessage`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#pinchatmessage
:param message_id: Identifier of a message to pin
:param disable_notification: Pass :code:`True` if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats.
:return: instance of method :class:`aiogram.methods.pin_chat_message.PinChatMessage`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import PinChatMessage
return PinChatMessage(
chat_id=self.id,
message_id=message_id,
disable_notification=disable_notification,
**kwargs,
)
def set_administrator_custom_title(
self,
user_id: int,
custom_title: str,
**kwargs: Any,
) -> SetChatAdministratorCustomTitle:
"""
Shortcut for method :class:`aiogram.methods.set_chat_administrator_custom_title.SetChatAdministratorCustomTitle`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#setchatadministratorcustomtitle
:param user_id: Unique identifier of the target user
:param custom_title: New custom title for the administrator; 0-16 characters, emoji are not allowed
:return: instance of method :class:`aiogram.methods.set_chat_administrator_custom_title.SetChatAdministratorCustomTitle`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetChatAdministratorCustomTitle
return SetChatAdministratorCustomTitle(
chat_id=self.id,
user_id=user_id,
custom_title=custom_title,
**kwargs,
)
def set_permissions(
self,
permissions: ChatPermissions,
**kwargs: Any,
) -> SetChatPermissions:
"""
Shortcut for method :class:`aiogram.methods.set_chat_permissions.SetChatPermissions`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the *can_restrict_members* administrator rights. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#setchatpermissions
:param permissions: A JSON-serialized object for new default chat permissions
:return: instance of method :class:`aiogram.methods.set_chat_permissions.SetChatPermissions`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetChatPermissions
return SetChatPermissions(
chat_id=self.id,
permissions=permissions,
**kwargs,
)
def promote(
self,
user_id: int,
is_anonymous: Optional[bool] = None,
can_manage_chat: Optional[bool] = None,
can_post_messages: Optional[bool] = None,
can_edit_messages: Optional[bool] = None,
can_delete_messages: Optional[bool] = None,
can_manage_video_chats: Optional[bool] = None,
can_restrict_members: Optional[bool] = None,
can_promote_members: Optional[bool] = None,
can_change_info: Optional[bool] = None,
can_invite_users: Optional[bool] = None,
can_pin_messages: Optional[bool] = None,
can_manage_topics: Optional[bool] = None,
**kwargs: Any,
) -> PromoteChatMember:
"""
Shortcut for method :class:`aiogram.methods.promote_chat_member.PromoteChatMember`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Pass :code:`False` for all boolean parameters to demote a user. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#promotechatmember
:param user_id: Unique identifier of the target user
:param is_anonymous: Pass :code:`True` if the administrator's presence in the chat is hidden
:param can_manage_chat: Pass :code:`True` if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege
:param can_post_messages: Pass :code:`True` if the administrator can create channel posts, channels only
:param can_edit_messages: Pass :code:`True` if the administrator can edit messages of other users and can pin messages, channels only
:param can_delete_messages: Pass :code:`True` if the administrator can delete messages of other users
:param can_manage_video_chats: Pass :code:`True` if the administrator can manage video chats
:param can_restrict_members: Pass :code:`True` if the administrator can restrict, ban or unban chat members
:param can_promote_members: Pass :code:`True` if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)
:param can_change_info: Pass :code:`True` if the administrator can change chat title, photo and other settings
:param can_invite_users: Pass :code:`True` if the administrator can invite new users to the chat
:param can_pin_messages: Pass :code:`True` if the administrator can pin messages, supergroups only
:param can_manage_topics: Pass :code:`True` if the user is allowed to create, rename, close, and reopen forum topics, supergroups only
:return: instance of method :class:`aiogram.methods.promote_chat_member.PromoteChatMember`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import PromoteChatMember
return PromoteChatMember(
chat_id=self.id,
user_id=user_id,
is_anonymous=is_anonymous,
can_manage_chat=can_manage_chat,
can_post_messages=can_post_messages,
can_edit_messages=can_edit_messages,
can_delete_messages=can_delete_messages,
can_manage_video_chats=can_manage_video_chats,
can_restrict_members=can_restrict_members,
can_promote_members=can_promote_members,
can_change_info=can_change_info,
can_invite_users=can_invite_users,
can_pin_messages=can_pin_messages,
can_manage_topics=can_manage_topics,
**kwargs,
)
def restrict(
self,
user_id: int,
permissions: ChatPermissions,
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
**kwargs: Any,
) -> RestrictChatMember:
"""
Shortcut for method :class:`aiogram.methods.restrict_chat_member.RestrictChatMember`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights. Pass :code:`True` for all permissions to lift restrictions from a user. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#restrictchatmember
:param user_id: Unique identifier of the target user
:param permissions: A JSON-serialized object for new user permissions
:param until_date: Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever
:return: instance of method :class:`aiogram.methods.restrict_chat_member.RestrictChatMember`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import RestrictChatMember
return RestrictChatMember(
chat_id=self.id,
user_id=user_id,
permissions=permissions,
until_date=until_date,
**kwargs,
)
def unban(
self,
user_id: int,
only_if_banned: Optional[bool] = None,
**kwargs: Any,
) -> UnbanChatMember:
"""
Shortcut for method :class:`aiogram.methods.unban_chat_member.UnbanChatMember`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to unban a previously banned user in a supergroup or channel. The user will **not** return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be **removed** from the chat. If you don't want this, use the parameter *only_if_banned*. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#unbanchatmember
:param user_id: Unique identifier of the target user
:param only_if_banned: Do nothing if the user is not banned
:return: instance of method :class:`aiogram.methods.unban_chat_member.UnbanChatMember`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import UnbanChatMember
return UnbanChatMember(
chat_id=self.id,
user_id=user_id,
only_if_banned=only_if_banned,
**kwargs,
)
def ban(
self,
user_id: int,
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
revoke_messages: Optional[bool] = None,
**kwargs: Any,
) -> BanChatMember:
"""
Shortcut for method :class:`aiogram.methods.ban_chat_member.BanChatMember`
will automatically fill method attributes:
- :code:`chat_id`
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
:param user_id: Unique identifier of the target user
:param until_date: 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.
:param revoke_messages: 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.
:return: instance of method :class:`aiogram.methods.ban_chat_member.BanChatMember`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import BanChatMember
return BanChatMember(
chat_id=self.id,
user_id=user_id,
until_date=until_date,
revoke_messages=revoke_messages,
**kwargs,
)
def set_description(
self,
description: Optional[str] = None,
**kwargs: Any,
) -> SetChatDescription:
"""
Shortcut for method :class:`aiogram.methods.set_chat_description.SetChatDescription`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to change the description of a group, a supergroup or a channel. 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#setchatdescription
:param description: New chat description, 0-255 characters
:return: instance of method :class:`aiogram.methods.set_chat_description.SetChatDescription`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetChatDescription
return SetChatDescription(
chat_id=self.id,
description=description,
**kwargs,
)
def set_title(
self,
title: str,
**kwargs: Any,
) -> SetChatTitle:
"""
Shortcut for method :class:`aiogram.methods.set_chat_title.SetChatTitle`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to change the title of a chat. Titles can't be changed for private chats. 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#setchattitle
:param title: New chat title, 1-128 characters
:return: instance of method :class:`aiogram.methods.set_chat_title.SetChatTitle`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetChatTitle
return SetChatTitle(
chat_id=self.id,
title=title,
**kwargs,
)
def delete_photo(
self,
**kwargs: Any,
) -> DeleteChatPhoto:
"""
Shortcut for method :class:`aiogram.methods.delete_chat_photo.DeleteChatPhoto`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to delete a chat photo. Photos can't be changed for private chats. 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#deletechatphoto
:return: instance of method :class:`aiogram.methods.delete_chat_photo.DeleteChatPhoto`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import DeleteChatPhoto
return DeleteChatPhoto(
chat_id=self.id,
**kwargs,
)
def set_photo(
self,
photo: InputFile,
**kwargs: Any,
) -> SetChatPhoto:
"""
Shortcut for method :class:`aiogram.methods.set_chat_photo.SetChatPhoto`
will automatically fill method attributes:
- :code:`chat_id`
Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. 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#setchatphoto
:param photo: New chat photo, uploaded using multipart/form-data
:return: instance of method :class:`aiogram.methods.set_chat_photo.SetChatPhoto`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetChatPhoto
return SetChatPhoto(
chat_id=self.id,
photo=photo,
**kwargs,
) )

View file

@ -1,33 +0,0 @@
import enum
from ..utils.enum import AutoName
class ChatAction(AutoName):
"""
This object represents bot actions.
Choose one, depending on what the user is about to receive:
typing for text messages,
upload_photo for photos,
record_video or upload_video for videos,
record_voice or upload_voice for voice notes,
upload_document for general files,
choose_sticker for stickers,
find_location for location data,
record_video_note or upload_video_note for video notes.
Source: https://core.telegram.org/bots/api#sendchataction
"""
TYPING = enum.auto()
UPLOAD_PHOTO = enum.auto()
RECORD_VIDEO = enum.auto()
UPLOAD_VIDEO = enum.auto()
RECORD_VOICE = enum.auto()
UPLOAD_VOICE = enum.auto()
UPLOAD_DOCUMENT = enum.auto()
CHOOSE_STICKER = enum.auto()
FIND_LOCATION = enum.auto()
RECORD_VIDEO_NOTE = enum.auto()
UPLOAD_VIDEO_NOTE = enum.auto()

View file

@ -1,7 +1,7 @@
from __future__ import annotations from __future__ import annotations
import datetime import datetime
from typing import TYPE_CHECKING, Optional from typing import TYPE_CHECKING, Any, Optional
from pydantic import Field from pydantic import Field
@ -34,24 +34,58 @@ class ChatJoinRequest(TelegramObject):
invite_link: Optional[ChatInviteLink] = None invite_link: Optional[ChatInviteLink] = None
"""*Optional*. Chat invite link that was used by the user to send the join request""" """*Optional*. Chat invite link that was used by the user to send the join request"""
def approve(self) -> ApproveChatJoinRequest: def approve(
self,
**kwargs: Any,
) -> ApproveChatJoinRequest:
""" """
Use this method to approve a chat join request. Shortcut for method :class:`aiogram.methods.approve_chat_join_request.ApproveChatJoinRequest`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`user_id`
Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#approvechatjoinrequest
:return: instance of method :class:`aiogram.methods.approve_chat_join_request.ApproveChatJoinRequest`
""" """
from ..methods import ApproveChatJoinRequest # DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import ApproveChatJoinRequest
return ApproveChatJoinRequest( return ApproveChatJoinRequest(
chat_id=self.chat.id, chat_id=self.chat.id,
user_id=self.from_user.id, user_id=self.from_user.id,
**kwargs,
) )
def decline(self) -> DeclineChatJoinRequest: def decline(
self,
**kwargs: Any,
) -> DeclineChatJoinRequest:
""" """
Use this method to decline a chat join request. Shortcut for method :class:`aiogram.methods.decline_chat_join_request.DeclineChatJoinRequest`
will automatically fill method attributes:
- :code:`chat_id`
- :code:`user_id`
Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#declinechatjoinrequest
:return: instance of method :class:`aiogram.methods.decline_chat_join_request.DeclineChatJoinRequest`
""" """
from ..methods import DeclineChatJoinRequest # DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import DeclineChatJoinRequest
return DeclineChatJoinRequest( return DeclineChatJoinRequest(
chat_id=self.chat.id, chat_id=self.chat.id,
user_id=self.from_user.id, user_id=self.from_user.id,
**kwargs,
) )

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import ChatMemberStatus
from .chat_member import ChatMember from .chat_member import ChatMember
if TYPE_CHECKING: if TYPE_CHECKING:
@ -17,7 +18,7 @@ class ChatMemberAdministrator(ChatMember):
Source: https://core.telegram.org/bots/api#chatmemberadministrator Source: https://core.telegram.org/bots/api#chatmemberadministrator
""" """
status: str = Field("administrator", const=True) status: str = Field(ChatMemberStatus.ADMINISTRATOR, const=True)
"""The member's status in the chat, always 'administrator'""" """The member's status in the chat, always 'administrator'"""
user: User user: User
"""Information about the user""" """Information about the user"""

View file

@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
from pydantic import Field from pydantic import Field
from ..enums import ChatMemberStatus
from .chat_member import ChatMember from .chat_member import ChatMember
if TYPE_CHECKING: if TYPE_CHECKING:
@ -18,7 +19,7 @@ class ChatMemberBanned(ChatMember):
Source: https://core.telegram.org/bots/api#chatmemberbanned Source: https://core.telegram.org/bots/api#chatmemberbanned
""" """
status: str = Field("kicked", const=True) status: str = Field(ChatMemberStatus.KICKED, const=True)
"""The member's status in the chat, always 'kicked'""" """The member's status in the chat, always 'kicked'"""
user: User user: User
"""Information about the user""" """Information about the user"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
from pydantic import Field from pydantic import Field
from ..enums import ChatMemberStatus
from .chat_member import ChatMember from .chat_member import ChatMember
if TYPE_CHECKING: if TYPE_CHECKING:
@ -17,7 +18,7 @@ class ChatMemberLeft(ChatMember):
Source: https://core.telegram.org/bots/api#chatmemberleft Source: https://core.telegram.org/bots/api#chatmemberleft
""" """
status: str = Field("left", const=True) status: str = Field(ChatMemberStatus.LEFT, const=True)
"""The member's status in the chat, always 'left'""" """The member's status in the chat, always 'left'"""
user: User user: User
"""Information about the user""" """Information about the user"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
from pydantic import Field from pydantic import Field
from ..enums import ChatMemberStatus
from .chat_member import ChatMember from .chat_member import ChatMember
if TYPE_CHECKING: if TYPE_CHECKING:
@ -17,7 +18,7 @@ class ChatMemberMember(ChatMember):
Source: https://core.telegram.org/bots/api#chatmembermember Source: https://core.telegram.org/bots/api#chatmembermember
""" """
status: str = Field("member", const=True) status: str = Field(ChatMemberStatus.MEMBER, const=True)
"""The member's status in the chat, always 'member'""" """The member's status in the chat, always 'member'"""
user: User user: User
"""Information about the user""" """Information about the user"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import ChatMemberStatus
from .chat_member import ChatMember from .chat_member import ChatMember
if TYPE_CHECKING: if TYPE_CHECKING:
@ -17,7 +18,7 @@ class ChatMemberOwner(ChatMember):
Source: https://core.telegram.org/bots/api#chatmemberowner Source: https://core.telegram.org/bots/api#chatmemberowner
""" """
status: str = Field("creator", const=True) status: str = Field(ChatMemberStatus.CREATOR, const=True)
"""The member's status in the chat, always 'creator'""" """The member's status in the chat, always 'creator'"""
user: User user: User
"""Information about the user""" """Information about the user"""

View file

@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
from pydantic import Field from pydantic import Field
from ..enums import ChatMemberStatus
from .chat_member import ChatMember from .chat_member import ChatMember
if TYPE_CHECKING: if TYPE_CHECKING:
@ -18,7 +19,7 @@ class ChatMemberRestricted(ChatMember):
Source: https://core.telegram.org/bots/api#chatmemberrestricted Source: https://core.telegram.org/bots/api#chatmemberrestricted
""" """
status: str = Field("restricted", const=True) status: str = Field(ChatMemberStatus.RESTRICTED, const=True)
"""The member's status in the chat, always 'restricted'""" """The member's status in the chat, always 'restricted'"""
user: User user: User
"""Information about the user""" """Information about the user"""

View file

@ -1,16 +1,26 @@
from aiogram.types import Update from __future__ import annotations
from typing import TYPE_CHECKING
from aiogram.types.base import MutableTelegramObject from aiogram.types.base import MutableTelegramObject
if TYPE_CHECKING:
from .update import Update
class ErrorEvent(MutableTelegramObject):
class _ErrorEvent(MutableTelegramObject):
class Config:
arbitrary_types_allowed = True
class ErrorEvent(_ErrorEvent):
""" """
Internal event, should be used to receive errors while processing Updates from Telegram Internal event, should be used to receive errors while processing Updates from Telegram
Source: https://core.telegram.org/bots/api#error-event
""" """
update: Update update: Update
"""Received update""" """Received update"""
exception: Exception exception: Exception
"""Exception""" """Exception"""
class Config:
arbitrary_types_allowed = True

View file

@ -1,6 +1,6 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, List, Optional from typing import TYPE_CHECKING, Any, List, Optional
from pydantic import Field from pydantic import Field
@ -41,17 +41,32 @@ class InlineQuery(TelegramObject):
next_offset: Optional[str] = None, next_offset: Optional[str] = None,
switch_pm_text: Optional[str] = None, switch_pm_text: Optional[str] = None,
switch_pm_parameter: Optional[str] = None, switch_pm_parameter: Optional[str] = None,
**kwargs: Any,
) -> AnswerInlineQuery: ) -> AnswerInlineQuery:
""" """
:param results: Shortcut for method :class:`aiogram.methods.answer_inline_query.AnswerInlineQuery`
:param cache_time: will automatically fill method attributes:
:param is_personal:
:param next_offset: - :code:`inline_query_id`
:param switch_pm_text:
:param switch_pm_parameter: Use this method to send answers to an inline query. On success, :code:`True` is returned.
:return:
No more than **50** results per query are allowed.
Source: https://core.telegram.org/bots/api#answerinlinequery
:param results: A JSON-serialized array of results for the inline query
:param cache_time: The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
:param is_personal: Pass :code:`True` if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
:param next_offset: Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.
:param switch_pm_text: If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*
:param switch_pm_parameter: `Deep-linking <https://core.telegram.org/bots/features#deep-linking>`_ parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed.
:return: instance of method :class:`aiogram.methods.answer_inline_query.AnswerInlineQuery`
""" """
from ..methods import AnswerInlineQuery # DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import AnswerInlineQuery
return AnswerInlineQuery( return AnswerInlineQuery(
inline_query_id=self.id, inline_query_id=self.id,
@ -61,4 +76,5 @@ class InlineQuery(TelegramObject):
next_offset=next_offset, next_offset=next_offset,
switch_pm_text=switch_pm_text, switch_pm_text=switch_pm_text,
switch_pm_parameter=switch_pm_parameter, switch_pm_parameter=switch_pm_parameter,
**kwargs,
) )

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
if TYPE_CHECKING: if TYPE_CHECKING:
@ -18,7 +19,7 @@ class InlineQueryResultArticle(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultarticle Source: https://core.telegram.org/bots/api#inlinequeryresultarticle
""" """
type: str = Field("article", const=True) type: str = Field(InlineQueryResultType.ARTICLE, const=True)
"""Type of the result, must be *article*""" """Type of the result, must be *article*"""
id: str id: str
"""Unique identifier for this result, 1-64 Bytes""" """Unique identifier for this result, 1-64 Bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -21,7 +22,7 @@ class InlineQueryResultAudio(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultaudio Source: https://core.telegram.org/bots/api#inlinequeryresultaudio
""" """
type: str = Field("audio", const=True) type: str = Field(InlineQueryResultType.AUDIO, const=True)
"""Type of the result, must be *audio*""" """Type of the result, must be *audio*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -21,7 +22,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcachedaudio Source: https://core.telegram.org/bots/api#inlinequeryresultcachedaudio
""" """
type: str = Field("audio", const=True) type: str = Field(InlineQueryResultType.AUDIO, const=True)
"""Type of the result, must be *audio*""" """Type of the result, must be *audio*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -21,7 +22,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcacheddocument Source: https://core.telegram.org/bots/api#inlinequeryresultcacheddocument
""" """
type: str = Field("document", const=True) type: str = Field(InlineQueryResultType.DOCUMENT, const=True)
"""Type of the result, must be *document*""" """Type of the result, must be *document*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -20,7 +21,7 @@ class InlineQueryResultCachedGif(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcachedgif Source: https://core.telegram.org/bots/api#inlinequeryresultcachedgif
""" """
type: str = Field("gif", const=True) type: str = Field(InlineQueryResultType.GIF, const=True)
"""Type of the result, must be *gif*""" """Type of the result, must be *gif*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -20,7 +21,7 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif Source: https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif
""" """
type: str = Field("mpeg4_gif", const=True) type: str = Field(InlineQueryResultType.MPEG, const=True)
"""Type of the result, must be *mpeg4_gif*""" """Type of the result, must be *mpeg4_gif*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -20,7 +21,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcachedphoto Source: https://core.telegram.org/bots/api#inlinequeryresultcachedphoto
""" """
type: str = Field("photo", const=True) type: str = Field(InlineQueryResultType.PHOTO, const=True)
"""Type of the result, must be *photo*""" """Type of the result, must be *photo*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
if TYPE_CHECKING: if TYPE_CHECKING:
@ -19,7 +20,7 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcachedsticker Source: https://core.telegram.org/bots/api#inlinequeryresultcachedsticker
""" """
type: str = Field("sticker", const=True) type: str = Field(InlineQueryResultType.STICKER, const=True)
"""Type of the result, must be *sticker*""" """Type of the result, must be *sticker*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -20,7 +21,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvideo Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvideo
""" """
type: str = Field("video", const=True) type: str = Field(InlineQueryResultType.VIDEO, const=True)
"""Type of the result, must be *video*""" """Type of the result, must be *video*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -21,7 +22,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvoice Source: https://core.telegram.org/bots/api#inlinequeryresultcachedvoice
""" """
type: str = Field("voice", const=True) type: str = Field(InlineQueryResultType.VOICE, const=True)
"""Type of the result, must be *voice*""" """Type of the result, must be *voice*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
if TYPE_CHECKING: if TYPE_CHECKING:
@ -19,7 +20,7 @@ class InlineQueryResultContact(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultcontact Source: https://core.telegram.org/bots/api#inlinequeryresultcontact
""" """
type: str = Field("contact", const=True) type: str = Field(InlineQueryResultType.CONTACT, const=True)
"""Type of the result, must be *contact*""" """Type of the result, must be *contact*"""
id: str id: str
"""Unique identifier for this result, 1-64 Bytes""" """Unique identifier for this result, 1-64 Bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -21,7 +22,7 @@ class InlineQueryResultDocument(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultdocument Source: https://core.telegram.org/bots/api#inlinequeryresultdocument
""" """
type: str = Field("document", const=True) type: str = Field(InlineQueryResultType.DOCUMENT, const=True)
"""Type of the result, must be *document*""" """Type of the result, must be *document*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
if TYPE_CHECKING: if TYPE_CHECKING:
@ -18,7 +19,7 @@ class InlineQueryResultGame(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultgame Source: https://core.telegram.org/bots/api#inlinequeryresultgame
""" """
type: str = Field("game", const=True) type: str = Field(InlineQueryResultType.GAME, const=True)
"""Type of the result, must be *game*""" """Type of the result, must be *game*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -20,7 +21,7 @@ class InlineQueryResultGif(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultgif Source: https://core.telegram.org/bots/api#inlinequeryresultgif
""" """
type: str = Field("gif", const=True) type: str = Field(InlineQueryResultType.GIF, const=True)
"""Type of the result, must be *gif*""" """Type of the result, must be *gif*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
if TYPE_CHECKING: if TYPE_CHECKING:
@ -19,7 +20,7 @@ class InlineQueryResultLocation(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultlocation Source: https://core.telegram.org/bots/api#inlinequeryresultlocation
""" """
type: str = Field("location", const=True) type: str = Field(InlineQueryResultType.LOCATION, const=True)
"""Type of the result, must be *location*""" """Type of the result, must be *location*"""
id: str id: str
"""Unique identifier for this result, 1-64 Bytes""" """Unique identifier for this result, 1-64 Bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -20,7 +21,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif Source: https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif
""" """
type: str = Field("mpeg4_gif", const=True) type: str = Field(InlineQueryResultType.MPEG, const=True)
"""Type of the result, must be *mpeg4_gif*""" """Type of the result, must be *mpeg4_gif*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -20,7 +21,7 @@ class InlineQueryResultPhoto(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultphoto Source: https://core.telegram.org/bots/api#inlinequeryresultphoto
""" """
type: str = Field("photo", const=True) type: str = Field(InlineQueryResultType.PHOTO, const=True)
"""Type of the result, must be *photo*""" """Type of the result, must be *photo*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
if TYPE_CHECKING: if TYPE_CHECKING:
@ -19,7 +20,7 @@ class InlineQueryResultVenue(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultvenue Source: https://core.telegram.org/bots/api#inlinequeryresultvenue
""" """
type: str = Field("venue", const=True) type: str = Field(InlineQueryResultType.VENUE, const=True)
"""Type of the result, must be *venue*""" """Type of the result, must be *venue*"""
id: str id: str
"""Unique identifier for this result, 1-64 Bytes""" """Unique identifier for this result, 1-64 Bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -22,7 +23,7 @@ class InlineQueryResultVideo(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultvideo Source: https://core.telegram.org/bots/api#inlinequeryresultvideo
""" """
type: str = Field("video", const=True) type: str = Field(InlineQueryResultType.VIDEO, const=True)
"""Type of the result, must be *video*""" """Type of the result, must be *video*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import Field from pydantic import Field
from ..enums import InlineQueryResultType
from .base import UNSET from .base import UNSET
from .inline_query_result import InlineQueryResult from .inline_query_result import InlineQueryResult
@ -21,7 +22,7 @@ class InlineQueryResultVoice(InlineQueryResult):
Source: https://core.telegram.org/bots/api#inlinequeryresultvoice Source: https://core.telegram.org/bots/api#inlinequeryresultvoice
""" """
type: str = Field("voice", const=True) type: str = Field(InlineQueryResultType.VOICE, const=True)
"""Type of the result, must be *voice*""" """Type of the result, must be *voice*"""
id: str id: str
"""Unique identifier for this result, 1-64 bytes""" """Unique identifier for this result, 1-64 bytes"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional, Union
from pydantic import Field from pydantic import Field
from ..enums import InputMediaType
from .base import UNSET from .base import UNSET
from .input_media import InputMedia from .input_media import InputMedia
@ -19,7 +20,7 @@ class InputMediaAnimation(InputMedia):
Source: https://core.telegram.org/bots/api#inputmediaanimation Source: https://core.telegram.org/bots/api#inputmediaanimation
""" """
type: str = Field("animation", const=True) type: str = Field(InputMediaType.ANIMATION, const=True)
"""Type of the result, must be *animation*""" """Type of the result, must be *animation*"""
media: Union[str, InputFile] media: Union[str, InputFile]
"""File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`""" """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional, Union
from pydantic import Field from pydantic import Field
from ..enums import InputMediaType
from .base import UNSET from .base import UNSET
from .input_media import InputMedia from .input_media import InputMedia
@ -19,7 +20,7 @@ class InputMediaAudio(InputMedia):
Source: https://core.telegram.org/bots/api#inputmediaaudio Source: https://core.telegram.org/bots/api#inputmediaaudio
""" """
type: str = Field("audio", const=True) type: str = Field(InputMediaType.AUDIO, const=True)
"""Type of the result, must be *audio*""" """Type of the result, must be *audio*"""
media: Union[str, InputFile] media: Union[str, InputFile]
"""File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`""" """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional, Union
from pydantic import Field from pydantic import Field
from ..enums import InputMediaType
from .base import UNSET from .base import UNSET
from .input_media import InputMedia from .input_media import InputMedia
@ -19,7 +20,7 @@ class InputMediaDocument(InputMedia):
Source: https://core.telegram.org/bots/api#inputmediadocument Source: https://core.telegram.org/bots/api#inputmediadocument
""" """
type: str = Field("document", const=True) type: str = Field(InputMediaType.DOCUMENT, const=True)
"""Type of the result, must be *document*""" """Type of the result, must be *document*"""
media: Union[str, InputFile] media: Union[str, InputFile]
"""File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`""" """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional, Union
from pydantic import Field from pydantic import Field
from ..enums import InputMediaType
from .base import UNSET from .base import UNSET
from .input_media import InputMedia from .input_media import InputMedia
@ -19,7 +20,7 @@ class InputMediaPhoto(InputMedia):
Source: https://core.telegram.org/bots/api#inputmediaphoto Source: https://core.telegram.org/bots/api#inputmediaphoto
""" """
type: str = Field("photo", const=True) type: str = Field(InputMediaType.PHOTO, const=True)
"""Type of the result, must be *photo*""" """Type of the result, must be *photo*"""
media: Union[str, InputFile] media: Union[str, InputFile]
"""File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`""" """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional, Union
from pydantic import Field from pydantic import Field
from ..enums import InputMediaType
from .base import UNSET from .base import UNSET
from .input_media import InputMedia from .input_media import InputMedia
@ -19,7 +20,7 @@ class InputMediaVideo(InputMedia):
Source: https://core.telegram.org/bots/api#inputmediavideo Source: https://core.telegram.org/bots/api#inputmediavideo
""" """
type: str = Field("video", const=True) type: str = Field(InputMediaType.VIDEO, const=True)
"""Type of the result, must be *video*""" """Type of the result, must be *video*"""
media: Union[str, InputFile] media: Union[str, InputFile]
"""File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`""" """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://<file_attach_name>' to upload a new one using multipart/form-data under <file_attach_name> name. :ref:`More information on Sending Files » <sending-files>`"""

View file

@ -2,6 +2,7 @@ from __future__ import annotations
from pydantic import Field from pydantic import Field
from ..enums import MenuButtonType
from .menu_button import MenuButton from .menu_button import MenuButton
@ -12,5 +13,5 @@ class MenuButtonCommands(MenuButton):
Source: https://core.telegram.org/bots/api#menubuttoncommands Source: https://core.telegram.org/bots/api#menubuttoncommands
""" """
type: str = Field("commands", const=True) type: str = Field(MenuButtonType.COMMANDS, const=True)
"""Type of the button, must be *commands*""" """Type of the button, must be *commands*"""

View file

@ -2,6 +2,7 @@ from __future__ import annotations
from pydantic import Field from pydantic import Field
from ..enums import MenuButtonType
from .menu_button import MenuButton from .menu_button import MenuButton
@ -12,5 +13,5 @@ class MenuButtonDefault(MenuButton):
Source: https://core.telegram.org/bots/api#menubuttondefault Source: https://core.telegram.org/bots/api#menubuttondefault
""" """
type: str = Field("default", const=True) type: str = Field(MenuButtonType.DEFAULT, const=True)
"""Type of the button, must be *default*""" """Type of the button, must be *default*"""

View file

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
from pydantic import Field from pydantic import Field
from ..enums import MenuButtonType
from .menu_button import MenuButton from .menu_button import MenuButton
if TYPE_CHECKING: if TYPE_CHECKING:
@ -17,7 +18,7 @@ class MenuButtonWebApp(MenuButton):
Source: https://core.telegram.org/bots/api#menubuttonwebapp Source: https://core.telegram.org/bots/api#menubuttonwebapp
""" """
type: str = Field("web_app", const=True) type: str = Field(MenuButtonType.WEB_APP, const=True)
"""Type of the button, must be *web_app*""" """Type of the button, must be *web_app*"""
text: str text: str
"""Text on the button""" """Text on the button"""

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,11 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Optional from typing import TYPE_CHECKING, Any, Optional
from .base import TelegramObject from .base import TelegramObject
if TYPE_CHECKING: if TYPE_CHECKING:
from ..methods import DeleteStickerFromSet, SetStickerPositionInSet
from .file import File from .file import File
from .mask_position import MaskPosition from .mask_position import MaskPosition
from .photo_size import PhotoSize from .photo_size import PhotoSize
@ -45,3 +46,58 @@ class Sticker(TelegramObject):
"""*Optional*. For custom emoji stickers, unique identifier of the custom emoji""" """*Optional*. For custom emoji stickers, unique identifier of the custom emoji"""
file_size: Optional[int] = None file_size: Optional[int] = None
"""*Optional*. File size in bytes""" """*Optional*. File size in bytes"""
def set_position_in_set(
self,
position: int,
**kwargs: Any,
) -> SetStickerPositionInSet:
"""
Shortcut for method :class:`aiogram.methods.set_sticker_position_in_set.SetStickerPositionInSet`
will automatically fill method attributes:
- :code:`sticker`
Use this method to move a sticker in a set created by the bot to a specific position. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#setstickerpositioninset
:param position: New sticker position in the set, zero-based
:return: instance of method :class:`aiogram.methods.set_sticker_position_in_set.SetStickerPositionInSet`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import SetStickerPositionInSet
return SetStickerPositionInSet(
sticker=self.file_id,
position=position,
**kwargs,
)
def delete_from_set(
self,
**kwargs: Any,
) -> DeleteStickerFromSet:
"""
Shortcut for method :class:`aiogram.methods.delete_sticker_from_set.DeleteStickerFromSet`
will automatically fill method attributes:
- :code:`sticker`
Use this method to delete a sticker from a set created by the bot. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#deletestickerfromset
:return: instance of method :class:`aiogram.methods.delete_sticker_from_set.DeleteStickerFromSet`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import DeleteStickerFromSet
return DeleteStickerFromSet(
sticker=self.file_id,
**kwargs,
)

View file

@ -1,11 +1,14 @@
from __future__ import annotations from __future__ import annotations
from typing import Optional from typing import TYPE_CHECKING, Any, Optional
from ..utils import markdown from ..utils import markdown
from ..utils.link import create_tg_link from ..utils.link import create_tg_link
from .base import TelegramObject from .base import TelegramObject
if TYPE_CHECKING:
from ..methods import GetUserProfilePhotos
class User(TelegramObject): class User(TelegramObject):
""" """
@ -56,3 +59,35 @@ class User(TelegramObject):
if name is None: if name is None:
name = self.full_name name = self.full_name
return markdown.hlink(name, self.url) return markdown.hlink(name, self.url)
def get_profile_photos(
self,
offset: Optional[int] = None,
limit: Optional[int] = None,
**kwargs: Any,
) -> GetUserProfilePhotos:
"""
Shortcut for method :class:`aiogram.methods.get_user_profile_photos.GetUserProfilePhotos`
will automatically fill method attributes:
- :code:`user_id`
Use this method to get a list of profile pictures for a user. Returns a :class:`aiogram.types.user_profile_photos.UserProfilePhotos` object.
Source: https://core.telegram.org/bots/api#getuserprofilephotos
:param offset: Sequential number of the first photo to be returned. By default, all photos are returned.
:param limit: Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
:return: instance of method :class:`aiogram.methods.get_user_profile_photos.GetUserProfilePhotos`
"""
# DO NOT EDIT MANUALLY!!!
# This method was auto-generated via `butcher`
from aiogram.methods import GetUserProfilePhotos
return GetUserProfilePhotos(
user_id=self.id,
offset=offset,
limit=limit,
**kwargs,
)

View file

@ -1,8 +0,0 @@
import enum
from typing import Any, List
class AutoName(str, enum.Enum):
@staticmethod
def _generate_next_value_(name: str, start: int, count: int, last_values: List[Any]) -> str:
return name.lower()

View file

@ -1,293 +0,0 @@
"""
Example:
>>> from aiogram.utils.helper import Helper, ListItem, HelperMode, Item
>>> class MyHelper(Helper):
... mode = HelperMode.lowerCamelCase
... FOO_ITEM = ListItem()
... BAR_ITEM = ListItem()
... BAZ_ITEM = ListItem()
... LOREM = Item()
...
>>> print(MyHelper.FOO_ITEM & MyHelper.BAR_ITEM)
<<< ['fooItem', 'barItem']
>>> print(MyHelper.all())
<<< ['barItem', 'bazItem', 'fooItem', 'lorem']
"""
import inspect
from typing import Any, Callable, Generic, Iterable, List, Optional, TypeVar, Union, cast
from weakref import WeakKeyDictionary
T = TypeVar("T")
PROPS_KEYS_ATTR_NAME = "_props_keys"
class Helper:
mode = ""
@classmethod
def all(cls) -> List[Any]:
"""
Get all consts
:return: list
"""
result: List[Any] = []
for name in dir(cls):
if not name.isupper():
continue
value = getattr(cls, name)
if isinstance(value, ItemsList):
result.append(value[0])
else:
result.append(value)
return result
class HelperMode(Helper):
mode = "original"
SCREAMING_SNAKE_CASE = "SCREAMING_SNAKE_CASE"
lowerCamelCase = "lowerCamelCase"
CamelCase = "CamelCase"
snake_case = "snake_case"
lowercase = "lowercase"
@classmethod
def all(cls) -> List[str]:
return [
cls.SCREAMING_SNAKE_CASE,
cls.lowerCamelCase,
cls.CamelCase,
cls.snake_case,
cls.lowercase,
]
@classmethod
def _screaming_snake_case(cls, text: str) -> str:
"""
Transform text to SCREAMING_SNAKE_CASE
:param text:
:return:
"""
if text.isupper():
return text
result = ""
for pos, symbol in enumerate(text):
if symbol.isupper() and pos > 0:
result += "_" + symbol
else:
result += symbol.upper()
return result
@classmethod
def _snake_case(cls, text: str) -> str:
"""
Transform text to snake case (Based on SCREAMING_SNAKE_CASE)
:param text:
:return:
"""
if text.islower():
return text
return cls._screaming_snake_case(text).lower()
@classmethod
def _camel_case(cls, text: str, first_upper: bool = False) -> str:
"""
Transform text to camelCase or CamelCase
:param text:
:param first_upper: first symbol must be upper?
:return:
"""
result = ""
need_upper = False
for pos, symbol in enumerate(text):
if symbol == "_" and pos > 0:
need_upper = True
else:
if need_upper:
result += symbol.upper()
else:
result += symbol.lower()
need_upper = False
if first_upper:
result = result[0].upper() + result[1:]
return result
@classmethod
def apply(cls, text: str, mode: Union[str, Callable[[str], str]]) -> str:
"""
Apply mode for text
:param text:
:param mode:
:return:
"""
if mode == cls.SCREAMING_SNAKE_CASE:
return cls._screaming_snake_case(text)
if mode == cls.snake_case:
return cls._snake_case(text)
if mode == cls.lowercase:
return cls._snake_case(text).replace("_", "")
if mode == cls.lowerCamelCase:
return cls._camel_case(text)
if mode == cls.CamelCase:
return cls._camel_case(text, True)
if callable(mode):
return mode(text)
return text
class _BaseItem:
def __init__(self, value: Optional[str] = None):
self._value = cast(str, value)
def __set_name__(self, owner: Any, name: str) -> None:
if not name.isupper():
raise NameError("Name for helper item must be in uppercase!")
if not self._value:
if not inspect.isclass(owner) or not issubclass(owner, Helper):
raise RuntimeError("Instances of Item can be used only as Helper attributes")
self._value = HelperMode.apply(name, owner.mode)
class Item(_BaseItem):
"""
Helper item
If a value is not provided,
it will be automatically generated based on a variable's name
"""
def __get__(self, instance: Any, owner: Any) -> str:
return self._value
class ListItem(_BaseItem):
"""
This item is always a list
You can use &, | and + operators for that.
"""
def add(self, other: "ListItem") -> "ListItem": # pragma: no cover
return self + other
def __get__(self, instance: Any, owner: Any) -> "ItemsList":
return ItemsList(self._value)
def __getitem__(self, item: Any) -> Any: # pragma: no cover
# Only for IDE. This method is never be called.
return self._value
# Need only for IDE
__iadd__ = __add__ = __rand__ = __and__ = __ror__ = __or__ = add
class ItemsList(List[str]):
"""
Patch for default list
This class provides +, &, |, +=, &=, |= operators for extending the list
"""
def __init__(self, *seq: Any):
super(ItemsList, self).__init__(map(str, seq))
def add(self, other: Iterable[str]) -> "ItemsList":
self.extend(other)
return self
__iadd__ = __add__ = __rand__ = __and__ = __ror__ = __or__ = add # type: ignore
class OrderedHelperMeta(type):
def __new__(mcs, name: Any, bases: Any, namespace: Any, **kwargs: Any) -> "OrderedHelperMeta":
cls = super().__new__(mcs, name, bases, namespace)
props_keys = []
for prop_name in (
name for name, prop in namespace.items() if isinstance(prop, (Item, ListItem))
):
props_keys.append(prop_name)
setattr(cls, PROPS_KEYS_ATTR_NAME, props_keys)
return cls
class OrderedHelper(Helper, metaclass=OrderedHelperMeta):
mode = ""
@classmethod
def all(cls) -> List[str]:
"""
Get all Items values
"""
result = []
for name in getattr(cls, PROPS_KEYS_ATTR_NAME, []):
value = getattr(cls, name)
if isinstance(value, ItemsList):
result.append(value[0])
else:
result.append(value)
return result
class Default(Generic[T]):
"""
Descriptor that holds default value getter
Example:
>>> class MyClass:
... att = Default("dflt")
...
>>> my_instance = MyClass()
>>> my_instance.att = "not dflt"
>>> my_instance.att
'not dflt'
>>> MyClass.att
'dflt'
>>> del my_instance.att
>>> my_instance.att
'dflt'
>>>
Intended to be used as a class attribute and only internally.
"""
__slots__ = "fget", "_descriptor_instances"
def __init__(
self,
default: Optional[T] = None,
*,
fget: Optional[Callable[[Any], T]] = None,
) -> None:
self.fget = fget or (lambda _: cast(T, default))
self._descriptor_instances = WeakKeyDictionary() # type: ignore
def __get__(self, instance: Any, owner: Any) -> T:
if instance is None:
return self.fget(instance)
return self._descriptor_instances.get(instance, self.fget(instance))
def __set__(self, instance: Any, value: T) -> None:
if instance is None or isinstance(instance, type):
raise AttributeError(
"Instance cannot be class or None. Setter must be called from a class."
)
self._descriptor_instances[instance] = value
def __delete__(self, instance: Any) -> None:
if instance is None or isinstance(instance, type):
raise AttributeError(
"Instance cannot be class or None. Deleter must be called from a class."
)
self._descriptor_instances.pop(instance, None)

View file

@ -5,6 +5,8 @@ import re
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Generator, List, Optional, Pattern, cast from typing import TYPE_CHECKING, Generator, List, Optional, Pattern, cast
from aiogram.enums import MessageEntityType
if TYPE_CHECKING: if TYPE_CHECKING:
from aiogram.types import MessageEntity from aiogram.types import MessageEntity
@ -36,25 +38,37 @@ class TextDecoration(ABC):
:param text: :param text:
:return: :return:
""" """
if entity.type in {"bot_command", "url", "mention", "phone_number"}: if entity.type in {
MessageEntityType.BOT_COMMAND,
MessageEntityType.URL,
MessageEntityType.MENTION,
MessageEntityType.PHONE_NUMBER,
}:
# This entities should not be changed # This entities should not be changed
return text return text
if entity.type in {"bold", "italic", "code", "underline", "strikethrough", "spoiler"}: if entity.type in {
MessageEntityType.BOLD,
MessageEntityType.ITALIC,
MessageEntityType.CODE,
MessageEntityType.UNDERLINE,
MessageEntityType.STRIKETHROUGH,
MessageEntityType.SPOILER,
}:
return cast(str, getattr(self, entity.type)(value=text)) return cast(str, getattr(self, entity.type)(value=text))
if entity.type == "pre": if entity.type == MessageEntityType.PRE:
return ( return (
self.pre_language(value=text, language=entity.language) self.pre_language(value=text, language=entity.language)
if entity.language if entity.language
else self.pre(value=text) else self.pre(value=text)
) )
if entity.type == "text_mention": if entity.type == MessageEntityType.TEXT_MENTION:
from aiogram.types import User from aiogram.types import User
user = cast(User, entity.user) user = cast(User, entity.user)
return self.link(value=text, link=f"tg://user?id={user.id}") return self.link(value=text, link=f"tg://user?id={user.id}")
if entity.type == "text_link": if entity.type == MessageEntityType.TEXT_LINK:
return self.link(value=text, link=cast(str, entity.url)) return self.link(value=text, link=cast(str, entity.url))
if entity.type == "custom_emoji": if entity.type == MessageEntityType.CUSTOM_EMOJI:
return self.custom_emoji(value=text, custom_emoji_id=cast(str, entity.custom_emoji_id)) return self.custom_emoji(value=text, custom_emoji_id=cast(str, entity.custom_emoji_id))
return self.quote(text) return self.quote(text)

Some files were not shown because too many files have changed in this diff Show more