diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index a5ce87e4..be726c44 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -222,6 +222,7 @@ def pyrogram_api(): set_slow_mode mark_chat_unread get_chat_event_log + get_chat_online_count """, users=""" Users diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 8aeb5fe4..31ffe4fd 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -53,6 +53,7 @@ from .unban_chat_member import UnbanChatMember from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_chat_username import UpdateChatUsername +from .get_chat_online_count import GetChatOnlineCount class Chats( @@ -92,6 +93,7 @@ class Chats( DeleteUserHistory, UnpinAllChatMessages, MarkChatUnread, - GetChatEventLog + GetChatEventLog, + GetChatOnlineCount ): pass diff --git a/pyrogram/methods/chats/get_chat_online_count.py b/pyrogram/methods/chats/get_chat_online_count.py new file mode 100644 index 00000000..5d3d861f --- /dev/null +++ b/pyrogram/methods/chats/get_chat_online_count.py @@ -0,0 +1,46 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Union + +from pyrogram import raw +from pyrogram.scaffold import Scaffold + + +class GetChatOnlineCount(Scaffold): + async def get_chat_online_count(self, chat_id: Union[int, str]) -> int: + """Get the number of members that are currently online in a chat. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + ``int``: On success, the chat members online count is returned. + + Example: + .. code-block:: python + + online = app.get_chat_online_count(chat_id) + print(online) + """ + return (await self.send( + raw.functions.messages.GetOnlines( + peer=await self.resolve_peer(chat_id) + ) + )).onlines