Skip to content

Instantly share code, notes, and snippets.

@x0x8x
Last active December 22, 2020 14:18
Show Gist options
  • Save x0x8x/3d194fed5cacdaa25f907730126932fa to your computer and use it in GitHub Desktop.
Save x0x8x/3d194fed5cacdaa25f907730126932fa to your computer and use it in GitHub Desktop.
fetch all users from the specific group and print their entities
import telethon
from telethon.errors.rpcerrorlist import FloodWaitError
import asyncio
e = event
bot = c = cl = app = client
csm = client.send_message
ecid = event.chat_id
members = []
chunk_size = 45
g = 1234567890
group = await c.get_entity(g)
glink = "[{}](t.me/c/{}/1)".format(str(group.title), str(group.id))
# for group in groups:
for m in list(await c.get_participants(g)):
if not m.deleted and not m.bot:
members.append(m)
for i in range(0, len(members), chunk_size):
try:
await csm(
ecid,
f"Participants of the chat {glink}\n"
+ "\n".join(
'`- {} "@{}" {}` [ [{}] ](tg://user?id={})'.format(
i.first_name if i.first_name is not None else "",
i.username if i.username is not None else "username",
i.last_name if i.last_name is not None else "",
i.id,
i.id,
)
.replace("\u200f", "")
.replace("\u200e", "")
.replace("\u200c", "")
.replace("\ud83e", "")
.replace("\u0634", "")
.replace('"@username"', "")
for i in members[i : i + chunk_size]
),
)
await asyncio.sleep(3)
except FloodWaitError as f:
await client.send_message(f"waiting {f.seconds} sec")
await asyncio.sleep(f.seconds + 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment