From 62e49dd8a57de7356c52dae8033d86d0e0e18f32 Mon Sep 17 00:00:00 2001 From: Itz-fork Date: Thu, 28 Dec 2023 13:32:55 +0530 Subject: [PATCH] fix: authorized users - added support for global mode (set AUTH_USERS to "*") - better authorization logic --- .env.sample | 2 +- megadl/helpers/mclient.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.env.sample b/.env.sample index 91acf417..e7c7521b 100644 --- a/.env.sample +++ b/.env.sample @@ -4,7 +4,7 @@ BOT_TOKEN=bot-token-from-@BotFather MEGA_EMAIL=yourname@gmail.com MEGA_PASSWORD=mypassword -AUTH_USERS=1340254734 +AUTH_USERS=* CIPHER_KEY=vJmDXO4xria6SYVcOfVYd3k3YM8WiiGBfRjbQ8MBsvI= USE_ENV=False diff --git a/megadl/helpers/mclient.py b/megadl/helpers/mclient.py index 03b0854a..b7887fc7 100644 --- a/megadl/helpers/mclient.py +++ b/megadl/helpers/mclient.py @@ -42,8 +42,8 @@ class MeganzClient(Client): database = Users() if os.getenv("MONGO_URI") else None auth_users = ( set(map(int, os.getenv("AUTH_USERS").split())) - if os.getenv("AUTH_USERS") - else None + if os.getenv("AUTH_USERS") and os.getenv("AUTH_USERS") != "*" + else "*" ) def __init__(self): @@ -118,20 +118,19 @@ def handle_checks(self, func: Callable) -> Callable: """ async def fn_run(client: Client, msg: Message): - is_auth = False + can_use = False uid = msg.from_user.id try: - if self.auth_users and self.database: + if self.database: await self.database.add(uid) - is_auth = uid in self.auth_users - elif self.database: - await self.database.add(uid) + if self.auth_users == "*": + can_use = True - elif self.auth_users: - is_auth = uid in self.auth_users + else: + can_use = uid in self.auth_users - if not is_auth: + if not can_use: await msg.reply("You're not authorized to use this bot 😬") return msg.stop_propagation()