2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-09-01 14:55:12 +00:00

Automatically handle flood waits when using get_chat_members

This commit is contained in:
Dan
2019-03-28 16:24:11 +01:00
parent e79f4fde80
commit fbe6af2fc6

View File

@@ -16,12 +16,17 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import logging
import time
from typing import Union from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.errors import FloodWait
from ...ext import BaseClient from ...ext import BaseClient
log = logging.getLogger(__name__)
class Filters: class Filters:
ALL = "all" ALL = "all"
@@ -116,17 +121,22 @@ class GetChatMembers(BaseClient):
else: else:
raise ValueError("Invalid filter \"{}\"".format(filter)) raise ValueError("Invalid filter \"{}\"".format(filter))
return pyrogram.ChatMembers._parse( while True:
self, try:
self.send( return pyrogram.ChatMembers._parse(
functions.channels.GetParticipants( self,
channel=peer, self.send(
filter=filter, functions.channels.GetParticipants(
offset=offset, channel=peer,
limit=limit, filter=filter,
hash=0 offset=offset,
limit=limit,
hash=0
)
)
) )
) except FloodWait as e:
) log.warning("Sleeping for {}s".format(e.x))
time.sleep(e.x)
else: else:
raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id))