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