from .. import loader, utils
from telethon.tl.functions.messages import GetCommonChatsRequest
from telethon.tl.functions.users import GetFullUserRequest
def register(cb):
cb(GetCommonChatsMod())
class GetCommonChatsMod(loader.Module):
"""Общие чаты с пользователем."""
strings = {'name': 'GetCommonChats'}
async def commoncmd(self, message):
"""Используй .common <@ или реплай>, чтобы узнать общие чаты с пользователем."""
args = utils.get_args_raw(message)
reply = await message.get_reply_message()
if not args and not reply:
return await message.edit('Нет аргументов или реплая.')
await message.edit('Считаем...')
try:
if args:
if args.isnumeric():
user = int(args)
user = await message.client.get_entity(user)
else:
user = await message.client.get_entity(args)
else:
user = await utils.get_user(reply)
except ValueError:
return await message.edit('Не удалось найти пользователя.')
msg = f'Общие чаты с {user.first_name}:\n'
user = await message.client(GetFullUserRequest(user.id))
comm = await message.client(GetCommonChatsRequest(user_id=user.user.id, max_id=0, limit=100))
count = 0
m = ''
for chat in comm.chats:
m += f'\n• {chat.title} | {chat.id}'
count += 1
msg = f'Общие чаты с {user.user.first_name}: {count}\n'
await message.edit(f'{msg} {m}')