Skip to content

Commit

Permalink
refactor: renamed getChatMembersCount to getChatMemberCount (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrohoi committed Jun 29, 2021
1 parent d242274 commit 1530904
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
3 changes: 2 additions & 1 deletion aiogram/bot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions aiogram/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,11 +2148,11 @@ async def get_chat_administrators(self, chat_id: typing.Union[base.Integer, base
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]`
Expand All @@ -2161,7 +2161,11 @@ async def get_chat_members_count(self, chat_id: typing.Union[base.Integer, base.
"""
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:
Expand Down
32 changes: 18 additions & 14 deletions aiogram/types/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ async def restrict(self, user_id: base.Integer,
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,
Expand All @@ -321,36 +321,36 @@ async def promote(self,
: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`
"""
Expand Down Expand Up @@ -484,16 +484,20 @@ async def get_administrators(self) -> typing.List[ChatMember]:
"""
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:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 1530904

Please sign in to comment.