mirror of
https://github.com/TheCaduceus/FileStreamBot.git
synced 2026-01-15 16:33:25 -03:00
Initial commit.
This commit is contained in:
27
bot/plugins/callback.py
Normal file
27
bot/plugins/callback.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from pyrogram.types import CallbackQuery
|
||||
from bot import TelegramBot
|
||||
from bot.modules.static import *
|
||||
from bot.modules.decorators import verify_user
|
||||
from bot.modules.telegram import get_message
|
||||
|
||||
@TelegramBot.on_callback_query()
|
||||
@verify_user
|
||||
async def manage_callback(bot, q: CallbackQuery):
|
||||
query = q.data
|
||||
if query.startswith('rm_'):
|
||||
sq = query.split('_')
|
||||
|
||||
if len(sq) != 3:
|
||||
return await q.answer(InvalidQueryText, show_alert=True)
|
||||
|
||||
message = await get_message(int(sq[1]))
|
||||
|
||||
if not message:
|
||||
return await q.answer(MessageNotExist, show_alert=True)
|
||||
if sq[2] != message.caption:
|
||||
return await q.answer(InvalidQueryText, show_alert=True)
|
||||
|
||||
await message.delete()
|
||||
await q.answer(LinkRevokedText, show_alert=True)
|
||||
else:
|
||||
await q.answer(InvalidQueryText, show_alert=True)
|
||||
45
bot/plugins/commands.py
Normal file
45
bot/plugins/commands.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from aiofiles import open as async_open
|
||||
from aiofiles.os import remove as async_rm
|
||||
from bot import TelegramBot, logger
|
||||
from bot.config import Telegram
|
||||
from bot.modules.static import *
|
||||
from .deeplinks import deeplinks
|
||||
from bot.modules.decorators import verify_user
|
||||
|
||||
@TelegramBot.on_message(filters.command('start') & filters.private)
|
||||
@verify_user
|
||||
async def start(_, msg: Message):
|
||||
if len(msg.command) != 1:
|
||||
return await deeplinks(msg, msg.command[1])
|
||||
|
||||
await msg.reply(
|
||||
text=WelcomeText % {'first_name': msg.from_user.first_name},
|
||||
quote=True,
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton('Add to Channel', url=f'https://t.me/{Telegram.BOT_USERNAME}?startchannel&admin=post_messages+edit_messages+delete_messages')
|
||||
]
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
@TelegramBot.on_message(filters.command('info') & filters.private)
|
||||
@verify_user
|
||||
async def user_info(_, msg: Message):
|
||||
await msg.reply(text=f'`{msg.from_user}`', quote=True)
|
||||
|
||||
filename = f'{msg.from_user.id}.json'
|
||||
async with async_open(filename, "w") as file:
|
||||
await file.write(f'{msg.from_user}')
|
||||
|
||||
await msg.reply_document(filename)
|
||||
await async_rm(filename)
|
||||
|
||||
@TelegramBot.on_message(filters.private & filters.command('log') & filters.user(Telegram.OWNER_ID))
|
||||
async def send_log(_, msg: Message):
|
||||
await msg.reply_document('event-log.txt', quote=True)
|
||||
|
||||
logger.info('Bot is now started!')
|
||||
21
bot/plugins/deeplinks.py
Normal file
21
bot/plugins/deeplinks.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from pyrogram.types import Message
|
||||
from bot.modules.static import *
|
||||
from bot.modules.telegram import get_message
|
||||
|
||||
async def deeplinks(msg: Message, payload: str):
|
||||
if payload.startswith('file_'):
|
||||
sp = payload.split('_')
|
||||
|
||||
if len(sp) != 3:
|
||||
return await msg.reply(InvalidPayloadText, quote=True)
|
||||
|
||||
message = await get_message(int(sp[1]))
|
||||
|
||||
if not message:
|
||||
return await msg.reply(MessageNotExist)
|
||||
if sp[2] != message.caption:
|
||||
return await msg.reply(InvalidPayloadText, quote=True)
|
||||
|
||||
await message.copy(chat_id=msg.from_user.id, caption="")
|
||||
else:
|
||||
await msg.reply(InvalidPayloadText, quote=True)
|
||||
126
bot/plugins/files.py
Normal file
126
bot/plugins/files.py
Normal file
@@ -0,0 +1,126 @@
|
||||
from pyrogram import filters, errors
|
||||
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from secrets import token_hex
|
||||
from bot import TelegramBot
|
||||
from bot.config import Telegram, Server
|
||||
from bot.modules.decorators import verify_user
|
||||
from bot.modules.static import *
|
||||
|
||||
@TelegramBot.on_message(
|
||||
filters.private
|
||||
& (
|
||||
filters.document
|
||||
| filters.video
|
||||
| filters.video_note
|
||||
| filters.audio
|
||||
| filters.voice
|
||||
| filters.photo
|
||||
)
|
||||
)
|
||||
@verify_user
|
||||
async def handle_user_file(_, msg: Message):
|
||||
secret_code = token_hex(Telegram.SECRET_CODE_LENGTH)
|
||||
file = await msg.copy(
|
||||
chat_id=Telegram.CHANNEL_ID,
|
||||
caption=f'`{secret_code}`'
|
||||
)
|
||||
file_id = file.id
|
||||
|
||||
dl_link = f'{Server.BASE_URL}/dl/{file_id}?code={secret_code}'
|
||||
tg_link = f'{Server.BASE_URL}/file/{file_id}?code={secret_code}'
|
||||
deep_link = f'https://t.me/{Telegram.BOT_USERNAME}?start=file_{file_id}_{secret_code}'
|
||||
|
||||
if (msg.document and 'video' in msg.document.mime_type) or msg.video:
|
||||
stream_link = f'{Server.BASE_URL}/stream/{file_id}?code={secret_code}'
|
||||
await msg.reply(
|
||||
text=MediaLinksText % {'dl_link': dl_link, 'tg_link': tg_link, 'stream_link': stream_link},
|
||||
quote=True,
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton('Download', url=dl_link),
|
||||
InlineKeyboardButton('Stream', url=stream_link)
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton('Get File', url=deep_link),
|
||||
InlineKeyboardButton('Revoke', callback_data=f'rm_{file_id}_{secret_code}')
|
||||
]
|
||||
]
|
||||
)
|
||||
)
|
||||
else:
|
||||
await msg.reply(
|
||||
text=FileLinksText % {'dl_link': dl_link, 'tg_link': tg_link},
|
||||
quote=True,
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton('Download', url=dl_link),
|
||||
InlineKeyboardButton('Get File', url=deep_link)
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton('Revoke', callback_data=f'rm_{file_id}_{secret_code}')
|
||||
]
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
@TelegramBot.on_message(
|
||||
filters.channel
|
||||
& ~filters.forwarded
|
||||
& ~filters.media_group
|
||||
& (
|
||||
filters.document
|
||||
| filters.video
|
||||
| filters.video_note
|
||||
| filters.audio
|
||||
| filters.voice
|
||||
| filters.photo
|
||||
)
|
||||
)
|
||||
@verify_user
|
||||
async def handle_channel_file(_, msg: Message):
|
||||
if msg.caption and '#pass' in msg.caption:
|
||||
return
|
||||
|
||||
secret_code = token_hex(Telegram.SECRET_CODE_LENGTH)
|
||||
|
||||
try:
|
||||
file = await msg.copy(
|
||||
chat_id=Telegram.CHANNEL_ID,
|
||||
caption=f'`{secret_code}`'
|
||||
)
|
||||
except (errors.ChatForwardsRestricted, errors.MessageIdInvalid, errors.ChannelPrivate):
|
||||
return
|
||||
|
||||
file_id = file.id
|
||||
|
||||
dl_link = f'{Server.BASE_URL}/dl/{file_id}?code={secret_code}'
|
||||
tg_link = f'{Server.BASE_URL}/file/{file_id}?code={secret_code}'
|
||||
|
||||
if (msg.document and 'video' in msg.document.mime_type) or msg.video:
|
||||
stream_link = f'{Server.BASE_URL}/stream/{file_id}?code={secret_code}'
|
||||
await msg.edit_reply_markup(
|
||||
InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton('Download', url=dl_link),
|
||||
InlineKeyboardButton('Stream', url=stream_link)
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton('Get File', url=tg_link)
|
||||
]
|
||||
]
|
||||
)
|
||||
)
|
||||
else:
|
||||
await msg.edit_reply_markup(
|
||||
InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton('Download', url=dl_link),
|
||||
InlineKeyboardButton('Get File', url=tg_link)
|
||||
]
|
||||
]
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user