Skip to content

Commit 72259cb

Browse files
feat: allow only specific users (#93)
1 parent c99ce49 commit 72259cb

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ Before running the bot, you will need to set up the following mandatory variable
160160
### Optional Vars
161161
In addition to the mandatory variables, you can also set the following optional variables:
162162

163+
- `ALLOWED_USERS`: The user Telegram IDs of users to which the bot only reply to.
164+
> **Note**
165+
> Leave this field empty and anyone will be able to use your bot instance.
166+
> You may also add multiple users by adding the IDs separated by comma (,)
163167
164168
- `HASH_LENGTH` : This is the custom hash length for generated URLs. The hash length must be greater than 5 and less than 64.
165169

WebStreamer/bot/plugins/start.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
from pyrogram import filters
55
from pyrogram.types import Message
6-
from WebStreamer.bot import StreamBot
76

7+
from WebStreamer.vars import Var
8+
from WebStreamer.bot import StreamBot
89

9-
@StreamBot.on_message(filters.command(["start", "help"]))
10+
@StreamBot.on_message(filters.command(["start", "help"]) & filters.private)
1011
async def start(_, m: Message):
12+
if Var.ALLOWED_USERS and not ((str(m.from_user.id) in Var.ALLOWED_USERS) or (m.from_user.username in Var.ALLOWED_USERS)):
13+
await m.reply("You are not in the allowed list of users who can use me. Check <a href='https://github.com/EverythingSuckz/TG-FileStreamBot#optional-vars'>this link</a> for more info.")
1114
await m.reply(
1215
f'Hi {m.from_user.mention(style="md")}, Send me a file to get an instant stream link.'
1316
)

WebStreamer/bot/plugins/stream.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
group=4,
2727
)
2828
async def media_receive_handler(_, m: Message):
29+
if Var.ALLOWED_USERS and not ((str(m.from_user.id) in Var.ALLOWED_USERS) or (m.from_user.username in Var.ALLOWED_USERS)):
30+
return await m.reply("You are not <b>allowed to use</b> this <a href='https://github.com/EverythingSuckz/TG-FileStreamBot'>bot</a>.", quote=True)
2931
log_msg = await m.forward(chat_id=Var.BIN_CHANNEL)
3032
file_hash = get_hash(log_msg, Var.HASH_LENGTH)
3133
stream_link = f"{Var.URL}{log_msg.id}/{quote_plus(get_name(m))}?hash={file_hash}"

WebStreamer/vars.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ class Var(object):
3232
)
3333
KEEP_ALIVE = str(environ.get("KEEP_ALIVE", "0").lower()) in ("1", "true", "t", "yes", "y")
3434
DEBUG = str(environ.get("DEBUG", "0").lower()) in ("1", "true", "t", "yes", "y")
35-
USE_SESSION_FILE = str(environ.get("USE_SESSION_FILE", "0").lower()) in ("1", "true", "t", "yes", "y")
35+
USE_SESSION_FILE = str(environ.get("USE_SESSION_FILE", "0").lower()) in ("1", "true", "t", "yes", "y")
36+
ALLOWED_USERS = [x.strip("@ ") for x in str(environ.get("ALLOWED_USERS", "") or "").split(",") if x.strip("@ ")]

0 commit comments

Comments
 (0)