Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 21 additions & 41 deletions bot/helpers/utils/auth_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,47 @@
from bot.helpers.tidal_func.events import checkLoginTidal
from bot.helpers.database.postgres_impl import users_db, admins_db, chats_db, user_settings, set_db

allowed_chats = []
allowed_users = []
admins = []
allowed_chats: set[int] = set()
allowed_users: set[int] = set()
admins: set[int] = set()

# NOOB WAY TO HANDLE BOTH ENV AND DB XD

async def get_chats(return_msg=False):
# CHATS
database_chats = chats_db.get_chats()
for chat in Config.AUTH_CHAT:
if chat not in allowed_chats:
allowed_chats.append(chat)
for chat in database_chats:
if chat != None:
if chat[0] not in allowed_chats and chat[0] != None:
allowed_chats.append(chat[0])
# ADMINS
database_admins = admins_db.get_admins()
for admin in Config.ADMINS:
if admin not in admins:
admins.append(admin)
for admin in database_admins:
if admin != None:
if admin[0] not in admins and admin[0] != None:
admins.append(admin[0])
# USERS
if not Config.IS_BOT_PUBLIC == "True":
database_users = users_db.get_users()
if Config.AUTH_USERS == "":
pass
else:
for user in Config.AUTH_USERS:
if user not in allowed_users:
allowed_users.append(user)
for user in database_users:
if user != None:
if user[0] not in allowed_users and user[0] != None:
allowed_users.append(user[0])
database_chats = chats_db.get_chats() or []
allowed_chats.update(Config.AUTH_CHAT)
allowed_chats.update(chat[0] for chat in database_chats if chat and chat[0])

database_admins = admins_db.get_admins() or []
admins.update(Config.ADMINS)
admins.update(admin[0] for admin in database_admins if admin and admin[0])

if Config.IS_BOT_PUBLIC != "True":
database_users = users_db.get_users() or []
if Config.AUTH_USERS:
allowed_users.update(Config.AUTH_USERS)
allowed_users.update(user[0] for user in database_users if user and user[0])

if return_msg:
msg = "<b>ALLOWED CHATS</b>"
for chat in allowed_chats:
for chat in sorted(allowed_chats):
msg += f"\n<code>{chat}</code>"

msg += "\n\n<b>ALLOWED USERS</b>"
if Config.IS_BOT_PUBLIC == "True":
msg += "\nAllowed For Everyone"
try:
for user in allowed_users:
else:
for user in sorted(allowed_users):
msg += f"\n<code>{user}</code>"
except:
pass

msg += "\n\n<b>ADMINS</b>"
for admin in admins:
for admin in sorted(admins):
msg += f"\n<code>{admin}</code>"

return msg

async def check_id(id=None, message=None, restricted=False):
all_list = allowed_chats + allowed_users + admins
all_list = allowed_chats | allowed_users | admins
if restricted:
if id in admins:
return True
Expand Down
3 changes: 1 addition & 2 deletions bot/modules/basics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import asyncio
from bot import CMD
from pyrogram import Client, filters
from bot.helpers.translations import lang
from bot.helpers.utils.auth_check import get_chats
from bot.helpers.utils.auth_check import check_id, get_chats

from bot.helpers.database.postgres_impl import users_db, admins_db, chats_db

@Client.on_message(filters.command(CMD.START))
Expand Down