-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (38 loc) · 1.49 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import logging
import tempfile
import telethon
from telethon import events
from config import *
client: telethon.client = telethon.TelegramClient('session_name', api_id, api_hash)
logging.basicConfig(level=logging.INFO)
@client.on(events.NewMessage(outgoing=True, pattern=r'(^\.getids (.*))|(^xd)'))
async def handler(event: events.newmessage.NewMessage.Event):
if "xd" in event.message.text:
group_id = event.chat_id
else:
group_id = event.pattern_match.group(2)
myself = await client.get_me()
chat_members_id = []
try:
users = await client.get_participants(int(group_id), aggressive=True)
for user in users:
if user.bot: # excluye a todos los bots de la lista
continue
if user.id == myself.id: # excluye su propia id de la lista
continue
chat_members_id.append(str(user.id))
except ValueError:
return await event.edit("no pude acceder a ese chat verifica que el ID sea correcto")
text = '\n'.join(chat_members_id)
with tempfile.NamedTemporaryFile("w+", suffix=".txt") as file:
file.write(text)
file.seek(0)
file.flush()
try:
await client.send_message("me", file=file.name)
except telethon.errors.rpcerrorlist.FilePartsInvalidError:
return await event.edit("no pude recolectar nada")
if __name__ == '__main__':
with client:
logging.info("Userbot inicido")
client.run_until_disconnected()