diff --git a/aiogram/methods/__init__.py b/aiogram/methods/__init__.py index df602bef..54b59e74 100644 --- a/aiogram/methods/__init__.py +++ b/aiogram/methods/__init__.py @@ -3,6 +3,7 @@ from .answer_callback_query import AnswerCallbackQuery from .answer_inline_query import AnswerInlineQuery from .answer_pre_checkout_query import AnswerPreCheckoutQuery from .answer_shipping_query import AnswerShippingQuery +from .ban_chat_member import BanChatMember from .base import Request, Response, TelegramMethod from .close import Close from .copy_message import CopyMessage @@ -11,6 +12,7 @@ from .create_new_sticker_set import CreateNewStickerSet from .delete_chat_photo import DeleteChatPhoto from .delete_chat_sticker_set import DeleteChatStickerSet from .delete_message import DeleteMessage +from .delete_my_commands import DeleteMyCommands from .delete_sticker_from_set import DeleteStickerFromSet from .delete_webhook import DeleteWebhook from .edit_chat_invite_link import EditChatInviteLink @@ -24,6 +26,7 @@ from .forward_message import ForwardMessage from .get_chat import GetChat from .get_chat_administrators import GetChatAdministrators from .get_chat_member import GetChatMember +from .get_chat_member_count import GetChatMemberCount from .get_chat_members_count import GetChatMembersCount from .get_file import GetFile from .get_game_high_scores import GetGameHighScores @@ -109,6 +112,7 @@ __all__ = ( "SendChatAction", "GetUserProfilePhotos", "GetFile", + "BanChatMember", "KickChatMember", "UnbanChatMember", "RestrictChatMember", @@ -129,12 +133,14 @@ __all__ = ( "LeaveChat", "GetChat", "GetChatAdministrators", + "GetChatMemberCount", "GetChatMembersCount", "GetChatMember", "SetChatStickerSet", "DeleteChatStickerSet", "AnswerCallbackQuery", "SetMyCommands", + "DeleteMyCommands", "GetMyCommands", "EditMessageText", "EditMessageCaption", diff --git a/aiogram/methods/ban_chat_member.py b/aiogram/methods/ban_chat_member.py new file mode 100644 index 00000000..457ca68b --- /dev/null +++ b/aiogram/methods/ban_chat_member.py @@ -0,0 +1,33 @@ +from __future__ import annotations + +import datetime +from typing import TYPE_CHECKING, Any, Dict, Optional, Union + +from .base import Request, TelegramMethod + +if TYPE_CHECKING: # pragma: no cover + from ..client.bot import Bot + + +class BanChatMember(TelegramMethod[bool]): + """ + 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 `_ first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns :code:`True` on success. + + Source: https://core.telegram.org/bots/api#banchatmember + """ + + __returning__ = bool + + chat_id: Union[int, str] + """Unique identifier for the target group or username of the target supergroup or channel (in the format :code:`@channelusername`)""" + user_id: int + """Unique identifier of the target user""" + until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None + """Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.""" + revoke_messages: Optional[bool] = None + """Pass :code:`True` to delete all messages from the chat for the user that is being removed. If :code:`False`, the user will be able to see messages in the group that were sent before the user was removed. Always :code:`True` for supergroups and channels.""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="banChatMember", data=data) diff --git a/aiogram/methods/delete_my_commands.py b/aiogram/methods/delete_my_commands.py new file mode 100644 index 00000000..b0b9ebaa --- /dev/null +++ b/aiogram/methods/delete_my_commands.py @@ -0,0 +1,29 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Optional + +from ..types import BotCommandScope +from .base import Request, TelegramMethod + +if TYPE_CHECKING: # pragma: no cover + from ..client.bot import Bot + + +class DeleteMyCommands(TelegramMethod[bool]): + """ + Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, `higher level commands `_ will be shown to affected users. Returns :code:`True` on success. + + Source: https://core.telegram.org/bots/api#deletemycommands + """ + + __returning__ = bool + + scope: Optional[BotCommandScope] = None + """A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.""" + language_code: Optional[str] = None + """A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="deleteMyCommands", data=data) diff --git a/aiogram/methods/get_chat_member_count.py b/aiogram/methods/get_chat_member_count.py new file mode 100644 index 00000000..b6bd67a4 --- /dev/null +++ b/aiogram/methods/get_chat_member_count.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, Union + +from .base import Request, TelegramMethod + +if TYPE_CHECKING: # pragma: no cover + from ..client.bot import Bot + + +class GetChatMemberCount(TelegramMethod[int]): + """ + Use this method to get the number of members in a chat. Returns *Int* on success. + + Source: https://core.telegram.org/bots/api#getchatmembercount + """ + + __returning__ = int + + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="getChatMemberCount", data=data) diff --git a/aiogram/methods/get_chat_members_count.py b/aiogram/methods/get_chat_members_count.py index 2ec638f4..cec4929d 100644 --- a/aiogram/methods/get_chat_members_count.py +++ b/aiogram/methods/get_chat_members_count.py @@ -10,9 +10,13 @@ if TYPE_CHECKING: # pragma: no cover class GetChatMembersCount(TelegramMethod[int]): """ + .. warning: + + Renamed from :code:`getChatMembersCount` in 5.3 bot API version and can be removed in near future + Use this method to get the number of members in a chat. Returns *Int* on success. - Source: https://core.telegram.org/bots/api#getchatmemberscount + Source: https://core.telegram.org/bots/api#getchatmembercount """ __returning__ = int diff --git a/aiogram/methods/get_my_commands.py b/aiogram/methods/get_my_commands.py index 19adb9bd..2e4e683d 100644 --- a/aiogram/methods/get_my_commands.py +++ b/aiogram/methods/get_my_commands.py @@ -1,8 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, Any, Dict, List, Optional -from ..types import BotCommand +from ..types import BotCommand, BotCommandScope from .base import Request, TelegramMethod if TYPE_CHECKING: # pragma: no cover @@ -11,13 +11,18 @@ if TYPE_CHECKING: # pragma: no cover class GetMyCommands(TelegramMethod[List[BotCommand]]): """ - Use this method to get the current list of the bot's commands. Requires no parameters. Returns Array of :class:`aiogram.types.bot_command.BotCommand` on success. + Use this method to get the current list of the bot's commands for the given scope and user language. Returns Array of :class:`aiogram.types.bot_command.BotCommand` on success. If commands aren't set, an empty list is returned. Source: https://core.telegram.org/bots/api#getmycommands """ __returning__ = List[BotCommand] + scope: Optional[BotCommandScope] = None + """A JSON-serialized object, describing scope of users. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.""" + language_code: Optional[str] = None + """A two-letter ISO 639-1 language code or an empty string""" + def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() diff --git a/aiogram/methods/kick_chat_member.py b/aiogram/methods/kick_chat_member.py index 11ed6bba..e854ff11 100644 --- a/aiogram/methods/kick_chat_member.py +++ b/aiogram/methods/kick_chat_member.py @@ -11,9 +11,13 @@ if TYPE_CHECKING: # pragma: no cover class KickChatMember(TelegramMethod[bool]): """ - Use this method to kick a user from 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 `_ first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns :code:`True` on success. + .. warning: - Source: https://core.telegram.org/bots/api#kickchatmember + Renamed from :code:`kickChatMember` in 5.3 bot API version and can be removed in near future + + Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless `unbanned `_ first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns :code:`True` on success. + + Source: https://core.telegram.org/bots/api#banchatmember """ __returning__ = bool diff --git a/aiogram/methods/set_my_commands.py b/aiogram/methods/set_my_commands.py index a739b228..451ce509 100644 --- a/aiogram/methods/set_my_commands.py +++ b/aiogram/methods/set_my_commands.py @@ -1,8 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, Any, Dict, List, Optional -from ..types import BotCommand +from ..types import BotCommand, BotCommandScope from .base import Request, TelegramMethod if TYPE_CHECKING: # pragma: no cover @@ -11,7 +11,7 @@ if TYPE_CHECKING: # pragma: no cover class SetMyCommands(TelegramMethod[bool]): """ - Use this method to change the list of the bot's commands. Returns :code:`True` on success. + Use this method to change the list of the bot's commands. See `https://core.telegram.org/bots#commands `_`https://core.telegram.org/bots#commands `_ for more details about bot commands. Returns :code:`True` on success. Source: https://core.telegram.org/bots/api#setmycommands """ @@ -20,6 +20,10 @@ class SetMyCommands(TelegramMethod[bool]): commands: List[BotCommand] """A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.""" + scope: Optional[BotCommandScope] = None + """A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.""" + language_code: Optional[str] = None + """A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands""" def build_request(self, bot: Bot) -> Request: data: Dict[str, Any] = self.dict() diff --git a/aiogram/methods/unban_chat_member.py b/aiogram/methods/unban_chat_member.py index cae62f8e..993335cf 100644 --- a/aiogram/methods/unban_chat_member.py +++ b/aiogram/methods/unban_chat_member.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: # pragma: no cover class UnbanChatMember(TelegramMethod[bool]): """ - Use this method to unban a previously kicked 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. + 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 """ diff --git a/aiogram/types/__init__.py b/aiogram/types/__init__.py index eb4c2c55..bfa7d6f8 100644 --- a/aiogram/types/__init__.py +++ b/aiogram/types/__init__.py @@ -2,12 +2,26 @@ from .animation import Animation from .audio import Audio from .base import UNSET, TelegramObject from .bot_command import BotCommand +from .bot_command_scope import BotCommandScope +from .bot_command_scope_all_chat_administrators import BotCommandScopeAllChatAdministrators +from .bot_command_scope_all_group_chats import BotCommandScopeAllGroupChats +from .bot_command_scope_all_private_chats import BotCommandScopeAllPrivateChats +from .bot_command_scope_chat import BotCommandScopeChat +from .bot_command_scope_chat_administrators import BotCommandScopeChatAdministrators +from .bot_command_scope_chat_member import BotCommandScopeChatMember +from .bot_command_scope_default import BotCommandScopeDefault from .callback_game import CallbackGame from .callback_query import CallbackQuery from .chat import Chat from .chat_invite_link import ChatInviteLink from .chat_location import ChatLocation from .chat_member import ChatMember +from .chat_member_administrator import ChatMemberAdministrator +from .chat_member_banned import ChatMemberBanned +from .chat_member_left import ChatMemberLeft +from .chat_member_member import ChatMemberMember +from .chat_member_owner import ChatMemberOwner +from .chat_member_restricted import ChatMemberRestricted from .chat_member_updated import ChatMemberUpdated from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto @@ -160,10 +174,24 @@ __all__ = ( "ChatPhoto", "ChatInviteLink", "ChatMember", + "ChatMemberOwner", + "ChatMemberAdministrator", + "ChatMemberMember", + "ChatMemberRestricted", + "ChatMemberLeft", + "ChatMemberBanned", "ChatMemberUpdated", "ChatPermissions", "ChatLocation", "BotCommand", + "BotCommandScope", + "BotCommandScopeDefault", + "BotCommandScopeAllPrivateChats", + "BotCommandScopeAllGroupChats", + "BotCommandScopeAllChatAdministrators", + "BotCommandScopeChat", + "BotCommandScopeChatAdministrators", + "BotCommandScopeChatMember", "ResponseParameters", "InputMedia", "InputMediaPhoto", diff --git a/aiogram/types/bot_command_scope.py b/aiogram/types/bot_command_scope.py new file mode 100644 index 00000000..dfb1d528 --- /dev/null +++ b/aiogram/types/bot_command_scope.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from .base import TelegramObject + + +class BotCommandScope(TelegramObject): + """ + This object represents the scope to which bot commands are applied. Currently, the following 7 scopes are supported: + + - :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault` + - :class:`aiogram.types.bot_command_scope_all_private_chats.BotCommandScopeAllPrivateChats` + - :class:`aiogram.types.bot_command_scope_all_group_chats.BotCommandScopeAllGroupChats` + - :class:`aiogram.types.bot_command_scope_all_chat_administrators.BotCommandScopeAllChatAdministrators` + - :class:`aiogram.types.bot_command_scope_chat.BotCommandScopeChat` + - :class:`aiogram.types.bot_command_scope_chat_administrators.BotCommandScopeChatAdministrators` + - :class:`aiogram.types.bot_command_scope_chat_member.BotCommandScopeChatMember` + + Source: https://core.telegram.org/bots/api#botcommandscope + """ diff --git a/aiogram/types/bot_command_scope_all_chat_administrators.py b/aiogram/types/bot_command_scope_all_chat_administrators.py new file mode 100644 index 00000000..25a35cbf --- /dev/null +++ b/aiogram/types/bot_command_scope_all_chat_administrators.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from pydantic import Field + +from .bot_command_scope import BotCommandScope + + +class BotCommandScopeAllChatAdministrators(BotCommandScope): + """ + Represents the `scope `_ of bot commands, covering all group and supergroup chat administrators. + + Source: https://core.telegram.org/bots/api#botcommandscopeallchatadministrators + """ + + type: str = Field("all_chat_administrators", const=True) + """Scope type, must be *all_chat_administrators*""" diff --git a/aiogram/types/bot_command_scope_all_group_chats.py b/aiogram/types/bot_command_scope_all_group_chats.py new file mode 100644 index 00000000..00e2984e --- /dev/null +++ b/aiogram/types/bot_command_scope_all_group_chats.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from pydantic import Field + +from .bot_command_scope import BotCommandScope + + +class BotCommandScopeAllGroupChats(BotCommandScope): + """ + Represents the `scope `_ of bot commands, covering all group and supergroup chats. + + Source: https://core.telegram.org/bots/api#botcommandscopeallgroupchats + """ + + type: str = Field("all_group_chats", const=True) + """Scope type, must be *all_group_chats*""" diff --git a/aiogram/types/bot_command_scope_all_private_chats.py b/aiogram/types/bot_command_scope_all_private_chats.py new file mode 100644 index 00000000..debc3baf --- /dev/null +++ b/aiogram/types/bot_command_scope_all_private_chats.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from pydantic import Field + +from .bot_command_scope import BotCommandScope + + +class BotCommandScopeAllPrivateChats(BotCommandScope): + """ + Represents the `scope `_ of bot commands, covering all private chats. + + Source: https://core.telegram.org/bots/api#botcommandscopeallprivatechats + """ + + type: str = Field("all_private_chats", const=True) + """Scope type, must be *all_private_chats*""" diff --git a/aiogram/types/bot_command_scope_chat.py b/aiogram/types/bot_command_scope_chat.py new file mode 100644 index 00000000..5d89c046 --- /dev/null +++ b/aiogram/types/bot_command_scope_chat.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import Union + +from pydantic import Field + +from .bot_command_scope import BotCommandScope + + +class BotCommandScopeChat(BotCommandScope): + """ + Represents the `scope `_ of bot commands, covering a specific chat. + + Source: https://core.telegram.org/bots/api#botcommandscopechat + """ + + type: str = Field("chat", const=True) + """Scope type, must be *chat*""" + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" diff --git a/aiogram/types/bot_command_scope_chat_administrators.py b/aiogram/types/bot_command_scope_chat_administrators.py new file mode 100644 index 00000000..152eab13 --- /dev/null +++ b/aiogram/types/bot_command_scope_chat_administrators.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import Union + +from pydantic import Field + +from .bot_command_scope import BotCommandScope + + +class BotCommandScopeChatAdministrators(BotCommandScope): + """ + Represents the `scope `_ of bot commands, covering all administrators of a specific group or supergroup chat. + + Source: https://core.telegram.org/bots/api#botcommandscopechatadministrators + """ + + type: str = Field("chat_administrators", const=True) + """Scope type, must be *chat_administrators*""" + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" diff --git a/aiogram/types/bot_command_scope_chat_member.py b/aiogram/types/bot_command_scope_chat_member.py new file mode 100644 index 00000000..e69ff642 --- /dev/null +++ b/aiogram/types/bot_command_scope_chat_member.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from typing import Union + +from pydantic import Field + +from .bot_command_scope import BotCommandScope + + +class BotCommandScopeChatMember(BotCommandScope): + """ + Represents the `scope `_ of bot commands, covering a specific member of a group or supergroup chat. + + Source: https://core.telegram.org/bots/api#botcommandscopechatmember + """ + + type: str = Field("chat_member", const=True) + """Scope type, must be *chat_member*""" + chat_id: Union[int, str] + """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" + user_id: int + """Unique identifier of the target user""" diff --git a/aiogram/types/bot_command_scope_default.py b/aiogram/types/bot_command_scope_default.py new file mode 100644 index 00000000..8cf1a1d5 --- /dev/null +++ b/aiogram/types/bot_command_scope_default.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from pydantic import Field + +from .bot_command_scope import BotCommandScope + + +class BotCommandScopeDefault(BotCommandScope): + """ + Represents the default `scope `_ of bot commands. Default commands are used if no commands with a `narrower scope `_ are specified for the user. + + Source: https://core.telegram.org/bots/api#botcommandscopedefault + """ + + type: str = Field("default", const=True) + """Scope type, must be *default*""" diff --git a/aiogram/types/chat_member.py b/aiogram/types/chat_member.py index 4a1abc8b..018bebda 100644 --- a/aiogram/types/chat_member.py +++ b/aiogram/types/chat_member.py @@ -1,87 +1,18 @@ from __future__ import annotations -import datetime -from typing import TYPE_CHECKING, Optional, Union - -from aiogram.utils import helper - from .base import TelegramObject -if TYPE_CHECKING: # pragma: no cover - from .user import User - class ChatMember(TelegramObject): """ - This object contains information about one member of a chat. + This object contains information about one member of a chat. Currently, the following 6 types of chat members are supported: + + - :class:`aiogram.types.chat_member_owner.ChatMemberOwner` + - :class:`aiogram.types.chat_member_administrator.ChatMemberAdministrator` + - :class:`aiogram.types.chat_member_member.ChatMemberMember` + - :class:`aiogram.types.chat_member_restricted.ChatMemberRestricted` + - :class:`aiogram.types.chat_member_left.ChatMemberLeft` + - :class:`aiogram.types.chat_member_banned.ChatMemberBanned` Source: https://core.telegram.org/bots/api#chatmember """ - - user: User - """Information about the user""" - status: str - """The member's status in the chat. Can be 'creator', 'administrator', 'member', 'restricted', 'left' or 'kicked'""" - custom_title: Optional[str] = None - """*Optional*. Owner and administrators only. Custom title for this user""" - is_anonymous: Optional[bool] = None - """*Optional*. Owner and administrators only. True, if the user's presence in the chat is hidden""" - can_be_edited: Optional[bool] = None - """*Optional*. Administrators only. True, if the bot is allowed to edit administrator privileges of that user""" - can_manage_chat: Optional[bool] = None - """*Optional*. Administrators only. 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""" - can_post_messages: Optional[bool] = None - """*Optional*. Administrators only. True, if the administrator can post in the channel; channels only""" - can_edit_messages: Optional[bool] = None - """*Optional*. Administrators only. True, if the administrator can edit messages of other users and can pin messages; channels only""" - can_delete_messages: Optional[bool] = None - """*Optional*. Administrators only. True, if the administrator can delete messages of other users""" - can_manage_voice_chats: Optional[bool] = None - """*Optional*. Administrators only. True, if the administrator can manage voice chats""" - can_restrict_members: Optional[bool] = None - """*Optional*. Administrators only. True, if the administrator can restrict, ban or unban chat members""" - can_promote_members: Optional[bool] = None - """*Optional*. Administrators only. 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 the user)""" - can_change_info: Optional[bool] = None - """*Optional*. Administrators and restricted only. True, if the user is allowed to change the chat title, photo and other settings""" - can_invite_users: Optional[bool] = None - """*Optional*. Administrators and restricted only. True, if the user is allowed to invite new users to the chat""" - can_pin_messages: Optional[bool] = None - """*Optional*. Administrators and restricted only. True, if the user is allowed to pin messages; groups and supergroups only""" - is_member: Optional[bool] = None - """*Optional*. Restricted only. True, if the user is a member of the chat at the moment of the request""" - can_send_messages: Optional[bool] = None - """*Optional*. Restricted only. True, if the user is allowed to send text messages, contacts, locations and venues""" - can_send_media_messages: Optional[bool] = None - """*Optional*. Restricted only. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes""" - can_send_polls: Optional[bool] = None - """*Optional*. Restricted only. True, if the user is allowed to send polls""" - can_send_other_messages: Optional[bool] = None - """*Optional*. Restricted only. True, if the user is allowed to send animations, games, stickers and use inline bots""" - can_add_web_page_previews: Optional[bool] = None - """*Optional*. Restricted only. True, if the user is allowed to add web page previews to their messages""" - until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None - """*Optional*. Restricted and kicked only. Date when restrictions will be lifted for this user; unix time""" - - @property - def is_chat_admin(self) -> bool: - return self.status in {ChatMemberStatus.CREATOR, ChatMemberStatus.ADMINISTRATOR} - - @property - def is_chat_member(self) -> bool: - return self.status not in {ChatMemberStatus.LEFT, ChatMemberStatus.KICKED} - - -class ChatMemberStatus(helper.Helper): - """ - Chat member status - """ - - mode = helper.HelperMode.lowercase - - CREATOR = helper.Item() # creator - ADMINISTRATOR = helper.Item() # administrator - MEMBER = helper.Item() # member - RESTRICTED = helper.Item() # restricted - LEFT = helper.Item() # left - KICKED = helper.Item() # kicked diff --git a/aiogram/types/chat_member_administrator.py b/aiogram/types/chat_member_administrator.py new file mode 100644 index 00000000..f25818c2 --- /dev/null +++ b/aiogram/types/chat_member_administrator.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .chat_member import ChatMember + +if TYPE_CHECKING: # pragma: no cover + from .user import User + + +class ChatMemberAdministrator(ChatMember): + """ + Represents a `chat member `_ that has some additional privileges. + + Source: https://core.telegram.org/bots/api#chatmemberadministrator + """ + + status: str = Field("administrator", const=True) + """The member's status in the chat, always 'administrator'""" + user: User + """Information about the user""" + can_be_edited: bool + """True, if the bot is allowed to edit administrator privileges of that user""" + is_anonymous: bool + """True, if the user's presence in the chat is hidden""" + can_manage_chat: bool + """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""" + can_delete_messages: bool + """True, if the administrator can delete messages of other users""" + can_manage_voice_chats: bool + """True, if the administrator can manage voice chats""" + can_restrict_members: bool + """True, if the administrator can restrict, ban or unban chat members""" + can_promote_members: bool + """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 the user)""" + can_change_info: bool + """True, if the user is allowed to change the chat title, photo and other settings""" + can_invite_users: bool + """True, if the user is allowed to invite new users to the chat""" + can_post_messages: Optional[bool] = None + """*Optional*. True, if the administrator can post in the channel; channels only""" + can_edit_messages: Optional[bool] = None + """*Optional*. True, if the administrator can edit messages of other users and can pin messages; channels only""" + can_pin_messages: Optional[bool] = None + """*Optional*. True, if the user is allowed to pin messages; groups and supergroups only""" + custom_title: Optional[str] = None + """*Optional*. Custom title for this user""" diff --git a/aiogram/types/chat_member_banned.py b/aiogram/types/chat_member_banned.py new file mode 100644 index 00000000..3b828247 --- /dev/null +++ b/aiogram/types/chat_member_banned.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +import datetime +from typing import TYPE_CHECKING, Union + +from pydantic import Field + +from .chat_member import ChatMember + +if TYPE_CHECKING: # pragma: no cover + from .user import User + + +class ChatMemberBanned(ChatMember): + """ + Represents a `chat member `_ that was banned in the chat and can't return to the chat or view chat messages. + + Source: https://core.telegram.org/bots/api#chatmemberbanned + """ + + status: str = Field("kicked", const=True) + """The member's status in the chat, always 'kicked'""" + user: User + """Information about the user""" + until_date: Union[datetime.datetime, datetime.timedelta, int] + """Date when restrictions will be lifted for this user; unix time""" diff --git a/aiogram/types/chat_member_left.py b/aiogram/types/chat_member_left.py new file mode 100644 index 00000000..d95cd320 --- /dev/null +++ b/aiogram/types/chat_member_left.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from pydantic import Field + +from .chat_member import ChatMember + +if TYPE_CHECKING: # pragma: no cover + from .user import User + + +class ChatMemberLeft(ChatMember): + """ + Represents a `chat member `_ that isn't currently a member of the chat, but may join it themselves. + + Source: https://core.telegram.org/bots/api#chatmemberleft + """ + + status: str = Field("left", const=True) + """The member's status in the chat, always 'left'""" + user: User + """Information about the user""" diff --git a/aiogram/types/chat_member_member.py b/aiogram/types/chat_member_member.py new file mode 100644 index 00000000..2c55ea62 --- /dev/null +++ b/aiogram/types/chat_member_member.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from pydantic import Field + +from .chat_member import ChatMember + +if TYPE_CHECKING: # pragma: no cover + from .user import User + + +class ChatMemberMember(ChatMember): + """ + Represents a `chat member `_ that has no additional privileges or restrictions. + + Source: https://core.telegram.org/bots/api#chatmembermember + """ + + status: str = Field("member", const=True) + """The member's status in the chat, always 'member'""" + user: User + """Information about the user""" diff --git a/aiogram/types/chat_member_owner.py b/aiogram/types/chat_member_owner.py new file mode 100644 index 00000000..dcc766a5 --- /dev/null +++ b/aiogram/types/chat_member_owner.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + +from pydantic import Field + +from .chat_member import ChatMember + +if TYPE_CHECKING: # pragma: no cover + from .user import User + + +class ChatMemberOwner(ChatMember): + """ + Represents a `chat member `_ that owns the chat and has all administrator privileges. + + Source: https://core.telegram.org/bots/api#chatmemberowner + """ + + status: str = Field("creator", const=True) + """The member's status in the chat, always 'creator'""" + user: User + """Information about the user""" + is_anonymous: bool + """True, if the user's presence in the chat is hidden""" + custom_title: Optional[str] = None + """*Optional*. Custom title for this user""" diff --git a/aiogram/types/chat_member_restricted.py b/aiogram/types/chat_member_restricted.py new file mode 100644 index 00000000..6860b8d0 --- /dev/null +++ b/aiogram/types/chat_member_restricted.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +import datetime +from typing import TYPE_CHECKING, Union + +from pydantic import Field + +from .chat_member import ChatMember + +if TYPE_CHECKING: # pragma: no cover + from .user import User + + +class ChatMemberRestricted(ChatMember): + """ + Represents a `chat member `_ that is under certain restrictions in the chat. Supergroups only. + + Source: https://core.telegram.org/bots/api#chatmemberrestricted + """ + + status: str = Field("restricted", const=True) + """The member's status in the chat, always 'restricted'""" + user: User + """Information about the user""" + is_member: bool + """True, if the user is a member of the chat at the moment of the request""" + can_change_info: bool + """True, if the user is allowed to change the chat title, photo and other settings""" + can_invite_users: bool + """True, if the user is allowed to invite new users to the chat""" + can_pin_messages: bool + """True, if the user is allowed to pin messages; groups and supergroups only""" + can_send_messages: bool + """True, if the user is allowed to send text messages, contacts, locations and venues""" + can_send_media_messages: bool + """True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes""" + can_send_polls: bool + """True, if the user is allowed to send polls""" + can_send_other_messages: bool + """True, if the user is allowed to send animations, games, stickers and use inline bots""" + can_add_web_page_previews: bool + """True, if the user is allowed to add web page previews to their messages""" + until_date: Union[datetime.datetime, datetime.timedelta, int] + """Date when restrictions will be lifted for this user; unix time""" diff --git a/aiogram/types/force_reply.py b/aiogram/types/force_reply.py index 9c29d130..b69ad94c 100644 --- a/aiogram/types/force_reply.py +++ b/aiogram/types/force_reply.py @@ -21,5 +21,7 @@ class ForceReply(MutableTelegramObject): force_reply: bool """Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply'""" + input_field_placeholder: Optional[str] = None + """*Optional*. The placeholder to be shown in the input field when the reply is active; 1-64 characters""" selective: Optional[bool] = None """*Optional*. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the *text* of the :class:`aiogram.types.message.Message` object; 2) if the bot's message is a reply (has *reply_to_message_id*), sender of the original message.""" diff --git a/aiogram/types/reply_keyboard_markup.py b/aiogram/types/reply_keyboard_markup.py index 33c364d0..dfbd46ed 100644 --- a/aiogram/types/reply_keyboard_markup.py +++ b/aiogram/types/reply_keyboard_markup.py @@ -21,5 +21,7 @@ class ReplyKeyboardMarkup(MutableTelegramObject): """*Optional*. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to *false*, in which case the custom keyboard is always of the same height as the app's standard keyboard.""" one_time_keyboard: Optional[bool] = None """*Optional*. Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat – the user can press a special button in the input field to see the custom keyboard again. Defaults to *false*.""" + input_field_placeholder: Optional[str] = None + """*Optional*. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters""" selective: Optional[bool] = None """*Optional*. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the *text* of the :class:`aiogram.types.message.Message` object; 2) if the bot's message is a reply (has *reply_to_message_id*), sender of the original message.""" diff --git a/docs/api/methods/ban_chat_member.rst b/docs/api/methods/ban_chat_member.rst new file mode 100644 index 00000000..0f8edf8b --- /dev/null +++ b/docs/api/methods/ban_chat_member.rst @@ -0,0 +1,51 @@ +############# +banChatMember +############# + +Returns: :obj:`bool` + +.. automodule:: aiogram.methods.ban_chat_member + :members: + :member-order: bysource + :undoc-members: True + + +Usage +===== + +As bot method +------------- + +.. code-block:: + + result: bool = await bot.ban_chat_member(...) + + +Method as object +---------------- + +Imports: + +- :code:`from aiogram.methods.ban_chat_member import BanChatMember` +- alias: :code:`from aiogram.methods import BanChatMember` + +In handlers with current bot +---------------------------- + +.. code-block:: python + + result: bool = await BanChatMember(...) + +With specific bot +~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + result: bool = await bot(BanChatMember(...)) + +As reply into Webhook in handler +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + return BanChatMember(...) diff --git a/docs/api/methods/delete_my_commands.rst b/docs/api/methods/delete_my_commands.rst new file mode 100644 index 00000000..5077f68c --- /dev/null +++ b/docs/api/methods/delete_my_commands.rst @@ -0,0 +1,51 @@ +################ +deleteMyCommands +################ + +Returns: :obj:`bool` + +.. automodule:: aiogram.methods.delete_my_commands + :members: + :member-order: bysource + :undoc-members: True + + +Usage +===== + +As bot method +------------- + +.. code-block:: + + result: bool = await bot.delete_my_commands(...) + + +Method as object +---------------- + +Imports: + +- :code:`from aiogram.methods.delete_my_commands import DeleteMyCommands` +- alias: :code:`from aiogram.methods import DeleteMyCommands` + +In handlers with current bot +---------------------------- + +.. code-block:: python + + result: bool = await DeleteMyCommands(...) + +With specific bot +~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + result: bool = await bot(DeleteMyCommands(...)) + +As reply into Webhook in handler +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + return DeleteMyCommands(...) diff --git a/docs/api/methods/get_chat_member_count.rst b/docs/api/methods/get_chat_member_count.rst new file mode 100644 index 00000000..2bee4cd9 --- /dev/null +++ b/docs/api/methods/get_chat_member_count.rst @@ -0,0 +1,44 @@ +################## +getChatMemberCount +################## + +Returns: :obj:`int` + +.. automodule:: aiogram.methods.get_chat_member_count + :members: + :member-order: bysource + :undoc-members: True + + +Usage +===== + +As bot method +------------- + +.. code-block:: + + result: int = await bot.get_chat_member_count(...) + + +Method as object +---------------- + +Imports: + +- :code:`from aiogram.methods.get_chat_member_count import GetChatMemberCount` +- alias: :code:`from aiogram.methods import GetChatMemberCount` + +In handlers with current bot +---------------------------- + +.. code-block:: python + + result: int = await GetChatMemberCount(...) + +With specific bot +~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + result: int = await bot(GetChatMemberCount(...)) diff --git a/docs/api/methods/index.rst b/docs/api/methods/index.rst index 94c08366..22fbff3e 100644 --- a/docs/api/methods/index.rst +++ b/docs/api/methods/index.rst @@ -48,6 +48,7 @@ Available methods send_chat_action get_user_profile_photos get_file + ban_chat_member kick_chat_member unban_chat_member restrict_chat_member @@ -68,12 +69,14 @@ Available methods leave_chat get_chat get_chat_administrators + get_chat_member_count get_chat_members_count get_chat_member set_chat_sticker_set delete_chat_sticker_set answer_callback_query set_my_commands + delete_my_commands get_my_commands Updating messages diff --git a/docs/api/types/bot_command_scope.rst b/docs/api/types/bot_command_scope.rst new file mode 100644 index 00000000..fa89f3ab --- /dev/null +++ b/docs/api/types/bot_command_scope.rst @@ -0,0 +1,9 @@ +############### +BotCommandScope +############### + + +.. automodule:: aiogram.types.bot_command_scope + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/bot_command_scope_all_chat_administrators.rst b/docs/api/types/bot_command_scope_all_chat_administrators.rst new file mode 100644 index 00000000..cfde1f73 --- /dev/null +++ b/docs/api/types/bot_command_scope_all_chat_administrators.rst @@ -0,0 +1,9 @@ +#################################### +BotCommandScopeAllChatAdministrators +#################################### + + +.. automodule:: aiogram.types.bot_command_scope_all_chat_administrators + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/bot_command_scope_all_group_chats.rst b/docs/api/types/bot_command_scope_all_group_chats.rst new file mode 100644 index 00000000..2fe3ec7a --- /dev/null +++ b/docs/api/types/bot_command_scope_all_group_chats.rst @@ -0,0 +1,9 @@ +############################ +BotCommandScopeAllGroupChats +############################ + + +.. automodule:: aiogram.types.bot_command_scope_all_group_chats + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/bot_command_scope_all_private_chats.rst b/docs/api/types/bot_command_scope_all_private_chats.rst new file mode 100644 index 00000000..4c018322 --- /dev/null +++ b/docs/api/types/bot_command_scope_all_private_chats.rst @@ -0,0 +1,9 @@ +############################## +BotCommandScopeAllPrivateChats +############################## + + +.. automodule:: aiogram.types.bot_command_scope_all_private_chats + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/bot_command_scope_chat.rst b/docs/api/types/bot_command_scope_chat.rst new file mode 100644 index 00000000..ee7900fc --- /dev/null +++ b/docs/api/types/bot_command_scope_chat.rst @@ -0,0 +1,9 @@ +################### +BotCommandScopeChat +################### + + +.. automodule:: aiogram.types.bot_command_scope_chat + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/bot_command_scope_chat_administrators.rst b/docs/api/types/bot_command_scope_chat_administrators.rst new file mode 100644 index 00000000..76e72c45 --- /dev/null +++ b/docs/api/types/bot_command_scope_chat_administrators.rst @@ -0,0 +1,9 @@ +################################# +BotCommandScopeChatAdministrators +################################# + + +.. automodule:: aiogram.types.bot_command_scope_chat_administrators + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/bot_command_scope_chat_member.rst b/docs/api/types/bot_command_scope_chat_member.rst new file mode 100644 index 00000000..60a76fa1 --- /dev/null +++ b/docs/api/types/bot_command_scope_chat_member.rst @@ -0,0 +1,9 @@ +######################### +BotCommandScopeChatMember +######################### + + +.. automodule:: aiogram.types.bot_command_scope_chat_member + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/bot_command_scope_default.rst b/docs/api/types/bot_command_scope_default.rst new file mode 100644 index 00000000..fe97331b --- /dev/null +++ b/docs/api/types/bot_command_scope_default.rst @@ -0,0 +1,9 @@ +###################### +BotCommandScopeDefault +###################### + + +.. automodule:: aiogram.types.bot_command_scope_default + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/chat_member_administrator.rst b/docs/api/types/chat_member_administrator.rst new file mode 100644 index 00000000..55302054 --- /dev/null +++ b/docs/api/types/chat_member_administrator.rst @@ -0,0 +1,9 @@ +####################### +ChatMemberAdministrator +####################### + + +.. automodule:: aiogram.types.chat_member_administrator + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/chat_member_banned.rst b/docs/api/types/chat_member_banned.rst new file mode 100644 index 00000000..31570bec --- /dev/null +++ b/docs/api/types/chat_member_banned.rst @@ -0,0 +1,9 @@ +################ +ChatMemberBanned +################ + + +.. automodule:: aiogram.types.chat_member_banned + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/chat_member_left.rst b/docs/api/types/chat_member_left.rst new file mode 100644 index 00000000..52a4dd9d --- /dev/null +++ b/docs/api/types/chat_member_left.rst @@ -0,0 +1,9 @@ +############## +ChatMemberLeft +############## + + +.. automodule:: aiogram.types.chat_member_left + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/chat_member_member.rst b/docs/api/types/chat_member_member.rst new file mode 100644 index 00000000..8f884af9 --- /dev/null +++ b/docs/api/types/chat_member_member.rst @@ -0,0 +1,9 @@ +################ +ChatMemberMember +################ + + +.. automodule:: aiogram.types.chat_member_member + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/chat_member_owner.rst b/docs/api/types/chat_member_owner.rst new file mode 100644 index 00000000..09eee65c --- /dev/null +++ b/docs/api/types/chat_member_owner.rst @@ -0,0 +1,9 @@ +############### +ChatMemberOwner +############### + + +.. automodule:: aiogram.types.chat_member_owner + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/chat_member_restricted.rst b/docs/api/types/chat_member_restricted.rst new file mode 100644 index 00000000..dcc3db58 --- /dev/null +++ b/docs/api/types/chat_member_restricted.rst @@ -0,0 +1,9 @@ +#################### +ChatMemberRestricted +#################### + + +.. automodule:: aiogram.types.chat_member_restricted + :members: + :member-order: bysource + :undoc-members: True diff --git a/docs/api/types/index.rst b/docs/api/types/index.rst index 2e3b3812..2309261b 100644 --- a/docs/api/types/index.rst +++ b/docs/api/types/index.rst @@ -60,10 +60,24 @@ Available types chat_photo chat_invite_link chat_member + chat_member_owner + chat_member_administrator + chat_member_member + chat_member_restricted + chat_member_left + chat_member_banned chat_member_updated chat_permissions chat_location bot_command + bot_command_scope + bot_command_scope_default + bot_command_scope_all_private_chats + bot_command_scope_all_group_chats + bot_command_scope_all_chat_administrators + bot_command_scope_chat + bot_command_scope_chat_administrators + bot_command_scope_chat_member response_parameters input_media input_media_photo diff --git a/docs/dispatcher/finite_state_machine/storages.rst b/docs/dispatcher/finite_state_machine/storages.rst new file mode 100644 index 00000000..f2fefe41 --- /dev/null +++ b/docs/dispatcher/finite_state_machine/storages.rst @@ -0,0 +1,23 @@ +######## +Storages +######## + +Storages out of the box +======================= + +MemoryStorage +------------- + +.. autoclass:: aiogram.dispatcher.fsm.storage.memory.MemoryStorage + :members: __init__, from_url + :member-order: bysource + +RedisStorage +------------ + +.. autoclass:: aiogram.dispatcher.fsm.storage.redis.RedisStorage + :members: __init__, from_url + :member-order: bysource + +Writing own storages +====================