Files
FileStreamBot/WebStreamer/bot/plugins/stream.py
Deekshith SH b1512234b2 Forgot to change 😅
2022-07-11 22:45:19 +05:30

135 lines
6.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# (c) @Avishkarpatil
import asyncio
import urllib.parse
from WebStreamer.bot import StreamBot
from WebStreamer.utils.database import Database
from WebStreamer.utils.human_readable import humanbytes
from WebStreamer.vars import Var
from pyrogram import filters, Client
from pyrogram.errors import FloodWait, UserNotParticipant
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.enums.parse_mode import ParseMode
db = Database(Var.DATABASE_URL, Var.SESSION_NAME)
def get_media_file_size(m):
media = m.video or m.audio or m.document
if media and media.file_size:
return media.file_size
else:
return None
def get_media_file_name(m):
media = m.video or m.document or m.audio
if media and media.file_name:
return urllib.parse.quote_plus(media.file_name)
else:
return None
@StreamBot.on_message(filters.private & (filters.document | filters.video | filters.audio), group=4)
async def private_receive_handler(c: Client, m: Message):
if not await db.is_user_exist(m.from_user.id):
await db.add_user(m.from_user.id)
await c.send_message(
Var.BIN_CHANNEL,
f"Nᴇ Usᴇʀ Jɪɴᴇᴅ : \n\nNᴀᴍᴇ : [{m.from_user.first_name}](tg://user?id={m.from_user.id}) Sᴛᴀʀᴛᴇᴅ Yʀ Bᴛ !!"
)
if Var.UPDATES_CHANNEL != "None":
try:
user = await c.get_chat_member(Var.UPDATES_CHANNEL, m.chat.id)
if user.status == "kicked":
await c.send_message(
chat_id=m.chat.id,
text="__Sʀʀʏ Sɪʀ, Y ᴀʀᴇ Bᴀɴɴᴇᴅ ᴛᴏ sᴇ ᴍᴇ.__\n\n **Cɴᴛᴀᴛ Dᴇᴇʟᴘᴇʀ @Avishkarpatil Tʜᴇʏ Wɪʟʟ Hᴇʟᴘ Y**",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True
)
return
except UserNotParticipant:
await c.send_message(
chat_id=m.chat.id,
text="""<i>Jɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜꜱᴇ ᴍᴇ 🔐</i>""",
reply_markup=InlineKeyboardMarkup(
[[ InlineKeyboardButton("Jɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Var.UPDATES_CHANNEL}") ]]
),
parse_mode=ParseMode.HTML
)
return
except Exception:
await c.send_message(
chat_id=m.chat.id,
text="**Sᴍᴇᴛʜɪɴɢ ᴡᴇɴᴛ Wʀɴɢ. Cɴᴛᴀᴛ ᴍʏ ʙss** @Avishkarpatil",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True)
return
try:
log_msg = await m.forward(chat_id=Var.BIN_CHANNEL)
file_name = get_media_file_name(m)
file_size = humanbytes(get_media_file_size(m))
stream_link = "https://{}/{}/{}".format(Var.FQDN, log_msg.id, file_name) if Var.ON_HEROKU or Var.NO_PORT else \
"http://{}:{}/{}/{}".format(Var.FQDN,
Var.PORT,
log_msg.id,
file_name)
msg_text ="""
<i><u>𝗬𝗼𝘂𝗿 𝗟𝗶𝗻𝗸 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗲𝗱 !</u></i>\n
<b>📂 Fɪʟᴇ ɴᴀᴍᴇ :</b> <i>{}</i>\n
<b>📦 Fɪʟᴇ ꜱɪᴢᴇ :</b> <i>{}</i>\n
<b>📥 Dɴʟᴀᴅ :</b> <i>{}</i>\n
<b>🚸 Nᴛᴇ : Tʜɪs ᴘᴇʀᴍᴀɴᴇɴᴛ Lɪɴᴋ, Nᴛ Exᴘɪʀᴇᴅ</b>\n
<i>© @AvishkarPatil </i>"""
await log_msg.reply_text(text=f"**RᴇQᴛᴇᴅ ʙʏ :** [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n**Uᴇʀ ɪᴅ :** `{m.from_user.id}`\n**Dɴʟᴀᴅ ʟɪɴᴋ :** {stream_link}", disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN, quote=True)
await m.reply_text(
text=msg_text.format(file_name, file_size, stream_link),
parse_mode=ParseMode.HTML,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Dɴʟᴀᴅ ɴᴏᴡ 📥", url=stream_link)]]),
quote=True
)
except FloodWait as e:
print(f"Sleeping for {str(e.value)}s")
await asyncio.sleep(e.value)
await c.send_message(chat_id=Var.BIN_CHANNEL, text=f"Gᴛ FʟᴅWᴀɪᴛ ᴏғ {str(e.value)}s from [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n\n**𝚄𝚜𝚎𝚛 𝙸𝙳 :** `{str(m.from_user.id)}`", disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)
@StreamBot.on_message(filters.channel & (filters.document | filters.video), group=-1)
async def channel_receive_handler(bot, broadcast):
if int(broadcast.chat.id) in Var.BANNED_CHANNELS:
await bot.leave_chat(broadcast.chat.id)
return
try:
log_msg = await broadcast.forward(chat_id=Var.BIN_CHANNEL)
stream_link = "https://{}/{}".format(Var.FQDN, log_msg.id) if Var.ON_HEROKU or Var.NO_PORT else \
"http://{}:{}/{}".format(Var.FQDN,
Var.PORT,
log_msg.id)
await log_msg.reply_text(
text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴇsᴛ ᴜʀʟ:** https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.id)}",
# text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴇsᴛ ᴜʀʟ:** https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.id)}",
quote=True,
parse_mode=ParseMode.MARKDOWN
)
await bot.edit_message_reply_markup(
chat_id=broadcast.chat.id,
message_id=broadcast.id,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Dɴʟᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.id)}")]])
# [[InlineKeyboardButton("Dɴʟᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.id)}")]])
)
except FloodWait as w:
print(f"Sleeping for {str(w.value)}s")
await asyncio.sleep(w.value)
await bot.send_message(chat_id=Var.BIN_CHANNEL,
text=f"Gᴛ FʟᴅWᴀɪᴛ ᴏғ {str(w.value)}s from {broadcast.chat.title}\n\n**Cʜᴀɴɴᴇʟ ID:** `{str(broadcast.chat.id)}`",
disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)
except Exception as e:
await bot.send_message(chat_id=Var.BIN_CHANNEL, text=f"**#ᴇʀʀʀ_ᴛʀᴀᴇʙᴀᴋ:** `{e}`", disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)
print(f"Cᴀɴ'ᴛ Eᴅɪᴛ Bʀᴀᴅᴀsᴛ Mᴇssᴀɢᴇ!\nEʀʀʀ: {e}")