Skip to content

Commit e78ec73

Browse files
committed
Added get_similar_channels method
1 parent 8e251d2 commit e78ec73

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def get_title_list(s: str) -> list:
241241
get_group_call_stream_rtmp_url
242242
create_group_call
243243
get_group_call_stream_channels
244+
get_similar_channels
244245
""",
245246
users="""
246247
Users

pyrogram/methods/chats/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from .get_chat_members import GetChatMembers
3434
from .get_chat_members_count import GetChatMembersCount
3535
from .get_chat_online_count import GetChatOnlineCount
36+
from .get_similar_channels import GetSimilarChannels
3637
from .get_dialogs import GetDialogs
3738
from .get_dialogs_count import GetDialogsCount
3839
from .get_group_call_stream_channels import GetGroupCallStreamChannels
@@ -98,6 +99,7 @@ class Chats(
9899
MarkChatUnread,
99100
GetChatEventLog,
100101
GetChatOnlineCount,
102+
GetSimilarChannels,
101103
GetSendAsChats,
102104
SetSendAsChat,
103105
SetChatReaction,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import List
20+
from typing import Optional
21+
from typing import Union
22+
23+
import pyrogram
24+
from pyrogram import raw
25+
from pyrogram import types
26+
27+
28+
class GetSimilarChannels:
29+
async def get_similar_channels(
30+
self: "pyrogram.Client",
31+
chat_id: Union[int, str]
32+
) -> Optional[List["types.Chat"]]:
33+
"""Get similar channels.
34+
35+
.. include:: /_includes/usable-by/users.rst
36+
37+
Parameters:
38+
chat_id (``int`` | ``str``):
39+
Unique identifier (int) or username (str) of the target chat.
40+
41+
Returns:
42+
List of :obj:`~pyrogram.types.Chat`: On success, the list of channels is returned.
43+
44+
Example:
45+
.. code-block:: python
46+
47+
channels = await app.get_similar_channels(chat_id)
48+
print(channels)
49+
"""
50+
chat = await self.resolve_peer(chat_id)
51+
52+
if isinstance(chat, raw.types.InputPeerChannel):
53+
r = await self.invoke(
54+
raw.functions.channels.GetChannelRecommendations(
55+
channel=chat
56+
)
57+
)
58+
59+
return types.List([types.Chat._parse_channel_chat(self, chat) for chat in r.chats]) or None
60+
else:
61+
raise ValueError(f'The chat_id "{chat_id}" belongs to a user or chat')

0 commit comments

Comments
 (0)