Created
April 6, 2018 23:54
-
-
Save RomanGorbatko/dff4db59785d9403bdceff70cf6a2ab4 to your computer and use it in GitHub Desktop.
py.py
This file contains 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
import time | |
from pyrogram import Client | |
from pyrogram.api import functions, types | |
from pyrogram.api.errors import ( | |
BadRequest, Flood, InternalServerError, | |
SeeOther, Unauthorized, UnknownError | |
) | |
client = Client("example") | |
client.start() | |
target = "" # Target channel/supergroup | |
destination = 321 | |
users = [] # List that will contain all the users of the target chat | |
limit = 200 # Amount of users to retrieve for each API call | |
offset = 0 # Offset starts at 0 | |
ids = [] | |
while True: | |
try: | |
participants = client.send( | |
functions.channels.GetParticipants( | |
channel=client.resolve_peer(target), | |
filter=types.ChannelParticipantsSearch(""), # Filter by empty string (search for all) | |
offset=offset, | |
limit=limit, | |
hash=0 | |
) | |
) | |
except FloodWait as e: | |
# Very large channels will trigger FloodWait. | |
# When happens, wait X seconds before continuing | |
time.sleep(e.x) | |
continue | |
if not participants.participants: | |
break # No more participants left | |
for user in participants.users: | |
ids.append(client.resolve_peer(user.id)) | |
users.extend(participants.users) | |
offset += limit | |
try: | |
update = client.send( | |
functions.channels.InviteToChannel( | |
channel=client.resolve_peer(destination), | |
users=ids | |
) | |
) | |
print(update) | |
except BadRequest as e: | |
print(1, e) | |
except Flood as e: | |
print(2, e) | |
except InternalServerError as e: | |
print(3, e) | |
except SeeOther as e: | |
print(4, e) | |
except Unauthorized as e: | |
print(5, e) | |
except UnknownError as e: | |
print(6, e) | |
client.stop() | |
# Now the "users" list contains all the members of the target chat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment