This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/app.py

43 lines
1.3 KiB
Python

from os import path, sep
from ujson import JSONDecodeError
from modules.logging import logWrite
from modules.utils import configGet, jsonLoad
from pyrogram.client import Client
from pyrogram.errors import bad_request_400
from convopyro import Conversation
app = Client(
"holochecker",
bot_token=configGet("bot_token", "bot"),
api_id=configGet("api_id", "bot"),
api_hash=configGet("api_hash", "bot"),
)
Conversation(app)
async def isAnAdmin(admin_id):
# Check if user is mentioned in config
if (admin_id == configGet("owner")) or (admin_id in configGet("admins")):
return True
# Check if user is probably in cache
if path.exists(f"cache{sep}admins") is True:
try:
return True if admin_id in jsonLoad(f"cache{sep}admins") else False
except (FileNotFoundError, JSONDecodeError):
pass
# Check if user is in admin group
try:
async for member in app.get_chat_members(configGet("admin", "groups")):
if member.user.id == admin_id:
return True
except bad_request_400.ChannelInvalid:
logWrite(
f"Could not get users in admin group to answer isAnAdmin(). Bot is likely not in the group."
)
return False
return False