mirror of
https://github.com/TheCaduceus/FileStreamBot.git
synced 2026-01-15 16:33:25 -03:00
Initial commit.
This commit is contained in:
16
bot/modules/decorators.py
Normal file
16
bot/modules/decorators.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from pyrogram import Client
|
||||
from pyrogram.types import Message, CallbackQuery
|
||||
from typing import Union, Callable
|
||||
from functools import wraps
|
||||
from bot.config import Telegram
|
||||
|
||||
def verify_user(func: Callable):
|
||||
|
||||
@wraps(func)
|
||||
async def decorator(client: Client, update: Union[Message, CallbackQuery]):
|
||||
user_id = str(update.from_user.id)
|
||||
|
||||
if not Telegram.ALLOWED_USER_IDS or user_id in Telegram.ALLOWED_USER_IDS:
|
||||
return await func(client, update)
|
||||
|
||||
return decorator
|
||||
48
bot/modules/static.py
Normal file
48
bot/modules/static.py
Normal file
@@ -0,0 +1,48 @@
|
||||
WelcomeText = \
|
||||
"""
|
||||
Hi **%(first_name)s**, send me a file or add me as an admin to any channel to instantly generate file links.
|
||||
|
||||
Add me to your channel to instantly generate links for any downloadable media. Once received, I will automatically attach appropriate buttons to the post containing the URL. If you want me to ignore a given post, you can insert `#pass` in the post.
|
||||
|
||||
- /start to get this message.
|
||||
- /info to get user info.
|
||||
- /log to get bot logs. (admin only!)
|
||||
"""
|
||||
|
||||
FileLinksText = \
|
||||
"""
|
||||
**Download Link:**
|
||||
`%(dl_link)s`
|
||||
**Telegram File:**
|
||||
`%(tg_link)s`
|
||||
"""
|
||||
|
||||
MediaLinksText = \
|
||||
"""
|
||||
**Download Link:**
|
||||
`%(dl_link)s`
|
||||
**Stream Link:**
|
||||
`%(stream_link)s`
|
||||
**Telegram File:**
|
||||
`%(tg_link)s`
|
||||
"""
|
||||
|
||||
InvalidQueryText = \
|
||||
"""
|
||||
Query data mismatched.
|
||||
"""
|
||||
|
||||
MessageNotExist = \
|
||||
"""
|
||||
File revoked or not exist.
|
||||
"""
|
||||
|
||||
LinkRevokedText = \
|
||||
"""
|
||||
The link has been revoked. It may take some time for the changes to take effect.
|
||||
"""
|
||||
|
||||
InvalidPayloadText = \
|
||||
"""
|
||||
Invalid payload.
|
||||
"""
|
||||
56
bot/modules/telegram.py
Normal file
56
bot/modules/telegram.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from pyrogram.types import Message
|
||||
from datetime import datetime
|
||||
from mimetypes import guess_type
|
||||
from bot import TelegramBot
|
||||
from bot.config import Telegram
|
||||
from bot.server.error import abort
|
||||
|
||||
|
||||
async def get_message(message_id: int):
|
||||
message = None
|
||||
|
||||
try:
|
||||
message = await TelegramBot.get_messages(
|
||||
chat_id=Telegram.CHANNEL_ID,
|
||||
message_ids=message_id
|
||||
)
|
||||
if message.empty: message = None
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return message
|
||||
|
||||
async def get_file_properties(msg: Message):
|
||||
attributes = (
|
||||
'document',
|
||||
'video',
|
||||
'audio',
|
||||
'voice',
|
||||
'photo',
|
||||
'video_note'
|
||||
)
|
||||
|
||||
for attribute in attributes:
|
||||
media = getattr(msg, attribute, None)
|
||||
if media:
|
||||
file_type = attribute
|
||||
break
|
||||
|
||||
if not media: abort(400, 'Unknown file type.')
|
||||
|
||||
file_name = getattr(media, 'file_name', None)
|
||||
|
||||
if not file_name:
|
||||
file_format = {
|
||||
'video': 'mp4',
|
||||
'audio': 'mp3',
|
||||
'voice': 'ogg',
|
||||
'photo': 'jpg',
|
||||
'video_note': 'mp4'
|
||||
}.get(attribute)
|
||||
date = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||
file_name = f'{file_type}-{date}.{file_format}'
|
||||
|
||||
mime_type = guess_type(file_name)[0] or 'application/octet-stream'
|
||||
|
||||
return file_name, mime_type
|
||||
Reference in New Issue
Block a user