mirror of
https://github.com/avipatilpro/FileStreamBot.git
synced 2026-01-15 22:32:53 -03:00
Updated ?
Nothing new but, looks like something changed ;) !
This commit is contained in:
25
FileStream/bot/__init__.py
Normal file
25
FileStream/bot/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from ..config import Telegram
|
||||
from pyrogram import Client
|
||||
|
||||
if Telegram.SECONDARY:
|
||||
plugins=None
|
||||
no_updates=True
|
||||
else:
|
||||
plugins={"root": "FileStream/bot/plugins"}
|
||||
no_updates=None
|
||||
|
||||
FileStream = Client(
|
||||
name="FileStream",
|
||||
api_id=Telegram.API_ID,
|
||||
api_hash=Telegram.API_HASH,
|
||||
workdir="FileStream",
|
||||
plugins=plugins,
|
||||
bot_token=Telegram.BOT_TOKEN,
|
||||
sleep_threshold=Telegram.SLEEP_THRESHOLD,
|
||||
workers=Telegram.WORKERS,
|
||||
no_updates=no_updates
|
||||
)
|
||||
|
||||
multi_clients = {}
|
||||
work_loads = {}
|
||||
|
||||
59
FileStream/bot/clients.py
Normal file
59
FileStream/bot/clients.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from os import environ
|
||||
from ..config import Telegram
|
||||
from pyrogram import Client
|
||||
from . import multi_clients, work_loads, FileStream
|
||||
|
||||
|
||||
async def initialize_clients():
|
||||
all_tokens = dict(
|
||||
(c + 1, t)
|
||||
for c, (_, t) in enumerate(
|
||||
filter(
|
||||
lambda n: n[0].startswith("MULTI_TOKEN"), sorted(environ.items())
|
||||
)
|
||||
)
|
||||
)
|
||||
if not all_tokens:
|
||||
multi_clients[0] = FileStream
|
||||
work_loads[0] = 0
|
||||
print("No additional clients found, using default client")
|
||||
return
|
||||
|
||||
async def start_client(client_id, token):
|
||||
try:
|
||||
if len(token) >= 100:
|
||||
session_string=token
|
||||
bot_token=None
|
||||
print(f'Starting Client - {client_id} Using Session String')
|
||||
else:
|
||||
session_string=None
|
||||
bot_token=token
|
||||
print(f'Starting Client - {client_id} Using Bot Token')
|
||||
if client_id == len(all_tokens):
|
||||
await asyncio.sleep(2)
|
||||
print("This will take some time, please wait...")
|
||||
client = await Client(
|
||||
name=str(client_id),
|
||||
api_id=Telegram.API_ID,
|
||||
api_hash=Telegram.API_HASH,
|
||||
bot_token=bot_token,
|
||||
sleep_threshold=Telegram.SLEEP_THRESHOLD,
|
||||
no_updates=True,
|
||||
session_string=session_string,
|
||||
in_memory=True,
|
||||
).start()
|
||||
client.id = (await client.get_me()).id
|
||||
work_loads[client_id] = 0
|
||||
return client_id, client
|
||||
except Exception:
|
||||
logging.error(f"Failed starting Client - {client_id} Error:", exc_info=True)
|
||||
|
||||
clients = await asyncio.gather(*[start_client(i, token) for i, token in all_tokens.items()])
|
||||
multi_clients.update(dict(clients))
|
||||
if len(multi_clients) != 1:
|
||||
Telegram.MULTI_CLIENT = True
|
||||
print("Multi-Client Mode Enabled")
|
||||
else:
|
||||
print("No additional clients were initialized, using default client")
|
||||
160
FileStream/bot/plugins/admin.py
Normal file
160
FileStream/bot/plugins/admin.py
Normal file
@@ -0,0 +1,160 @@
|
||||
import os
|
||||
import time
|
||||
import string
|
||||
import random
|
||||
import asyncio
|
||||
import aiofiles
|
||||
import datetime
|
||||
|
||||
from FileStream.utils.broadcast_helper import send_msg
|
||||
from FileStream.utils.database import Database
|
||||
from FileStream.bot import FileStream
|
||||
from FileStream.server.exceptions import FIleNotFound
|
||||
from FileStream.config import Telegram, Server
|
||||
from pyrogram import filters, Client
|
||||
from pyrogram.types import Message
|
||||
from pyrogram.enums.parse_mode import ParseMode
|
||||
|
||||
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
||||
broadcast_ids = {}
|
||||
|
||||
|
||||
@FileStream.on_message(filters.command("status") & filters.private & filters.user(Telegram.OWNER_ID))
|
||||
async def sts(c: Client, m: Message):
|
||||
await m.reply_text(text=f"""**Total Users in DB:** `{await db.total_users_count()}`
|
||||
**Banned Users in DB:** `{await db.total_banned_users_count()}`
|
||||
**Total Links Generated: ** `{await db.total_files()}`"""
|
||||
, parse_mode=ParseMode.MARKDOWN, quote=True)
|
||||
|
||||
|
||||
@FileStream.on_message(filters.command("ban") & filters.private & filters.user(Telegram.OWNER_ID))
|
||||
async def sts(b, m: Message):
|
||||
id = m.text.split("/ban ")[-1]
|
||||
if not await db.is_user_banned(int(id)):
|
||||
try:
|
||||
await db.ban_user(int(id))
|
||||
await db.delete_user(int(id))
|
||||
await m.reply_text(text=f"`{id}`** is Banned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
|
||||
if not str(id).startswith('-100'):
|
||||
await b.send_message(
|
||||
chat_id=id,
|
||||
text="**Your Banned to Use The Bot**",
|
||||
parse_mode=ParseMode.MARKDOWN,
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
except Exception as e:
|
||||
await m.reply_text(text=f"**something went wrong: {e}** ", parse_mode=ParseMode.MARKDOWN, quote=True)
|
||||
else:
|
||||
await m.reply_text(text=f"`{id}`** is Already Banned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
|
||||
|
||||
|
||||
@FileStream.on_message(filters.command("unban") & filters.private & filters.user(Telegram.OWNER_ID))
|
||||
async def sts(b, m: Message):
|
||||
id = m.text.split("/unban ")[-1]
|
||||
if await db.is_user_banned(int(id)):
|
||||
try:
|
||||
await db.unban_user(int(id))
|
||||
await m.reply_text(text=f"`{id}`** is Unbanned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
|
||||
if not str(id).startswith('-100'):
|
||||
await b.send_message(
|
||||
chat_id=id,
|
||||
text="**Your Unbanned now Use can use The Bot**",
|
||||
parse_mode=ParseMode.MARKDOWN,
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
except Exception as e:
|
||||
await m.reply_text(text=f"** something went wrong: {e}**", parse_mode=ParseMode.MARKDOWN, quote=True)
|
||||
else:
|
||||
await m.reply_text(text=f"`{id}`** is not Banned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
|
||||
|
||||
|
||||
@FileStream.on_message(filters.command("broadcast") & filters.private & filters.user(Telegram.OWNER_ID) & filters.reply)
|
||||
async def broadcast_(c, m):
|
||||
all_users = await db.get_all_users()
|
||||
broadcast_msg = m.reply_to_message
|
||||
while True:
|
||||
broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)])
|
||||
if not broadcast_ids.get(broadcast_id):
|
||||
break
|
||||
out = await m.reply_text(
|
||||
text=f"Broadcast initiated! You will be notified with log file when all the users are notified."
|
||||
)
|
||||
start_time = time.time()
|
||||
total_users = await db.total_users_count()
|
||||
done = 0
|
||||
failed = 0
|
||||
success = 0
|
||||
broadcast_ids[broadcast_id] = dict(
|
||||
total=total_users,
|
||||
current=done,
|
||||
failed=failed,
|
||||
success=success
|
||||
)
|
||||
async with aiofiles.open('broadcast.txt', 'w') as broadcast_log_file:
|
||||
async for user in all_users:
|
||||
sts, msg = await send_msg(
|
||||
user_id=int(user['id']),
|
||||
message=broadcast_msg
|
||||
)
|
||||
if msg is not None:
|
||||
await broadcast_log_file.write(msg)
|
||||
if sts == 200:
|
||||
success += 1
|
||||
else:
|
||||
failed += 1
|
||||
if sts == 400:
|
||||
await db.delete_user(user['id'])
|
||||
done += 1
|
||||
if broadcast_ids.get(broadcast_id) is None:
|
||||
break
|
||||
else:
|
||||
broadcast_ids[broadcast_id].update(
|
||||
dict(
|
||||
current=done,
|
||||
failed=failed,
|
||||
success=success
|
||||
)
|
||||
)
|
||||
try:
|
||||
await out.edit_text(f"Broadcast Status\n\ncurrent: {done}\nfailed:{failed}\nsuccess: {success}")
|
||||
except:
|
||||
pass
|
||||
if broadcast_ids.get(broadcast_id):
|
||||
broadcast_ids.pop(broadcast_id)
|
||||
completed_in = datetime.timedelta(seconds=int(time.time() - start_time))
|
||||
await asyncio.sleep(3)
|
||||
await out.delete()
|
||||
if failed == 0:
|
||||
await m.reply_text(
|
||||
text=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
|
||||
quote=True
|
||||
)
|
||||
else:
|
||||
await m.reply_document(
|
||||
document='broadcast.txt',
|
||||
caption=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
|
||||
quote=True
|
||||
)
|
||||
os.remove('broadcast.txt')
|
||||
|
||||
|
||||
@FileStream.on_message(filters.command("del") & filters.private & filters.user(Telegram.OWNER_ID))
|
||||
async def sts(c: Client, m: Message):
|
||||
file_id = m.text.split(" ")[-1]
|
||||
try:
|
||||
file_info = await db.get_file(file_id)
|
||||
except FIleNotFound:
|
||||
await m.reply_text(
|
||||
text=f"**File Already Deleted**",
|
||||
quote=True
|
||||
)
|
||||
return
|
||||
await db.delete_one_file(file_info['_id'])
|
||||
await db.count_links(file_info['user_id'], "-")
|
||||
await m.reply_text(
|
||||
text=f"**Fɪʟᴇ Dᴇʟᴇᴛᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ !** ",
|
||||
quote=True
|
||||
)
|
||||
|
||||
|
||||
|
||||
198
FileStream/bot/plugins/callback.py
Normal file
198
FileStream/bot/plugins/callback.py
Normal file
@@ -0,0 +1,198 @@
|
||||
import datetime
|
||||
import math
|
||||
from FileStream import __version__
|
||||
from FileStream.bot import FileStream
|
||||
from FileStream.config import Telegram, Server
|
||||
from FileStream.utils.translation import LANG, BUTTON
|
||||
from FileStream.utils.bot_utils import gen_link
|
||||
from FileStream.utils.database import Database
|
||||
from FileStream.utils.human_readable import humanbytes
|
||||
from FileStream.server.exceptions import FIleNotFound
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
|
||||
from pyrogram.file_id import FileId, FileType, PHOTO_TYPES
|
||||
from pyrogram.enums.parse_mode import ParseMode
|
||||
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
||||
|
||||
#---------------------[ START CMD ]---------------------#
|
||||
@FileStream.on_callback_query()
|
||||
async def cb_data(bot, update: CallbackQuery):
|
||||
usr_cmd = update.data.split("_")
|
||||
if usr_cmd[0] == "home":
|
||||
await update.message.edit_text(
|
||||
text=LANG.START_TEXT.format(update.from_user.mention, FileStream.username),
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=BUTTON.START_BUTTONS
|
||||
)
|
||||
elif usr_cmd[0] == "help":
|
||||
await update.message.edit_text(
|
||||
text=LANG.HELP_TEXT.format(Telegram.OWNER_ID),
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=BUTTON.HELP_BUTTONS
|
||||
)
|
||||
elif usr_cmd[0] == "about":
|
||||
await update.message.edit_text(
|
||||
text=LANG.ABOUT_TEXT.format(FileStream.fname, __version__),
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=BUTTON.ABOUT_BUTTONS
|
||||
)
|
||||
|
||||
#---------------------[ MY FILES CMD ]---------------------#
|
||||
|
||||
elif usr_cmd[0] == "N/A":
|
||||
await update.answer("N/A", True)
|
||||
elif usr_cmd[0] == "close":
|
||||
await update.message.delete()
|
||||
elif usr_cmd[0] == "msgdelete":
|
||||
await update.message.edit_caption(
|
||||
caption= "**Cᴏɴғɪʀᴍ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴅᴇʟᴇᴛᴇ ᴛʜᴇ Fɪʟᴇ**\n\n",
|
||||
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("ʏᴇs", callback_data=f"msgdelyes_{usr_cmd[1]}_{usr_cmd[2]}"), InlineKeyboardButton("ɴᴏ", callback_data=f"myfile_{usr_cmd[1]}_{usr_cmd[2]}")]])
|
||||
)
|
||||
elif usr_cmd[0] == "msgdelyes":
|
||||
await delete_user_file(usr_cmd[1], int(usr_cmd[2]), update)
|
||||
return
|
||||
elif usr_cmd[0] == "msgdelpvt":
|
||||
await update.message.edit_caption(
|
||||
caption= "**Cᴏɴғɪʀᴍ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴅᴇʟᴇᴛᴇ ᴛʜᴇ Fɪʟᴇ**\n\n",
|
||||
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("ʏᴇs", callback_data=f"msgdelpvtyes_{usr_cmd[1]}"), InlineKeyboardButton("ɴᴏ", callback_data=f"mainstream_{usr_cmd[1]}")]])
|
||||
)
|
||||
elif usr_cmd[0] == "msgdelpvtyes":
|
||||
await delete_user_filex(usr_cmd[1], update)
|
||||
return
|
||||
|
||||
elif usr_cmd[0] == "mainstream":
|
||||
_id = usr_cmd[1]
|
||||
reply_markup, stream_text = await gen_link(_id=_id)
|
||||
await update.message.edit_text(
|
||||
text=stream_text,
|
||||
parse_mode=ParseMode.HTML,
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=reply_markup,
|
||||
)
|
||||
|
||||
elif usr_cmd[0] == "userfiles":
|
||||
file_list, total_files = await gen_file_list_button(int(usr_cmd[1]), update.from_user.id)
|
||||
await update.message.edit_caption(
|
||||
caption="Total files: {}".format(total_files),
|
||||
reply_markup=InlineKeyboardMarkup(file_list)
|
||||
)
|
||||
elif usr_cmd[0] == "myfile":
|
||||
await gen_file_menu(usr_cmd[1], usr_cmd[2], update)
|
||||
return
|
||||
elif usr_cmd[0] == "sendfile":
|
||||
myfile = await db.get_file(usr_cmd[1])
|
||||
file_name = myfile['file_name']
|
||||
await update.answer(f"Sending File {file_name}")
|
||||
await update.message.reply_cached_media(myfile['file_id'], caption=f'**{file_name}**')
|
||||
else:
|
||||
await update.message.delete()
|
||||
|
||||
|
||||
|
||||
#---------------------[ MY FILES FUNC ]---------------------#
|
||||
|
||||
async def gen_file_list_button(file_list_no: int, user_id: int):
|
||||
|
||||
file_range=[file_list_no*10-10+1, file_list_no*10]
|
||||
user_files, total_files=await db.find_files(user_id, file_range)
|
||||
|
||||
file_list=[]
|
||||
async for x in user_files:
|
||||
file_list.append([InlineKeyboardButton(x["file_name"], callback_data=f"myfile_{x['_id']}_{file_list_no}")])
|
||||
if total_files > 10:
|
||||
file_list.append(
|
||||
[InlineKeyboardButton("◄", callback_data="{}".format("userfiles_"+str(file_list_no-1) if file_list_no > 1 else 'N/A')),
|
||||
InlineKeyboardButton(f"{file_list_no}/{math.ceil(total_files/10)}", callback_data="N/A"),
|
||||
InlineKeyboardButton("►", callback_data="{}".format("userfiles_"+str(file_list_no+1) if total_files > file_list_no*10 else 'N/A'))]
|
||||
)
|
||||
if not file_list:
|
||||
file_list.append(
|
||||
[InlineKeyboardButton("ᴇᴍᴘᴛʏ", callback_data="N/A")])
|
||||
file_list.append([InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")])
|
||||
return file_list, total_files
|
||||
|
||||
async def gen_file_menu(_id, file_list_no, update: CallbackQuery):
|
||||
try:
|
||||
myfile_info=await db.get_file(_id)
|
||||
except FIleNotFound:
|
||||
await update.answer("File Not Found")
|
||||
return
|
||||
|
||||
file_id=FileId.decode(myfile_info['file_id'])
|
||||
|
||||
if file_id.file_type in PHOTO_TYPES:
|
||||
file_type = "Image"
|
||||
elif file_id.file_type == FileType.VOICE:
|
||||
file_type = "Voice"
|
||||
elif file_id.file_type in (FileType.VIDEO, FileType.ANIMATION, FileType.VIDEO_NOTE):
|
||||
file_type = "Video"
|
||||
elif file_id.file_type == FileType.DOCUMENT:
|
||||
file_type = "Document"
|
||||
elif file_id.file_type == FileType.STICKER:
|
||||
file_type = "Sticker"
|
||||
elif file_id.file_type == FileType.AUDIO:
|
||||
file_type = "Audio"
|
||||
else:
|
||||
file_type = "Unknown"
|
||||
|
||||
page_link = f"{Server.URL}watch/{myfile_info['_id']}"
|
||||
stream_link = f"{Server.URL}dl/{myfile_info['_id']}"
|
||||
if "video" in file_type.lower():
|
||||
MYFILES_BUTTONS = InlineKeyboardMarkup(
|
||||
[
|
||||
[InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link), InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
||||
[InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
||||
InlineKeyboardButton("ʀᴇᴠᴏᴋᴇ ғɪʟᴇ", callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")],
|
||||
[InlineKeyboardButton("ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))]
|
||||
]
|
||||
)
|
||||
else:
|
||||
MYFILES_BUTTONS = InlineKeyboardMarkup(
|
||||
[
|
||||
[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
||||
[InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
||||
InlineKeyboardButton("ʀᴇᴠᴏᴋᴇ ғɪʟᴇ", callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")],
|
||||
[InlineKeyboardButton("ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))]
|
||||
]
|
||||
)
|
||||
|
||||
TiMe = myfile_info['time']
|
||||
if type(TiMe) == float:
|
||||
date = datetime.datetime.fromtimestamp(TiMe)
|
||||
await update.edit_message_caption(
|
||||
caption="**File Name :** `{}`\n**File Size :** `{}`\n**File Type :** `{}`\n**Created On :** `{}`".format(myfile_info['file_name'],
|
||||
humanbytes(int(myfile_info['file_size'])),
|
||||
file_type,
|
||||
TiMe if isinstance(TiMe,str) else date.date()),
|
||||
reply_markup=MYFILES_BUTTONS )
|
||||
|
||||
|
||||
async def delete_user_file(_id, file_list_no: int, update:CallbackQuery):
|
||||
|
||||
try:
|
||||
myfile_info=await db.get_file(_id)
|
||||
except FIleNotFound:
|
||||
await update.answer("File Already Deleted")
|
||||
return
|
||||
|
||||
await db.delete_one_file(myfile_info['_id'])
|
||||
await db.count_links(update.from_user.id, "-")
|
||||
await update.message.edit_caption(
|
||||
caption= "**Fɪʟᴇ Dᴇʟᴇᴛᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ !**" + update.message.caption.replace("Cᴏɴғɪʀᴍ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴅᴇʟᴇᴛᴇ ᴛʜᴇ Fɪʟᴇ", ""),
|
||||
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("ʙᴀᴄᴋ", callback_data=f"userfiles_1")]])
|
||||
)
|
||||
|
||||
async def delete_user_filex(_id, update:CallbackQuery):
|
||||
|
||||
try:
|
||||
myfile_info=await db.get_file(_id)
|
||||
except FIleNotFound:
|
||||
await update.answer("File Already Deleted")
|
||||
return
|
||||
|
||||
await db.delete_one_file(myfile_info['_id'])
|
||||
await db.count_links(update.from_user.id, "-")
|
||||
await update.message.edit_caption(
|
||||
caption= "**Fɪʟᴇ Dᴇʟᴇᴛᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ !**\n\n",
|
||||
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data=f"close")]])
|
||||
)
|
||||
|
||||
119
FileStream/bot/plugins/start.py
Normal file
119
FileStream/bot/plugins/start.py
Normal file
@@ -0,0 +1,119 @@
|
||||
import logging
|
||||
import math
|
||||
from FileStream import __version__
|
||||
from FileStream.bot import FileStream
|
||||
from FileStream.server.exceptions import FIleNotFound
|
||||
from FileStream.utils.bot_utils import gen_linkx, verify_user
|
||||
from FileStream.config import Telegram
|
||||
from FileStream.utils.database import Database
|
||||
from FileStream.utils.translation import LANG, BUTTON
|
||||
from pyrogram import filters, Client
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
|
||||
from pyrogram.enums.parse_mode import ParseMode
|
||||
|
||||
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
||||
|
||||
@FileStream.on_message(filters.command('start') & filters.private)
|
||||
async def start(bot: Client, message: Message):
|
||||
if not await verify_user(bot, message):
|
||||
return
|
||||
usr_cmd = message.text.split("_")[-1]
|
||||
|
||||
if usr_cmd == "/start":
|
||||
await message.reply_text(
|
||||
text=LANG.START_TEXT.format(message.from_user.mention, FileStream.username),
|
||||
parse_mode=ParseMode.HTML,
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=BUTTON.START_BUTTONS
|
||||
)
|
||||
else:
|
||||
if "stream_" in message.text:
|
||||
try:
|
||||
file_check = await db.get_file(usr_cmd)
|
||||
file_id = str(file_check['_id'])
|
||||
if file_id == usr_cmd:
|
||||
reply_markup, stream_text = await gen_linkx(m=message, _id=file_id,
|
||||
name=[FileStream.username, FileStream.fname])
|
||||
await message.reply_text(
|
||||
text=stream_text,
|
||||
parse_mode=ParseMode.HTML,
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=reply_markup,
|
||||
quote=True
|
||||
)
|
||||
|
||||
except FIleNotFound as e:
|
||||
await message.reply_text("File Not Found")
|
||||
except Exception as e:
|
||||
await message.reply_text("Something Went Wrong")
|
||||
logging.error(e)
|
||||
|
||||
elif "file_" in message.text:
|
||||
try:
|
||||
file_check = await db.get_file(usr_cmd)
|
||||
db_id = str(file_check['_id'])
|
||||
file_id = file_check['file_id']
|
||||
file_name = file_check['file_name']
|
||||
if db_id == usr_cmd:
|
||||
await message.reply_cached_media(file_id=file_id, caption=f'**{file_name}**')
|
||||
|
||||
except FIleNotFound as e:
|
||||
await message.reply_text("**File Not Found**")
|
||||
except Exception as e:
|
||||
await message.reply_text("Something Went Wrong")
|
||||
logging.error(e)
|
||||
|
||||
else:
|
||||
await message.reply_text(f"**Invalid Command**")
|
||||
|
||||
@FileStream.on_message(filters.private & filters.command(["about"]))
|
||||
async def start(bot, message):
|
||||
if not await verify_user(bot, message):
|
||||
return
|
||||
await message.reply_text(
|
||||
text=LANG.ABOUT_TEXT.format(FileStream.fname, __version__),
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=BUTTON.ABOUT_BUTTONS
|
||||
)
|
||||
|
||||
|
||||
@FileStream.on_message((filters.command('help')) & filters.private)
|
||||
async def help_handler(bot, message):
|
||||
if not await verify_user(bot, message):
|
||||
return
|
||||
await message.reply_text(
|
||||
text=LANG.HELP_TEXT.format(Telegram.OWNER_ID),
|
||||
parse_mode=ParseMode.HTML,
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=BUTTON.HELP_BUTTONS
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------
|
||||
|
||||
@FileStream.on_message(filters.command('files') & filters.private)
|
||||
async def my_files(bot: Client, message: Message):
|
||||
if not await verify_user(bot, message):
|
||||
return
|
||||
user_files, total_files = await db.find_files(message.from_user.id, [1, 10])
|
||||
|
||||
file_list = []
|
||||
async for x in user_files:
|
||||
file_list.append([InlineKeyboardButton(x["file_name"], callback_data=f"myfile_{x['_id']}_{1}")])
|
||||
if total_files > 10:
|
||||
file_list.append(
|
||||
[
|
||||
InlineKeyboardButton("◄", callback_data="N/A"),
|
||||
InlineKeyboardButton(f"1/{math.ceil(total_files / 10)}", callback_data="N/A"),
|
||||
InlineKeyboardButton("►", callback_data="userfiles_2")
|
||||
],
|
||||
)
|
||||
if not file_list:
|
||||
file_list.append(
|
||||
[InlineKeyboardButton("ᴇᴍᴘᴛʏ", callback_data="N/A")],
|
||||
)
|
||||
file_list.append([InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")])
|
||||
await message.reply_photo(photo=Telegram.IMAGE_FILEID,
|
||||
caption="Total files: {}".format(total_files),
|
||||
reply_markup=InlineKeyboardMarkup(file_list))
|
||||
|
||||
|
||||
95
FileStream/bot/plugins/stream.py
Normal file
95
FileStream/bot/plugins/stream.py
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
import asyncio
|
||||
from FileStream.bot import FileStream, multi_clients
|
||||
from FileStream.utils.bot_utils import is_user_banned, is_user_exist, is_user_joined, gen_link, is_channel_banned, is_channel_exist, is_user_authorized
|
||||
from FileStream.utils.database import Database
|
||||
from FileStream.utils.file_properties import get_file_ids, get_file_info
|
||||
from FileStream.config import Telegram
|
||||
from pyrogram import filters, Client
|
||||
from pyrogram.errors import FloodWait
|
||||
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from pyrogram.enums.parse_mode import ParseMode
|
||||
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
||||
|
||||
@FileStream.on_message(
|
||||
filters.private
|
||||
& (
|
||||
filters.document
|
||||
| filters.video
|
||||
| filters.video_note
|
||||
| filters.audio
|
||||
| filters.voice
|
||||
| filters.animation
|
||||
| filters.photo
|
||||
),
|
||||
group=4,
|
||||
)
|
||||
async def private_receive_handler(bot: Client, message: Message):
|
||||
if not await is_user_authorized(message):
|
||||
return
|
||||
if await is_user_banned(message):
|
||||
return
|
||||
|
||||
await is_user_exist(bot, message)
|
||||
if Telegram.FORCE_UPDATES_CHANNEL:
|
||||
if not await is_user_joined(bot, message):
|
||||
return
|
||||
try:
|
||||
inserted_id = await db.add_file(get_file_info(message))
|
||||
await get_file_ids(False, inserted_id, multi_clients, message)
|
||||
reply_markup, stream_text = await gen_link(_id=inserted_id)
|
||||
await message.reply_text(
|
||||
text=stream_text,
|
||||
parse_mode=ParseMode.HTML,
|
||||
disable_web_page_preview=True,
|
||||
reply_markup=reply_markup,
|
||||
quote=True
|
||||
)
|
||||
except FloodWait as e:
|
||||
print(f"Sleeping for {str(e.value)}s")
|
||||
await asyncio.sleep(e.value)
|
||||
await bot.send_message(chat_id=Telegram.LOG_CHANNEL,
|
||||
text=f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(e.value)}s from [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n\n**𝚄𝚜𝚎𝚛 𝙸𝙳 :** `{str(message.from_user.id)}`",
|
||||
disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)
|
||||
|
||||
|
||||
@FileStream.on_message(
|
||||
filters.channel
|
||||
& ~filters.forwarded
|
||||
& ~filters.media_group
|
||||
& (
|
||||
filters.document
|
||||
| filters.video
|
||||
| filters.video_note
|
||||
| filters.audio
|
||||
| filters.voice
|
||||
| filters.photo
|
||||
)
|
||||
)
|
||||
async def channel_receive_handler(bot: Client, message: Message):
|
||||
if await is_channel_banned(bot, message):
|
||||
return
|
||||
await is_channel_exist(bot, message)
|
||||
|
||||
try:
|
||||
inserted_id = await db.add_file(get_file_info(message))
|
||||
await get_file_ids(False, inserted_id, multi_clients, message)
|
||||
reply_markup, stream_link = await gen_link(_id=inserted_id)
|
||||
await bot.edit_message_reply_markup(
|
||||
chat_id=message.chat.id,
|
||||
message_id=message.id,
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥",
|
||||
url=f"https://t.me/{FileStream.username}?start=stream_{str(inserted_id)}")]])
|
||||
)
|
||||
|
||||
except FloodWait as w:
|
||||
print(f"Sleeping for {str(w.x)}s")
|
||||
await asyncio.sleep(w.x)
|
||||
await bot.send_message(chat_id=Telegram.LOG_CHANNEL,
|
||||
text=f"ɢᴏᴛ ғʟᴏᴏᴅᴡᴀɪᴛ ᴏғ {str(w.x)}s FROM {message.chat.title}\n\n**CHANNEL ID:** `{str(message.chat.id)}`",
|
||||
disable_web_page_preview=True)
|
||||
except Exception as e:
|
||||
await bot.send_message(chat_id=Telegram.LOG_CHANNEL, text=f"**#EʀʀᴏʀTʀᴀᴄᴋᴇʙᴀᴄᴋ:** `{e}`",
|
||||
disable_web_page_preview=True)
|
||||
print(f"Cᴀɴ'ᴛ Eᴅɪᴛ Bʀᴏᴀᴅᴄᴀsᴛ Mᴇssᴀɢᴇ!\nEʀʀᴏʀ: **Gɪᴠᴇ ᴍᴇ ᴇᴅɪᴛ ᴘᴇʀᴍɪssɪᴏɴ ɪɴ ᴜᴘᴅᴀᴛᴇs ᴀɴᴅ ʙɪɴ Cʜᴀɴɴᴇʟ!{e}**")
|
||||
Reference in New Issue
Block a user