diff --git a/bot/helpers/utils/auth_check.py b/bot/helpers/utils/auth_check.py index ba2360c..4f85c67 100644 --- a/bot/helpers/utils/auth_check.py +++ b/bot/helpers/utils/auth_check.py @@ -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 = "ALLOWED CHATS" - for chat in allowed_chats: + for chat in sorted(allowed_chats): msg += f"\n{chat}" msg += "\n\nALLOWED USERS" 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{user}" - except: - pass msg += "\n\nADMINS" - for admin in admins: + for admin in sorted(admins): msg += f"\n{admin}" 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 diff --git a/bot/modules/basics.py b/bot/modules/basics.py index 730944b..dd2c238 100644 --- a/bot/modules/basics.py +++ b/bot/modules/basics.py @@ -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))