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
Raw Normal View History

2022-12-30 21:36:06 +02:00
from os import path, sep
from ujson import JSONDecodeError
2022-12-13 15:24:31 +02:00
from modules.logging import logWrite
2022-12-30 21:36:06 +02:00
from modules.utils import configGet, jsonLoad
2022-10-26 15:54:55 +03:00
from pyrogram.client import Client
2022-12-13 15:24:31 +02:00
from pyrogram.errors import bad_request_400
2023-03-26 20:32:07 +03:00
from convopyro import Conversation
2022-10-26 15:54:55 +03:00
2023-03-09 17:25:06 +02:00
app = Client(
"holochecker",
bot_token=configGet("bot_token", "bot"),
api_id=configGet("api_id", "bot"),
api_hash=configGet("api_hash", "bot"),
)
2022-10-26 15:54:55 +03:00
2023-03-26 20:32:07 +03:00
Conversation(app)
2023-01-03 14:17:59 +02:00
2023-03-09 17:25:06 +02:00
async def isAnAdmin(admin_id):
2023-01-03 14:17:59 +02:00
# Check if user is mentioned in config
2022-12-11 02:31:06 +02:00
if (admin_id == configGet("owner")) or (admin_id in configGet("admins")):
2022-10-26 15:54:55 +03:00
return True
2023-01-03 14:17:59 +02:00
# Check if user is probably in cache
2022-12-30 21:36:06 +02:00
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
2023-03-09 17:25:06 +02:00
2023-01-03 14:17:59 +02:00
# Check if user is in admin group
2022-12-13 15:24:31 +02:00
try:
2023-01-04 20:14:02 +02:00
async for member in app.get_chat_members(configGet("admin", "groups")):
2022-12-13 15:24:31 +02:00
if member.user.id == admin_id:
return True
except bad_request_400.ChannelInvalid:
2023-03-09 17:25:06 +02:00
logWrite(
f"Could not get users in admin group to answer isAnAdmin(). Bot is likely not in the group."
)
2022-12-13 15:24:31 +02:00
return False
2023-03-09 17:25:06 +02:00
return False