This repository was archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add get_chat_onlines method #654
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| # Pyrogram - Telegram MTProto API Client Library for Python | ||||||
| # Copyright (C) 2017-2021 Dan <https://github.com/delivrance> | ||||||
| # | ||||||
| # 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 <http://www.gnu.org/licenses/>. | ||||||
|
|
||||||
| from typing import Optional, Union | ||||||
|
|
||||||
| from pyrogram import raw | ||||||
| from pyrogram.scaffold import Scaffold | ||||||
|
|
||||||
|
|
||||||
| class GetChatOnlines(Scaffold): | ||||||
| async def get_chat_onlines( | ||||||
| self, | ||||||
| chat_id: Union[int, str] | ||||||
| ) -> Optional[int]: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function does not return None. Just int or raise an exception.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😳 |
||||||
| """Get count of online users 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. | ||||||
|
|
||||||
| Raises: | ||||||
| ValueError: In case a chat id belongs to user. | ||||||
|
|
||||||
| Example: | ||||||
| .. code-block:: python | ||||||
|
|
||||||
| onlines = app.get_chat_onlines("pyrogram") | ||||||
| print(onlines) | ||||||
| """ | ||||||
| peer = await self.resolve_peer(chat_id) | ||||||
|
|
||||||
| if isinstance(peer, (raw.types.InputPeerChat, raw.types.InputPeerChannel)): | ||||||
| r = await self.send( | ||||||
| raw.functions.messages.GetOnlines( | ||||||
| peer=peer | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| return r.onlines | ||||||
| else: | ||||||
| raise ValueError(f'The chat_id "{chat_id}" belongs to a user') | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import when applying the suggestion below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.