Изменена структура из-за ограничений телеги

This commit is contained in:
Григорич 2022-02-15 18:30:40 +00:00
parent c271be3792
commit b4449eeda2

View File

@ -3,7 +3,6 @@ import config
from telethon.sync import TelegramClient
from telethon.tl.types import ChannelParticipantsAdmins
from telethon import functions, errors
api_id = config.api_id
api_hash = config.api_hash
session = 'session.session'
@ -70,12 +69,11 @@ async def check_chat(chat, type_link):
ch = await client.get_entity(res.chats[1])
count_members = await client(functions.channels.GetFullChannelRequest(channel=ch))
count_members = count_members.full_chat.participants_count
if count_members > 10000:
print(f'Количество участников чата "{ch.title}" насчитывает более 10 тысяч человек. Выбран "обычный" + "агрессивный" режим.')
aggressive = True
else:
print(f'Количество участников чата "{ch.title}" насчитывает менее 10 тысяч человек. Выбран "обычный" режим.')
aggressive = False
if count_members > 5000:
print(f'Количество участников чата "{ch.title}" насчитывает более 5 тысяч человек. Из-за ограничений Telegram, мы не можем получить весь список. '
f'Предлагаем выгрузить сообщения и получить список пользователей, которые хотя бы раз оставляли сообщение в чате.')
return {'status': 'error', 'error_type': 'too_many_users', 'ch': ch, 'channel_type': channel_type,
'channel_title': ch.title}
admins = []
titles = {}
async for user in client.iter_participants(ch, filter=ChannelParticipantsAdmins):
@ -86,18 +84,11 @@ async def check_chat(chat, type_link):
admins = None
else:
admins = list_users(admins, titles)
members = await client.get_participants(ch, aggressive=False)
members = await client.get_participants(ch)
if len(members) == 0:
members = None
else:
members = list_users(members)
if aggressive is True:
ag_members = await client.get_participants(ch, aggressive=True)
if len(ag_members) == 0:
ag_members = None
else:
ag_members = list_users(ag_members)
members = {**members, **ag_members}
if channel_type == 'Каналы':
limit = 3000
print(
@ -154,7 +145,9 @@ async def check_chat(chat, type_link):
users.append(user)
if channel_type != 'Каналы':
channel_title = ch.title
return members, admins, ch, users, channel_type, channel_title
return {'status': 'ok', 'members': members, 'admins': admins,
'ch': ch, 'users': users, 'channel_type': channel_type,
'channel_title': channel_title}
else:
print('Вы ввели ссылку, которая не ведёт на открытую группу. Попробуйте другую.')
return False
@ -168,6 +161,7 @@ async def dump_messages(chat, title):
with open(f'../Чаты/{title}/Сообщения {title}.txt', 'w', encoding='utf8') as file:
with open(f'../Чаты/{title}/Сообщения {title}.html', 'w', encoding='utf8') as f:
async for message in client.iter_messages(chat):
print(message)
file.write(f'{message}\n')
if message.media is not None:
f.write(
@ -215,4 +209,3 @@ def list_users(*args):
for key, value in titles.items():
users[key]['title'] = value
return users