mirror of
https://github.com/avipatilpro/FileStreamBot.git
synced 2026-01-15 14:22:53 -03:00
Initial Commit
This commit is contained in:
@@ -10,6 +10,7 @@ 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
|
||||
import asyncio
|
||||
|
||||
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
||||
|
||||
@@ -63,7 +64,14 @@ async def start(bot: Client, message: Message):
|
||||
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}**')
|
||||
if db_id == usr_cmd:
|
||||
filex = await message.reply_cached_media(file_id=file_id, caption=f'**{file_name}**')
|
||||
await asyncio.sleep(3600)
|
||||
try:
|
||||
await filex.delete()
|
||||
await message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
except FIleNotFound as e:
|
||||
await message.reply_text("**File Not Found**")
|
||||
|
||||
@@ -31,7 +31,7 @@ async def private_receive_handler(bot: Client, message: Message):
|
||||
return
|
||||
|
||||
await is_user_exist(bot, message)
|
||||
if Telegram.FORCE_UPDATES_CHANNEL:
|
||||
if Telegram.FORCE_SUB:
|
||||
if not await is_user_joined(bot, message):
|
||||
return
|
||||
try:
|
||||
|
||||
@@ -12,8 +12,9 @@ class Telegram:
|
||||
DATABASE_URL = str(env.get('DATABASE_URL'))
|
||||
UPDATES_CHANNEL = str(env.get('UPDATES_CHANNEL', "Telegram"))
|
||||
SESSION_NAME = str(env.get('SESSION_NAME', 'FileStream'))
|
||||
FORCE_UPDATES_CHANNEL = env.get('FORCE_UPDATES_CHANNEL', False)
|
||||
FORCE_UPDATES_CHANNEL = True if str(FORCE_UPDATES_CHANNEL).lower() == "true" else False
|
||||
FORCE_SUB_ID = env.get('FORCE_SUB_ID', None)
|
||||
FORCE_SUB = env.get('FORCE_UPDATES_CHANNEL', False)
|
||||
FORCE_SUB = True if str(FORCE_SUB).lower() == "true" else False
|
||||
SLEEP_THRESHOLD = int(env.get("SLEEP_THRESHOLD", "60"))
|
||||
FILE_PIC = env.get('FILE_PIC', "https://graph.org/file/5bb9935be0229adf98b73.jpg")
|
||||
START_PIC = env.get('START_PIC', "https://graph.org/file/290af25276fa34fa8f0aa.jpg")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from pyrogram.errors import UserNotParticipant
|
||||
from pyrogram.errors import UserNotParticipant, FloodWait
|
||||
from pyrogram.enums.parse_mode import ParseMode
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
|
||||
from FileStream.utils.translation import LANG
|
||||
@@ -6,12 +6,32 @@ from FileStream.utils.database import Database
|
||||
from FileStream.utils.human_readable import humanbytes
|
||||
from FileStream.config import Telegram, Server
|
||||
from FileStream.bot import FileStream
|
||||
import asyncio
|
||||
from typing import (
|
||||
Union
|
||||
)
|
||||
|
||||
|
||||
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
||||
|
||||
async def is_user_joined(bot, message: Message):
|
||||
async def get_invite_link(bot, chat_id: Union[str, int]):
|
||||
try:
|
||||
user = await bot.get_chat_member(Telegram.UPDATES_CHANNEL, message.chat.id)
|
||||
invite_link = await bot.create_chat_invite_link(chat_id=chat_id)
|
||||
return invite_link
|
||||
except FloodWait as e:
|
||||
print(f"Sleep of {e.value}s caused by FloodWait ...")
|
||||
await asyncio.sleep(e.value)
|
||||
return await get_invite_link(bot, chat_id)
|
||||
|
||||
async def is_user_joined(bot, message: Message):
|
||||
if Telegram.FORCE_SUB_ID and Telegram.FORCE_SUB_ID.startswith("-100"):
|
||||
channel_chat_id = int(Telegram.FORCE_SUB_ID) # When id startswith with -100
|
||||
elif Telegram.FORCE_SUB_ID and (not Telegram.FORCE_SUB_ID.startswith("-100")):
|
||||
channel_chat_id = Telegram.FORCE_SUB_ID # When id not startswith -100
|
||||
else:
|
||||
return 200
|
||||
try:
|
||||
user = await bot.get_chat_member(chat_id=channel_chat_id, user_id=message.from_user.id)
|
||||
if user.status == "BANNED":
|
||||
await message.reply_text(
|
||||
text=LANG.BAN_TEXT.format(Telegram.OWNER_ID),
|
||||
@@ -20,27 +40,34 @@ async def is_user_joined(bot, message: Message):
|
||||
)
|
||||
return False
|
||||
except UserNotParticipant:
|
||||
invite_link = await get_invite_link(bot, chat_id=channel_chat_id)
|
||||
if Telegram.VERIFY_PIC:
|
||||
await message.reply_photo(
|
||||
ver = 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}")
|
||||
]]
|
||||
[[
|
||||
InlineKeyboardButton("❆ Jᴏɪɴ Oᴜʀ Cʜᴀɴɴᴇʟ ❆", url=invite_link.invite_link)
|
||||
]]
|
||||
)
|
||||
)
|
||||
else:
|
||||
await message.reply_text(
|
||||
text="<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
|
||||
ver = await message.reply_text(
|
||||
text = "<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[[
|
||||
InlineKeyboardButton("Jᴏɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Telegram.UPDATES_CHANNEL}")
|
||||
InlineKeyboardButton("❆ Jᴏɪɴ Oᴜʀ Cʜᴀɴɴᴇʟ ❆", url=invite_link.invite_link)
|
||||
]]
|
||||
),
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
await asyncio.sleep(30)
|
||||
try:
|
||||
await ver.delete()
|
||||
await message.delete()
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
except Exception:
|
||||
await message.reply_text(
|
||||
@@ -182,7 +209,7 @@ async def verify_user(bot, message):
|
||||
|
||||
await is_user_exist(bot, message)
|
||||
|
||||
if Telegram.FORCE_UPDATES_CHANNEL:
|
||||
if Telegram.FORCE_SUB:
|
||||
if not await is_user_joined(bot, message):
|
||||
return False
|
||||
|
||||
|
||||
@@ -144,7 +144,8 @@ PORT = 8080
|
||||
#### 🪐 Optional Vars :
|
||||
|
||||
* `UPDATES_CHANNEL`: Channel Username without `@` to set channel as Update Channel `str`
|
||||
* `FORCE_UPDATES_CHANNEL`: Set to True, so every user have to Join update channel to use the bot. `bool`
|
||||
* `FORCE_SUB_ID`: Force Sub Channel ID, if you want to use Force Sub. start with `-100` `int
|
||||
* `FORCE_SUB`: Set to True, so every user have to Join update channel to use the bot. `bool`
|
||||
* `AUTH_USERS`: Put authorized user IDs to use bot, separated by <kbd>Space</kbd>. `int`
|
||||
* `SLEEP_THRESHOLD`: Set global flood wait threshold, auto-retry requests under 60s. `int`
|
||||
* `SESSION_NAME`: Name for the Database created on your MongoDB. Defaults to `FileStream`. `str`
|
||||
|
||||
38
app.json
38
app.json
@@ -23,8 +23,11 @@
|
||||
"BOT_TOKEN": {
|
||||
"description": "Get this value from @BotFather"
|
||||
},
|
||||
"LOG_CHANNEL": {
|
||||
"description": "The BIN Channel ID. Read the readme for more info about this var"
|
||||
"FLOG_CHANNEL": {
|
||||
"description": "ID of Channel Where store files sent by users. Read the readme for more info about this var"
|
||||
},
|
||||
"ULOG_CHANNEL": {
|
||||
"description": "ID of Channel Where store New Users data. Read the readme for more info about this var"
|
||||
},
|
||||
"OWNER_ID": {
|
||||
"description": "Your Telegram User ID as Owner"
|
||||
@@ -40,7 +43,11 @@
|
||||
"description": "Channel Username without `@` to set channel as Update Channel",
|
||||
"required": false
|
||||
},
|
||||
"FORCE_UPDATES_CHANNEL": {
|
||||
"FORCE_SUB_ID": {
|
||||
"description": "Channel ID starts with -100 to set channel as Force Sub Channel",
|
||||
"required": false
|
||||
},
|
||||
"FORCE_SUB": {
|
||||
"description": "Set to True, so every user have to Join update channel to use the bot.",
|
||||
"required": false
|
||||
},
|
||||
@@ -48,10 +55,6 @@
|
||||
"description": "Set global flood wait threshold, auto-retry requests under 60s. ",
|
||||
"required": false
|
||||
},
|
||||
"PING_INTERVAL": {
|
||||
"description": " Heroku ping interval (ms), defaults to 1200 (20 minutes).",
|
||||
"required": false
|
||||
},
|
||||
"WORKERS": {
|
||||
"description": "No. of workers that is to be assigned.",
|
||||
"required": false
|
||||
@@ -70,27 +73,30 @@
|
||||
"value": "True",
|
||||
"required": false
|
||||
},
|
||||
"KEEP_ALIVE": {
|
||||
"description": "Self-ping server every PING_INTERVAL sec to avoid sleeping",
|
||||
"value": "True",
|
||||
"required": false
|
||||
},
|
||||
"BIND_ADRESS": {
|
||||
"description": "Your server bind adress. Defauls to 0.0.0.0",
|
||||
"BIND_ADDRESS": {
|
||||
"description": "Your server bind address. default to 0.0.0.0",
|
||||
"required": false
|
||||
},
|
||||
"FQDN": {
|
||||
"description": "Heroku app Link without http/s, you can set later. its required",
|
||||
"description": "Heroku app Link without http/s://, you can set later. its required",
|
||||
"required": false
|
||||
},
|
||||
"SESSION_NAME": {
|
||||
"description": "Name for the Database created on your MongoDB. Defaults to FileStream",
|
||||
"required": false
|
||||
},
|
||||
"IMAGE_FILEID": {
|
||||
"FILE_PIC": {
|
||||
"description": "To set Image at /files command. Defaults to pre-set image.",
|
||||
"required": false
|
||||
},
|
||||
"START_PIC": {
|
||||
"description": "To set Image at /start command. Defaults to pre-set image.",
|
||||
"required": false
|
||||
},
|
||||
"VERIFY_PIC": {
|
||||
"description": "To set Image at Force Subscribe Verify. Defaults to pre-set image.",
|
||||
"required": false
|
||||
},
|
||||
"MODE": {
|
||||
"description": "Should be set to `secondary` if you only want to use the server for serving files.",
|
||||
"required": false
|
||||
|
||||
Reference in New Issue
Block a user