diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index d117dc70..1bf00d47 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -245,7 +245,8 @@ class Methods(Helper): LEAVE_CHAT = Item() # leaveChat GET_CHAT = Item() # getChat GET_CHAT_ADMINISTRATORS = Item() # getChatAdministrators - GET_CHAT_MEMBERS_COUNT = Item() # getChatMembersCount + GET_CHAT_MEMBER_COUNT = Item() # getChatMemberCount + GET_CHAT_MEMBERS_COUNT = Item() # getChatMembersCount (renamed to getChatMemberCount) GET_CHAT_MEMBER = Item() # getChatMember SET_CHAT_STICKER_SET = Item() # setChatStickerSet DELETE_CHAT_STICKER_SET = Item() # deleteChatStickerSet diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index 1ca4931a..27c4cb0f 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -2148,11 +2148,11 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.GET_CHAT_ADMINISTRATORS, payload) return [types.ChatMember(**chatmember) for chatmember in result] - async def get_chat_members_count(self, chat_id: typing.Union[base.Integer, base.String]) -> base.Integer: + async def get_chat_member_count(self, chat_id: typing.Union[base.Integer, base.String]) -> base.Integer: """ Use this method to get the number of members in a chat. - Source: https://core.telegram.org/bots/api#getchatmemberscount + Source: https://core.telegram.org/bots/api#getchatmembercount :param chat_id: Unique identifier for the target chat or username of the target supergroup or channel :type chat_id: :obj:`typing.Union[base.Integer, base.String]` @@ -2161,7 +2161,11 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): """ payload = generate_payload(**locals()) - return await self.request(api.Methods.GET_CHAT_MEMBERS_COUNT, payload) + return await self.request(api.Methods.GET_CHAT_MEMBER_COUNT, payload) + + async def get_chat_members_count(self, chat_id: typing.Union[base.Integer, base.String]) -> base.Integer: + """Renamed to get_chat_member_count.""" + return await self.get_chat_member_count(chat_id) async def get_chat_member(self, chat_id: typing.Union[base.Integer, base.String], user_id: base.Integer) -> types.ChatMember: diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 5b3b315a..2cd19a0f 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -301,7 +301,7 @@ class Chat(base.TelegramObject): can_send_other_messages=can_send_other_messages, can_add_web_page_previews=can_add_web_page_previews) - async def promote(self, + async def promote(self, user_id: base.Integer, is_anonymous: typing.Optional[base.Boolean] = None, can_change_info: typing.Optional[base.Boolean] = None, @@ -321,36 +321,36 @@ class Chat(base.TelegramObject): :param user_id: Unique identifier of the target user :type user_id: :obj:`base.Integer` - + :param is_anonymous: Pass True, if the administrator's presence in the chat is hidden :type is_anonymous: :obj:`typing.Optional[base.Boolean]` - + :param can_change_info: Pass True, if the administrator can change chat title, photo and other settings :type can_change_info: :obj:`typing.Optional[base.Boolean]` - + :param can_post_messages: Pass True, if the administrator can create channel posts, channels only :type can_post_messages: :obj:`typing.Optional[base.Boolean]` - + :param can_edit_messages: Pass True, if the administrator can edit messages of other users, channels only :type can_edit_messages: :obj:`typing.Optional[base.Boolean]` - + :param can_delete_messages: Pass True, if the administrator can delete messages of other users :type can_delete_messages: :obj:`typing.Optional[base.Boolean]` - + :param can_invite_users: Pass True, if the administrator can invite new users to the chat :type can_invite_users: :obj:`typing.Optional[base.Boolean]` - + :param can_restrict_members: Pass True, if the administrator can restrict, ban or unban chat members :type can_restrict_members: :obj:`typing.Optional[base.Boolean]` - + :param can_pin_messages: Pass True, if the administrator can pin messages, supergroups only :type can_pin_messages: :obj:`typing.Optional[base.Boolean]` - + :param can_promote_members: Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him) :type can_promote_members: :obj:`typing.Optional[base.Boolean]` - + :return: Returns True on success. :rtype: :obj:`base.Boolean` """ @@ -484,16 +484,20 @@ class Chat(base.TelegramObject): """ return await self.bot.get_chat_administrators(self.id) - async def get_members_count(self) -> base.Integer: + async def get_member_count(self) -> base.Integer: """ Use this method to get the number of members in a chat. - Source: https://core.telegram.org/bots/api#getchatmemberscount + Source: https://core.telegram.org/bots/api#getchatmembercount :return: Returns Int on success. :rtype: :obj:`base.Integer` """ - return await self.bot.get_chat_members_count(self.id) + return await self.bot.get_chat_member_count(self.id) + + async def get_members_count(self) -> base.Integer: + """Renamed to get_member_count.""" + return await self.get_member_count(self.id) async def get_member(self, user_id: base.Integer) -> ChatMember: """ diff --git a/tests/test_bot.py b/tests/test_bot.py index 224666ec..bc3a537c 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -435,14 +435,14 @@ async def test_get_chat_administrators(bot: Bot): assert len(result) == 2 -async def test_get_chat_members_count(bot: Bot): +async def test_get_chat_member_count(bot: Bot): """ getChatMembersCount method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) count = 5 async with FakeTelegram(message_data=count): - result = await bot.get_chat_members_count(chat_id=chat.id) + result = await bot.get_chat_member_count(chat_id=chat.id) assert result == count