Download Systumm/bot/plugins/start.py from ruhscps/ruhs2: direct link, hf CLI and curl.
- Browser
- Download file 9.29 kB
-
https://huggingface.co/spaces/ruhscps/ruhs2/resolve/main/Systumm/bot/plugins/start.py
- Command line
-
hf download hf://spaces/ruhscps/ruhs2/Systumm/bot/plugins/start.py
-
curl -L -o start.py https://huggingface.co/spaces/ruhscps/ruhs2/resolve/main/Systumm/bot/plugins/start.py
9.29 kB
| import logging | |
| import math | |
| import asyncio | |
| from pyrogram import filters, Client | |
| from pyrogram.errors import FloodWait | |
| from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message | |
| from pyrogram.enums.parse_mode import ParseMode | |
| # --- SYSTUMM BRANDING IMPORTS --- | |
| from Systumm import __version__ | |
| from Systumm.bot import SystummBot | |
| from Systumm.server.exceptions import FIleNotFound | |
| from Systumm.utils.bot_utils import gen_linkx, verify_user | |
| from Systumm.config import Telegram | |
| from Systumm.utils.database import Database | |
| from Systumm.utils.translation import LANG, BUTTON | |
| db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME) | |
| async def start(bot: Client, message: Message): | |
| if not await verify_user(bot, message): | |
| return | |
| usr_cmd = message.text.split("_")[-1] | |
| if usr_cmd == "/start": | |
| if Telegram.START_PIC: | |
| await message.reply_photo( | |
| photo=Telegram.START_PIC, | |
| caption=LANG.START_TEXT.format(message.from_user.mention, SystummBot.username), | |
| parse_mode=ParseMode.HTML, | |
| reply_markup=BUTTON.START_BUTTONS | |
| ) | |
| else: | |
| await message.reply_text( | |
| text=LANG.START_TEXT.format(message.from_user.mention, SystummBot.username), | |
| parse_mode=ParseMode.HTML, | |
| disable_web_page_preview=True, | |
| reply_markup=BUTTON.START_BUTTONS | |
| ) | |
| else: | |
| if "stream_" in message.text: | |
| try: | |
| file_check = await db.get_file(usr_cmd) | |
| file_id = str(file_check['_id']) | |
| if file_id == usr_cmd: | |
| reply_markup, stream_text = await gen_linkx(m=message, _id=file_id, | |
| name=[SystummBot.username, SystummBot.fname]) | |
| await message.reply_text( | |
| text=stream_text, | |
| parse_mode=ParseMode.HTML, | |
| disable_web_page_preview=True, | |
| reply_markup=reply_markup, | |
| quote=True | |
| ) | |
| except FIleNotFound as e: | |
| await message.reply_text("**File Not Found!** ❌") | |
| except Exception as e: | |
| await message.reply_text("**Something Went Wrong!** ⚠️") | |
| logging.error(e) | |
| elif "file_" in message.text: | |
| try: | |
| file_check = await db.get_file(usr_cmd) | |
| db_id = str(file_check['_id']) | |
| file_id = file_check['file_id'] | |
| file_name = file_check['file_name'] | |
| if db_id == usr_cmd: | |
| # Injecting Ajay Yadav branding and 10-min warning into the downloaded file caption | |
| filex = await message.reply_cached_media( | |
| file_id=file_id, | |
| caption=f"**{file_name}**\n\n⚠️ **This file will be deleted after 10 minutes so please save this message by forwarding it to yourself.**\n\n_Made with ♥️ by Ajay Yadav_" | |
| ) | |
| # Wait for 600 seconds (10 Minutes) | |
| await asyncio.sleep(600) | |
| try: | |
| # Delete the media file | |
| await filex.delete() | |
| # Send the replacement text message | |
| await bot.send_message( | |
| chat_id=message.chat.id, | |
| text="❌ **File deleted. Please click 'Get File' again.**\n\n_Made with ♥️ by Ajay Yadav_", | |
| reply_to_message_id=message.id | |
| ) | |
| except Exception: | |
| pass | |
| except FIleNotFound as e: | |
| await message.reply_text("**File Not Found!** ❌") | |
| except Exception as e: | |
| await message.reply_text("**Something Went Wrong!** ⚠️") | |
| logging.error(e) | |
| else: | |
| await message.reply_text("**Invalid Command!** ❌") | |
| async def about_handler(bot: Client, message: Message): | |
| if not await verify_user(bot, message): | |
| return | |
| if Telegram.START_PIC: | |
| await message.reply_photo( | |
| photo=Telegram.START_PIC, | |
| caption=LANG.ABOUT_TEXT.format(SystummBot.fname, __version__), | |
| parse_mode=ParseMode.HTML, | |
| reply_markup=BUTTON.ABOUT_BUTTONS | |
| ) | |
| else: | |
| await message.reply_text( | |
| text=LANG.ABOUT_TEXT.format(SystummBot.fname, __version__), | |
| disable_web_page_preview=True, | |
| reply_markup=BUTTON.ABOUT_BUTTONS | |
| ) | |
| async def help_handler(bot: Client, message: Message): | |
| if not await verify_user(bot, message): | |
| return | |
| if Telegram.START_PIC: | |
| await message.reply_photo( | |
| photo=Telegram.START_PIC, | |
| caption=LANG.HELP_TEXT.format(Telegram.OWNER_ID), | |
| parse_mode=ParseMode.HTML, | |
| reply_markup=BUTTON.HELP_BUTTONS | |
| ) | |
| else: | |
| await message.reply_text( | |
| text=LANG.HELP_TEXT.format(Telegram.OWNER_ID), | |
| parse_mode=ParseMode.HTML, | |
| disable_web_page_preview=True, | |
| reply_markup=BUTTON.HELP_BUTTONS | |
| ) | |
| # --------------------------------------------------------------------------------------------------- | |
| async def my_files(bot: Client, message: Message): | |
| if not await verify_user(bot, message): | |
| return | |
| user_files, total_files = await db.find_files(message.from_user.id, [1, 10]) | |
| file_list = [] | |
| async for x in user_files: | |
| file_list.append([InlineKeyboardButton(x["file_name"], callback_data=f"myfile_{x['_id']}_{1}")]) | |
| if total_files > 10: | |
| file_list.append( | |
| [ | |
| InlineKeyboardButton("◄", callback_data="N/A"), | |
| InlineKeyboardButton(f"1/{math.ceil(total_files / 10)}", callback_data="N/A"), | |
| InlineKeyboardButton("►", callback_data="userfiles_2") | |
| ], | |
| ) | |
| if not file_list: | |
| file_list.append( | |
| [InlineKeyboardButton("ᴇᴍᴘᴛʏ", callback_data="N/A")], | |
| ) | |
| file_list.append([InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]) | |
| # Adding the signature to the user's file list panel | |
| custom_caption = f"**Your Uploaded Files**\nTotal files: {total_files}\n\n_Made with ♥️ by Ajay Yadav_" | |
| if Telegram.FILE_PIC: | |
| await message.reply_photo(photo=Telegram.FILE_PIC, | |
| caption=custom_caption, | |
| reply_markup=InlineKeyboardMarkup(file_list)) | |
| else: | |
| await message.reply_text(text=custom_caption, | |
| reply_markup=InlineKeyboardMarkup(file_list)) | |
| # ----------------------[ ADMIN PURGE COMMAND ]---------------------- | |
| async def purge_server(bot: Client, message: Message): | |
| # 1. Security Check: Only the Owner can use this | |
| if message.from_user.id != Telegram.OWNER_ID: | |
| return | |
| status_msg = await message.reply_text("🧹 **Starting Server Wipe...**\n_Please wait, this might take a moment depending on the number of files._") | |
| deleted_count = 0 | |
| # Fetch EVERY file currently in the database | |
| all_files = db.file.find({}) | |
| async for file_data in all_files: | |
| chat_id = file_data.get("user_id") | |
| user_msg_id = file_data.get("user_msg_id") | |
| log_msg_id = file_data.get("log_msg_id") | |
| db_id = file_data.get("_id") | |
| # 2. Edit User Message (if we have the ID) | |
| if user_msg_id and chat_id: | |
| try: | |
| if str(chat_id).startswith("-100"): | |
| await bot.edit_message_reply_markup(chat_id=chat_id, message_id=user_msg_id, reply_markup=None) | |
| else: | |
| await bot.edit_message_text( | |
| chat_id=chat_id, | |
| message_id=user_msg_id, | |
| text="**⚠️ The generated link has been deleted by the Admin.**", | |
| reply_markup=None | |
| ) | |
| except FloodWait as e: | |
| await asyncio.sleep(e.value) | |
| except Exception: | |
| pass # Ignore if the user already deleted the chat | |
| # 3. Delete Log Channel Message | |
| if log_msg_id: | |
| try: | |
| await bot.delete_messages(chat_id=Telegram.FLOG_CHANNEL, message_ids=log_msg_id) | |
| except Exception: | |
| pass | |
| # 4. Hard Delete from Database | |
| await db.delete_one_file(db_id) | |
| await db.count_links(chat_id, "-") | |
| deleted_count += 1 | |
| # 5. Success Message | |
| await status_msg.edit_text(f"✅ **Server Wipe Complete!**\n\nSuccessfully deleted **{deleted_count}** files from the database and channel.") |