From d6ec5ff4d6bc47935f1ac5114835b4881d364c3e Mon Sep 17 00:00:00 2001 From: Avi Patil Date: Sat, 6 Jan 2024 22:31:43 +0530 Subject: [PATCH] Initial Commit --- FileStream/bot/plugins/start.py | 10 ++++++- FileStream/bot/plugins/stream.py | 2 +- FileStream/config.py | 5 ++-- FileStream/utils/bot_utils.py | 49 +++++++++++++++++++++++++------- README.md | 3 +- app.json | 38 ++++++++++++++----------- 6 files changed, 75 insertions(+), 32 deletions(-) diff --git a/FileStream/bot/plugins/start.py b/FileStream/bot/plugins/start.py index b2fe645..075c8ba 100644 --- a/FileStream/bot/plugins/start.py +++ b/FileStream/bot/plugins/start.py @@ -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**") diff --git a/FileStream/bot/plugins/stream.py b/FileStream/bot/plugins/stream.py index cca7e4d..d405131 100644 --- a/FileStream/bot/plugins/stream.py +++ b/FileStream/bot/plugins/stream.py @@ -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: diff --git a/FileStream/config.py b/FileStream/config.py index b958365..48c49c8 100644 --- a/FileStream/config.py +++ b/FileStream/config.py @@ -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") diff --git a/FileStream/utils/bot_utils.py b/FileStream/utils/bot_utils.py index b241a10..e40d7f6 100644 --- a/FileStream/utils/bot_utils.py +++ b/FileStream/utils/bot_utils.py @@ -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="Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐", 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="Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐", + ver = await message.reply_text( + text = "Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐", 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 diff --git a/README.md b/README.md index 8034e57..7f86eed 100644 --- a/README.md +++ b/README.md @@ -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 Space. `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` diff --git a/app.json b/app.json index 5056cac..3f5d59b 100644 --- a/app.json +++ b/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