From dd32854db45a129fd0cfc8c759cedb53d83f710e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 12 May 2021 09:39:51 +0200 Subject: [PATCH] Squashed commit of the following: commit d6dcf98d7445cbdc2a036deca57207c14bc354fc Author: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed May 12 09:35:18 2021 +0200 Rename get_chat_onlines to get_chat_online_count commit 21ff2a39d856ebc939ce9b15810198c82a9c23c6 Merge: 808c629f 29701a3a Author: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed May 12 09:32:59 2021 +0200 Merge branch 'master' into get-chat-online-count commit 808c629f43b185bc0df8337a82f5ecc860bbdb94 Author: Andriel Rodrigues Date: Wed May 12 04:28:53 2021 -0300 Add get_chat_online_count method (todo) (#654) --- compiler/docs/compiler.py | 1 + pyrogram/methods/chats/__init__.py | 4 +- .../methods/chats/get_chat_online_count.py | 46 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/chats/get_chat_online_count.py 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