This repository has been archived on 2024-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
moderator-bot/utils/telegram_client.py

37 lines
1.0 KiB
Python
Raw Normal View History

2022-08-13 08:25:52 -04:00
from pyrogram.client import Client
2022-08-07 04:45:35 -04:00
2022-12-01 05:54:32 -05:00
2022-08-13 08:25:52 -04:00
class TelegramClient:
def __init__(self, api_id, api_hash, token):
2022-08-07 04:45:35 -04:00
self.api_id = api_id
self.api_hash = api_hash
self.token = token
2022-08-13 08:25:52 -04:00
self.client = Client("session",
api_id=self.api_id, api_hash=self.api_hash,
2022-08-13 08:25:52 -04:00
bot_token=self.token
)
2022-08-07 04:45:35 -04:00
async def members_list(self, chat_id: int):
2022-08-13 08:25:52 -04:00
members = []
2022-08-07 04:45:35 -04:00
2022-08-13 08:25:52 -04:00
async for member in self.client.get_chat_members(chat_id):
try:
username = member.user.username
except AttributeError:
username = None
2022-08-07 04:45:35 -04:00
2022-08-13 08:25:52 -04:00
if not (username is None):
username = f"@{username}"
2022-08-07 04:45:35 -04:00
2022-08-13 08:25:52 -04:00
if (not member.user.is_bot):
members.append({
"id": member.user.id,
"status": str(member.status),
"first_name": member.user.first_name,
"username": username,
})
2022-08-13 08:25:52 -04:00
return members