mirror of
https://github.com/avipatilpro/FileStreamBot.git
synced 2026-01-15 22:32:53 -03:00
192 lines
8.9 KiB
Python
192 lines
8.9 KiB
Python
|
||
|
||
from WebStreamer.bot import StreamBot
|
||
from WebStreamer.vars import Var
|
||
from WebStreamer.utils.human_readable import humanbytes
|
||
from WebStreamer.utils.database import Database
|
||
from pyrogram import filters
|
||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||
from pyrogram.errors import UserNotParticipant
|
||
db = Database(Var.DATABASE_URL, Var.SESSION_NAME)
|
||
|
||
|
||
@StreamBot.on_message(filters.command('start') & filters.private & ~filters.edited)
|
||
async def start(b, m):
|
||
if not await db.is_user_exist(m.from_user.id):
|
||
await db.add_user(m.from_user.id)
|
||
await b.send_message(
|
||
Var.BIN_CHANNEL,
|
||
f"New User : [{m.from_user.first_name}](tg://user?id={m.from_user.id}) Started !!"
|
||
)
|
||
usr_cmd = m.text.split("_")[-1]
|
||
if usr_cmd == "/start":
|
||
if Var.UPDATES_CHANNEL is not None:
|
||
try:
|
||
user = await b.get_chat_member(Var.UPDATES_CHANNEL, m.chat.id)
|
||
if user.status == "kicked":
|
||
await b.send_message(
|
||
chat_id=m.chat.id,
|
||
text="**Sorry Sir, You are Banned to use me. Contact the Developer**",
|
||
parse_mode="markdown",
|
||
disable_web_page_preview=True
|
||
)
|
||
return
|
||
except UserNotParticipant:
|
||
await b.send_message(
|
||
chat_id=m.chat.id,
|
||
text="**Please Join My Updates Channel to use this Bot!**\n\nDue to Overload, Only Channel Subscribers can use the Bot!",
|
||
reply_markup=InlineKeyboardMarkup(
|
||
[
|
||
[
|
||
InlineKeyboardButton("🤖 Join Updates Channel", url=f"https://t.me/{Var.UPDATES_CHANNEL}")
|
||
]
|
||
]
|
||
),
|
||
parse_mode="markdown"
|
||
)
|
||
return
|
||
except Exception:
|
||
await b.send_message(
|
||
chat_id=m.chat.id,
|
||
text="**Something went Wrong. Contact me [Avishkar Patil](https://t.me/Avishkarpatil).**",
|
||
parse_mode="markdown",
|
||
disable_web_page_preview=True)
|
||
return
|
||
await m.reply_text(
|
||
text="""
|
||
<i>👋 Hᴇʏ, ᴛʜɪꜱ ɪꜱ ꜰɪʟᴇ ᴛᴏ ʟɪɴᴋ ɢᴇɴ ʙᴏᴛ</i>\n
|
||
<i>Pʀᴇꜱꜱ ʜᴇʟᴘ ʙᴜᴛᴛᴏɴ ꜰᴏʀ ᴍᴏʀᴇ ɪɴꜰᴏ... /help </i>\n
|
||
<i><u>𝗪𝗔𝗥𝗡𝗜𝗡𝗚 🚸</u></i>\n
|
||
<b>Pʀᴏɴ ᴄᴏɴᴛᴇɴᴛꜱ ʟᴇᴀᴅꜱ ᴛᴏ ᴘᴇʀᴍᴀɴᴇɴᴛ ʙᴀɴ ʏᴏᴜ.</b>""",
|
||
parse_mode="HTML",
|
||
disable_web_page_preview=True,
|
||
reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton('😎 Developer', url='https://t.me/Avishkarpatil'),
|
||
InlineKeyboardButton('😉 GitHub', url='https://t.me/Avishkarpatil') ],
|
||
[ InlineKeyboardButton(text='Close', callback_data='') ] ] ) )
|
||
else:
|
||
if Var.UPDATES_CHANNEL is not None:
|
||
try:
|
||
user = await b.get_chat_member(Var.UPDATES_CHANNEL, m.chat.id)
|
||
if user.status == "kicked":
|
||
await b.send_message(
|
||
chat_id=m.chat.id,
|
||
text="*Sorry Sir, You are Banned to use me. Quickly contact @Avishkarpatil*",
|
||
parse_mode="markdown",
|
||
disable_web_page_preview=True
|
||
)
|
||
return
|
||
except UserNotParticipant:
|
||
await b.send_message(
|
||
chat_id=m.chat.id,
|
||
text="**Please Join My Updates Channel to use this Bot!**\n\n*Due to Overload, Only Channel Subscribers can use the Bot!*",
|
||
reply_markup=InlineKeyboardMarkup(
|
||
[
|
||
[
|
||
InlineKeyboardButton("🤖 Join Updates Channel", url=f"https://t.me/{Var.UPDATES_CHANNEL}")
|
||
],
|
||
[
|
||
InlineKeyboardButton("🔄 Refresh / Try Again",
|
||
url=f"https://t.me/avifilestreambot/{usr_cmd}")
|
||
]
|
||
]
|
||
),
|
||
parse_mode="markdown"
|
||
)
|
||
return
|
||
except Exception:
|
||
await b.send_message(
|
||
chat_id=m.chat.id,
|
||
text="**Something went Wrong. Contact me [Avishkar Patil](https://t.me/Avishkarpatil).**",
|
||
parse_mode="markdown",
|
||
disable_web_page_preview=True)
|
||
return
|
||
|
||
get_msg = await b.get_messages(chat_id=Var.BIN_CHANNEL, message_ids=int(usr_cmd))
|
||
|
||
file_size = None
|
||
if get_msg.video:
|
||
file_size = f"{humanbytes(get_msg.video.file_size)}"
|
||
elif get_msg.document:
|
||
file_size = f"{humanbytes(get_msg.document.file_size)}"
|
||
elif get_msg.audio:
|
||
file_size = f"{humanbytes(get_msg.audio.file_size)}"
|
||
|
||
file_name = None
|
||
if get_msg.video:
|
||
file_name = f"{get_msg.video.file_name}"
|
||
elif get_msg.document:
|
||
file_name = f"{get_msg.document.file_name}"
|
||
elif get_msg.audio:
|
||
file_name = f"{get_msg.audio.file_name}"
|
||
|
||
stream_link = "https://{}/{}".format(Var.FQDN, get_msg.message_id) if Var.ON_HEROKU or Var.NO_PORT else \
|
||
"http://{}:{}/{}".format(Var.FQDN,
|
||
Var.PORT,
|
||
get_msg.message_id)
|
||
|
||
msg_text = "Bruh! 😁\n*Your Link Generated!* 🤓\n\n**📂 Fɪʟᴇ ɴᴀᴍᴇ :** `{}`\n**📦 Fɪʟᴇ ꜱɪᴢᴇ :** `{}`\n**📥 Dᴏᴡɴʟᴏᴀᴅ :** {}\n🚸 **Nᴏᴛᴇ : Lɪɴᴋ ᴇxᴘɪʀᴇᴅ ɪɴ 24 ʜᴏᴜʀꜱ**"
|
||
await m.reply_text(
|
||
text=msg_text.format(file_name, file_size, stream_link),
|
||
parse_mode="Markdown",
|
||
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ɴᴏᴡ 📥", url=stream_link)]])
|
||
)
|
||
|
||
|
||
@StreamBot.on_message(filters.command('help') & filters.private & ~filters.edited)
|
||
async def help_handler(bot, message):
|
||
if not await db.is_user_exist(message.from_user.id):
|
||
await db.add_user(message.from_user.id)
|
||
await bot.send_message(
|
||
Var.BIN_CHANNEL,
|
||
f"New User : [{m.from_user.first_name}](tg://user?id={m.from_user.id}) Started !!"
|
||
)
|
||
if Var.UPDATES_CHANNEL is not None:
|
||
try:
|
||
user = await bot.get_chat_member(Var.UPDATES_CHANNEL, message.chat.id)
|
||
if user.status == "kicked":
|
||
await bot.send_message(
|
||
chat_id=message.chat.id,
|
||
text="Sorry Sir, You are Banned to use me.",
|
||
parse_mode="markdown",
|
||
disable_web_page_preview=True
|
||
)
|
||
return
|
||
except UserNotParticipant:
|
||
await bot.send_message(
|
||
chat_id=message.chat.id,
|
||
text="**Please Join My Updates Channel to use this Bot!**\n\nDue to Overload, Only Channel Subscribers can use the Bot!",
|
||
reply_markup=InlineKeyboardMarkup(
|
||
[
|
||
[
|
||
InlineKeyboardButton("🤖 Join Updates Channel", url=f"https://t.me/{Var.UPDATES_CHANNEL}")
|
||
]
|
||
]
|
||
),
|
||
parse_mode="markdown"
|
||
)
|
||
return
|
||
except Exception:
|
||
await bot.send_message(
|
||
chat_id=message.chat.id,
|
||
text="""<i>Cᴏɴᴛᴀᴄᴛ ᴅᴇᴠᴇʟᴏᴘᴇʀ (ᴏʀ) ʀᴇᴘᴏʀᴛ ʙᴜɢꜱ</i> <b>: <a href='https://t.me/Avishkarpatil'>[ ᴄʟɪᴄᴋ ʜᴇʀᴇ ]</a></b>""",
|
||
parse_mode="html",
|
||
disable_web_page_preview=True)
|
||
return
|
||
await message.reply_text(
|
||
text="""
|
||
<i>Sᴇɴᴅ ᴍᴇ ᴀɴʏ ꜰɪʟᴇ (ᴏʀ) ᴍᴇᴅɪᴀ ꜰʀᴏᴍ ᴛᴇʟᴇɢʀᴀᴍ.</i>\n
|
||
<i>I ᴡɪʟʟ ᴘʀᴏᴠɪᴅᴇ ᴇxᴛᴇʀɴᴀʟ ᴅɪʀᴇᴄᴛ ᴅᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ !.</i>\n
|
||
<u>𝗪𝗔𝗥𝗡𝗜𝗡𝗚 🚸</u>\n
|
||
<b>Pʀᴏɴ ᴄᴏɴᴛᴇɴᴛꜱ ʟᴇᴀᴅꜱ ᴛᴏ ᴘᴇʀᴍᴀɴᴇɴᴛ ʙᴀɴ ʏᴏᴜ.</b>\n
|
||
<i>Cᴏɴᴛᴀᴄᴛ ᴅᴇᴠᴇʟᴏᴘᴇʀ (ᴏʀ) ʀᴇᴘᴏʀᴛ ʙᴜɢꜱ</i> <b>: <a href='https://t.me/Avishkarpatil'>[ ᴄʟɪᴄᴋ ʜᴇʀᴇ ]</a></b>""",
|
||
|
||
parse_mode="html",
|
||
disable_web_page_preview=True,
|
||
reply_markup=InlineKeyboardMarkup(
|
||
[
|
||
|
||
[InlineKeyboardButton('😎 Developer', url='https://t.me/Avishkarpatil'), InlineKeyboardButton('Me', url='https://avipatilweb.me')]
|
||
]
|
||
)
|
||
)
|