Skip to content

Commit e1a7169

Browse files
committed
Add experimental iter_invoke method
Credits: https://t.me/c/1220993104/1395231
1 parent b446247 commit e1a7169

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ def get_title_list(s: str) -> list:
433433
resolve_peer
434434
get_file
435435
save_file
436+
iter_invoke
436437
"""
437438
)
438439

pyrogram/methods/advanced/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
from .invoke import Invoke
20+
from .iter_invoke import IterInvoke
2021
from .resolve_peer import ResolvePeer
2122
from .save_file import SaveFile
2223

2324

2425
class Advanced(
2526
Invoke,
27+
IterInvoke,
2628
ResolvePeer,
2729
SaveFile
2830
):
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present <https://github.com/TelegramPlayGround>
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+
20+
from asyncio import sleep
21+
22+
import pyrogram
23+
from pyrogram.raw.core import TLObject
24+
25+
26+
class IterInvoke:
27+
async def iter_invoke(
28+
self: "pyrogram.Client",
29+
query: TLObject,
30+
key: str,
31+
):
32+
"""Invoke raw Telegram yield functions.
33+
34+
This method makes it possible to do bakchodi.
35+
36+
.. note::
37+
38+
This is a utility method intended to be used **only** when working with raw
39+
:obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
40+
available yet in the Client class as an easy-to-use method).
41+
42+
.. include:: /_includes/usable-by/users-bots.rst
43+
44+
Parameters:
45+
query (``RawFunction``):
46+
The API Schema function filled with proper arguments.
47+
48+
key (``str``):
49+
The key using which to yield the iterator.
50+
51+
Returns:
52+
``Generator``: A generator yielding the raw type response object generated by the query.
53+
54+
Raises:
55+
RPCError: In case of a Telegram RPC error.
56+
57+
"""
58+
59+
r = await self.invoke(query)
60+
s = getattr(r, key, [])
61+
for d in s:
62+
await sleep(0)
63+
yield d

0 commit comments

Comments
 (0)