Skip to content

Commit

Permalink
Added Allowed users list
Browse files Browse the repository at this point in the history
Co-authored-by: Deekshith SH <[email protected]>
  • Loading branch information
EverythingSuckz and DeekshithSH committed Mar 28, 2024
1 parent e6f515d commit aecbaf4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ dmypy.json
*.session
*.session-journal

.env
*.env
test.py
/test

streambot.log.*
streambot.log.*
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ you may also add as many as bots you want. (max limit is not tested yet)

`SESSION_NAME` : Name for the Database created on your MongoDB. Defaults to `F2LxBot`

`BANNED_CHANNELS` : Put IDs of Banned Channels where bot will not work. You can add multiple IDs & separate with <kbd>Space</kbd>.
`ALLOWED_USERS`: The user Telegram IDs of users to which the bot only reply to.
> **Note**
> Leave this field empty and anyone will be able to use your bot instance.
> You may also add multiple users by adding the IDs separated by comma (,)
`KEEP_ALIVE` : If you want to make the server ping itself every

Expand Down
6 changes: 6 additions & 0 deletions WebStreamer/bot/plugins/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ async def help_handler(bot, message):

@StreamBot.on_message(filters.command('myfiles') & filters.private)
async def my_files(bot: Client, message: Message):
if not await validate_user(message):
return
user_files, total_files=await db.find_files(message.from_user.id, [1,10])

file_list=[]
Expand Down Expand Up @@ -89,6 +91,8 @@ async def tos_handler(bot: Client, message: Message):
@StreamBot.on_message(filters.command('info') & filters.private)
async def info_handler(bot: Client, message: Message):
lang = Language(message)
if not await validate_user(message, lang):
return
i_cmd=message.text.split()
if (message.from_user.id == Var.OWNER_ID) and (len(i_cmd) > 1):
message.from_user.id=int(i_cmd[1])
Expand All @@ -101,6 +105,8 @@ async def info_handler(bot: Client, message: Message):

@StreamBot.on_message(filters.command('getfile') & filters.private & filters.user(Var.OWNER_ID))
async def getfile(bot: Client, message: Message):
if not await validate_user(message):
return
usr_cmd=message.text.split()
if len(usr_cmd) < 2:
return await message.reply_text("Invalid Format\nUsage: `/getfile _id`")
Expand Down
15 changes: 13 additions & 2 deletions WebStreamer/utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,24 @@ async def is_user_accepted_tos(message: Message) -> bool:
return False
return True

async def validate_user(message: Message, lang) -> bool:
if await is_user_banned(message, lang):
async def is_allowed(message: Message):
if Var.ALLOWED_USERS and not ((str(message.from_user.id) in Var.ALLOWED_USERS) or (message.from_user.username in Var.ALLOWED_USERS)):
await message.reply("You are not in the allowed list of users who can use me.", quote=True)
return False
return True

async def validate_user(message: Message, lang=None) -> bool:
if not await is_allowed(message):
return False
await is_user_exist(message)
if Var.TOS:
if not await is_user_accepted_tos(message):
return False

if not lang:
lang = Language(message)
if await is_user_banned(message, lang):
return False
if Var.FORCE_UPDATES_CHANNEL:
if not await is_user_joined(message,lang):
return False
Expand Down
2 changes: 1 addition & 1 deletion WebStreamer/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Var(object):
SESSION_NAME = str(environ.get('SESSION_NAME', 'F2LxBot'))
FORCE_UPDATES_CHANNEL = environ.get('FORCE_UPDATES_CHANNEL', False)
FORCE_UPDATES_CHANNEL = True if str(FORCE_UPDATES_CHANNEL).lower() == "true" else False
ALLOWED_USERS = [x.strip("@ ") for x in str(environ.get("ALLOWED_USERS", "") or "").split(",") if x.strip("@ ")]

BANNED_CHANNELS = list(set(int(x) for x in str(environ.get("BANNED_CHANNELS", "-1001296894100")).split()))
KEEP_ALIVE = str(environ.get("KEEP_ALIVE", "0").lower()) in ("1", "true", "t", "yes", "y")
IMAGE_FILEID = environ.get('IMAGE_FILEID', "https://deekshith.eu.org/static/MyFiles.png")
TOS = environ.get("TOS", None)
Expand Down

0 comments on commit aecbaf4

Please sign in to comment.