mirror of
https://github.com/avipatilpro/FileStreamBot.git
synced 2026-01-16 06:42:54 -03:00
Minor Changes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from .keepalive import ping_server
|
||||
from .time_format import get_readable_time
|
||||
from .file_properties import get_name, get_file_ids
|
||||
from .custom_dl import ByteStreamer
|
||||
@@ -20,15 +20,27 @@ async def is_user_joined(bot, message: Message):
|
||||
)
|
||||
return False
|
||||
except UserNotParticipant:
|
||||
await message.reply_text(
|
||||
text = "<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[[
|
||||
InlineKeyboardButton("Jᴏɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Telegram.UPDATES_CHANNEL}")
|
||||
]]
|
||||
),
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
if Telegram.VERIFY_PIC:
|
||||
await message.reply_photo(
|
||||
photo=Telegram.VERIFY_PIC,
|
||||
caption="<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
|
||||
parse_mode=ParseMode.HTML,
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[[
|
||||
InlineKeyboardButton("Jᴏɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Telegram.UPDATES_CHANNEL}")
|
||||
]]
|
||||
)
|
||||
)
|
||||
else:
|
||||
await message.reply_text(
|
||||
text="<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[[
|
||||
InlineKeyboardButton("Jᴏɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Telegram.UPDATES_CHANNEL}")
|
||||
]]
|
||||
),
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
return False
|
||||
except Exception:
|
||||
await message.reply_text(
|
||||
@@ -134,7 +146,7 @@ async def is_user_authorized(message):
|
||||
|
||||
if not (user_id in Telegram.AUTH_USERS):
|
||||
await message.reply_text(
|
||||
text="You are not authorized to use this bot.",
|
||||
text="Yᴏᴜ ᴀʀᴇ ɴᴏᴛ ᴀᴜᴛʜᴏʀɪᴢᴇᴅ ᴛᴏ ᴜsᴇ ᴛʜɪs ʙᴏᴛ.",
|
||||
parse_mode=ParseMode.MARKDOWN,
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
@@ -148,7 +160,7 @@ async def is_user_exist(bot, message):
|
||||
if not bool(await db.get_user(message.from_user.id)):
|
||||
await db.add_user(message.from_user.id)
|
||||
await bot.send_message(
|
||||
Telegram.LOG_CHANNEL,
|
||||
Telegram.ULOG_CHANNEL,
|
||||
f"**#NᴇᴡUsᴇʀ**\n**⬩ ᴜsᴇʀ ɴᴀᴍᴇ :** [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n**⬩ ᴜsᴇʀ ɪᴅ :** `{message.from_user.id}`"
|
||||
)
|
||||
|
||||
@@ -157,7 +169,7 @@ async def is_channel_exist(bot, message):
|
||||
await db.add_user(message.chat.id)
|
||||
members = await bot.get_chat_members_count(message.chat.id)
|
||||
await bot.send_message(
|
||||
Telegram.LOG_CHANNEL,
|
||||
Telegram.ULOG_CHANNEL,
|
||||
f"**#NᴇᴡCʜᴀɴɴᴇʟ** \n**⬩ ᴄʜᴀᴛ ɴᴀᴍᴇ :** `{message.chat.title}`\n**⬩ ᴄʜᴀᴛ ɪᴅ :** `{message.chat.id}`\n**⬩ ᴛᴏᴛᴀʟ ᴍᴇᴍʙᴇʀs :** `{members}`"
|
||||
)
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@ class Database:
|
||||
return dict(
|
||||
id=id,
|
||||
join_date=time.time(),
|
||||
agreed_to_tos=False,
|
||||
Links=0,
|
||||
Plan="Free"
|
||||
Links=0
|
||||
)
|
||||
|
||||
# ---------------------[ ADD USER ]---------------------#
|
||||
@@ -119,15 +117,15 @@ class Database:
|
||||
await self.file.update_one({"_id": ObjectId(_id)}, {"$set": {"file_ids": file_ids}})
|
||||
|
||||
# ---------------------[ PAID SYS ]---------------------#
|
||||
async def link_available(self, id):
|
||||
user = await self.col.find_one({"id": id})
|
||||
if user.get("Plan") == "Plus":
|
||||
return "Plus"
|
||||
elif user.get("Plan") == "Free":
|
||||
files = await self.file.count_documents({"user_id": id})
|
||||
if files < 11:
|
||||
return True
|
||||
return False
|
||||
# async def link_available(self, id):
|
||||
# user = await self.col.find_one({"id": id})
|
||||
# if user.get("Plan") == "Plus":
|
||||
# return "Plus"
|
||||
# elif user.get("Plan") == "Free":
|
||||
# files = await self.file.count_documents({"user_id": id})
|
||||
# if files < 11:
|
||||
# return True
|
||||
# return False
|
||||
|
||||
async def count_links(self, id, operation: str):
|
||||
if operation == "-":
|
||||
|
||||
@@ -30,7 +30,7 @@ async def get_file_ids(client: Client | bool, db_id: str, multi_clients, message
|
||||
if not str(client.id) in file_id_info:
|
||||
logging.debug("Storing file_id in DB")
|
||||
log_msg = await send_file(FileStream, db_id, file_info['file_id'], message)
|
||||
msg = await client.get_messages(Telegram.LOG_CHANNEL, log_msg.id)
|
||||
msg = await client.get_messages(Telegram.FLOG_CHANNEL, log_msg.id)
|
||||
media = get_media_from_message(msg)
|
||||
file_id_info[str(client.id)] = getattr(media, "file_id", "")
|
||||
await db.update_file_ids(db_id, file_id_info)
|
||||
@@ -118,7 +118,7 @@ def get_file_info(message):
|
||||
async def update_file_id(msg_id, multi_clients):
|
||||
file_ids = {}
|
||||
for client_id, client in multi_clients.items():
|
||||
log_msg = await client.get_messages(Telegram.LOG_CHANNEL, msg_id)
|
||||
log_msg = await client.get_messages(Telegram.FLOG_CHANNEL, msg_id)
|
||||
media = get_media_from_message(log_msg)
|
||||
file_ids[str(client.id)] = getattr(media, "file_id", "")
|
||||
|
||||
@@ -126,10 +126,8 @@ async def update_file_id(msg_id, multi_clients):
|
||||
|
||||
|
||||
async def send_file(client: Client, db_id, file_id: str, message):
|
||||
file_caption = message.caption
|
||||
if file_caption is None:
|
||||
file_caption = message.file_name
|
||||
log_msg = await client.send_cached_media(chat_id=Telegram.LOG_CHANNEL, file_id=file_id,
|
||||
file_caption = getattr(message, 'caption', None) or get_name(message)
|
||||
log_msg = await client.send_cached_media(chat_id=Telegram.FLOG_CHANNEL, file_id=file_id,
|
||||
caption=f'**{file_caption}**')
|
||||
|
||||
if message.chat.type == ChatType.PRIVATE:
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import aiohttp
|
||||
import traceback
|
||||
from FileStream.config import Server
|
||||
|
||||
async def ping_server():
|
||||
sleep_time = Server.PING_INTERVAL
|
||||
while True:
|
||||
await asyncio.sleep(sleep_time)
|
||||
try:
|
||||
async with aiohttp.ClientSession(
|
||||
timeout=aiohttp.ClientTimeout(total=10)
|
||||
) as session:
|
||||
async with session.get(Server.URL) as resp:
|
||||
logging.info("Pinged server with response: {}".format(resp.status))
|
||||
except TimeoutError:
|
||||
logging.warning("Couldn't connect to the site URL..!")
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
@@ -1,5 +1,5 @@
|
||||
import aiohttp
|
||||
import aiofiles
|
||||
import jinja2
|
||||
import urllib.parse
|
||||
from FileStream.config import Telegram, Server
|
||||
from FileStream.utils.database import Database
|
||||
@@ -9,17 +9,22 @@ db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
||||
async def render_page(db_id):
|
||||
file_data=await db.get_file(db_id)
|
||||
src = urllib.parse.urljoin(Server.URL, f'dl/{file_data["_id"]}')
|
||||
file_size = humanbytes(file_data['file_size'])
|
||||
file_name = file_data['file_name'].replace("_", " ")
|
||||
|
||||
if str((file_data['mime_type']).split('/')[0].strip()) == 'video':
|
||||
async with aiofiles.open('FileStream/template/stream.html') as r:
|
||||
heading = 'Watch {}'.format(file_data['file_name'])
|
||||
html_template = await r.read()
|
||||
html = html_template.replace('streamMediaLink', src).replace('streamHeading', heading)
|
||||
template_file = "FileStream/template/play.html"
|
||||
else:
|
||||
async with aiofiles.open('FileStream/template/dl.html') as r:
|
||||
async with aiohttp.ClientSession() as s:
|
||||
async with s.get(src) as u:
|
||||
heading = 'Download {}'.format(file_data['file_name'])
|
||||
file_size = humanbytes(int(u.headers.get('Content-Length')))
|
||||
html = (await r.read()) % (heading, file_data['file_name'], src, file_size)
|
||||
return html
|
||||
template_file = "FileStream/template/dl.html"
|
||||
async with aiohttp.ClientSession() as s:
|
||||
async with s.get(src) as u:
|
||||
file_size = humanbytes(int(u.headers.get('Content-Length')))
|
||||
|
||||
with open(template_file) as f:
|
||||
template = jinja2.Template(f.read())
|
||||
|
||||
return template.render(
|
||||
file_name=file_name,
|
||||
file_url=src,
|
||||
file_size=file_size
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ class LANG(object):
|
||||
ABOUT_TEXT = """
|
||||
<b>⚜ ᴍʏ ɴᴀᴍᴇ : {}</b>\n
|
||||
<b>✦ ᴠᴇʀsɪᴏɴ : {}</b>
|
||||
<b>✦ ᴜᴘᴅᴀᴛᴇᴅ ᴏɴ : 19-November-2023</b>
|
||||
<b>✦ ᴜᴘᴅᴀᴛᴇᴅ ᴏɴ : 06-January-2024</b>
|
||||
<b>✦ ᴅᴇᴠᴇʟᴏᴘᴇʀ : <a href='https://telegram.me/AvishkarPatil'>Avishkar Patil</a></b>\n
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user