Skip to content

Commit

Permalink
fix: authorized users
Browse files Browse the repository at this point in the history
- added support for global mode (set AUTH_USERS to "*")
- better authorization logic
  • Loading branch information
Itz-fork committed Dec 28, 2023
1 parent b5f7cd2 commit 62e49dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BOT_TOKEN=bot-token-from-@BotFather

MEGA_EMAIL=[email protected]
MEGA_PASSWORD=mypassword
AUTH_USERS=1340254734
AUTH_USERS=*
CIPHER_KEY=vJmDXO4xria6SYVcOfVYd3k3YM8WiiGBfRjbQ8MBsvI=
USE_ENV=False

Expand Down
19 changes: 9 additions & 10 deletions megadl/helpers/mclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 62e49dd

Please sign in to comment.