forked from EverythingSuckz/TG-FileStreamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.py
More file actions
54 lines (51 loc) · 1.94 KB
/
Copy pathstream.py
File metadata and controls
54 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# This file is a part of TG-FileStreamBot
# Coding : Jyothis Jayanth [@EverythingSuckz]
import logging
from pyrogram import filters, errors
from WebStreamer.vars import Var
from urllib.parse import quote_plus
from WebStreamer.bot import StreamBot, logger
from WebStreamer.utils import get_hash, get_name
from pyrogram.enums.parse_mode import ParseMode
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
@StreamBot.on_message(
filters.private
& (
filters.document
| filters.video
| filters.audio
| filters.animation
| filters.voice
| filters.video_note
| filters.photo
| filters.sticker
),
group=4,
)
async def media_receive_handler(_, m: Message):
if Var.ALLOWED_USERS and not ((str(m.from_user.id) in Var.ALLOWED_USERS) or (m.from_user.username in Var.ALLOWED_USERS)):
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)
log_msg = await m.forward(chat_id=Var.BIN_CHANNEL)
file_hash = get_hash(log_msg, Var.HASH_LENGTH)
stream_link = f"{Var.URL}{log_msg.id}/{quote_plus(get_name(m))}?hash={file_hash}"
short_link = f"{Var.URL}{file_hash}{log_msg.id}"
logger.info(f"Generated link: {stream_link} for {m.from_user.first_name}")
try:
await m.reply_text(
text="<code>{}</code>\n(<a href='{}'>shortened</a>)".format(
stream_link, short_link
),
quote=True,
parse_mode=ParseMode.HTML,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Open", url=stream_link)]]
),
)
except errors.ButtonUrlInvalid:
await m.reply_text(
text="<code>{}</code>\n\nshortened: {})".format(
stream_link, short_link
),
quote=True,
parse_mode=ParseMode.HTML,
)