src / bot.py
Agnivesh10M's picture
Update bot.py
3a7dcf2 verified
Raw History Blame Contribute Delete
44.4 kB
import asyncio
import time
from datetime import datetime, timezone
from pyrogram import Client, filters
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated
from config import API_ID, API_HASH, BOT_TOKEN, ADMINS, OWNER_HANDLE, SUPPORT_GROUP
from db import db
try:
import pyromod
except ImportError:
pass
PAYMENT_IMG_URL = "https://files.catbox.moe/vnrhxg.jpg"
TUTORIAL_VIDEO_URL = "https://t.me/srcbysachin/19"
PHONEPE_LINK = "https://phon.pe/4fjyavab"
PENDING_BROADCASTS = {}
class Bot(Client):
def __init__(self):
super().__init__(
"SACHIN_SHARMA",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
plugins=dict(root="TechVJ"),
workers=150,
max_concurrent_transmissions=16,
sleep_threshold=5
)
async def start(self):
await super().start()
print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
print("SACHIN SHARMA Bot Started Successfully!")
print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
async def stop(self, *args):
await super().stop()
print("SACHIN SHARMA Bot Stopped.")
bot = Bot()
def is_admin(user_id: int) -> bool:
if isinstance(ADMINS, list):
return int(user_id) in [int(x) for x in ADMINS]
return int(user_id) == int(ADMINS)
def get_lang_prompt_markup():
return InlineKeyboardMarkup([
[
InlineKeyboardButton("🇮🇳 हिंदी", callback_data="setlang_hi"),
InlineKeyboardButton("🇬🇧 English", callback_data="setlang_en")
]
])
def get_start_panel(name: str, is_adm: bool = False, lang: str = "hi"):
if lang == "en":
admin_tag = "\n👑 **(You are the Bot Owner - Lifetime Access)**\n" if is_adm else ""
text = (
f"👋 **Welcome to Save Restricted Content Bot!**{admin_tag}\n"
"━━━━━━━━━━━━━━━━━━━━\n\n"
"Clone or forward files from any **private or public** Telegram channel/group — "
"even if forwarding is restricted. Topics/Threads are fully supported.\n\n"
"✅ Dedicated 1 GB RAM per user\n"
"✅ Forward-restricted channel/group supported\n"
"✅ Topics/Threads groups supported\n"
"✅ 2GB+ files · Smart caption & filename editing\n"
"✅ Custom transfer thumbnail support\n\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"Select an option from the menu below:"
)
buttons = InlineKeyboardMarkup([
[
InlineKeyboardButton("💎 VIP Plans & Pricing", callback_data="nav_plans"),
InlineKeyboardButton("💳 How to Pay?", callback_data="nav_payment")
],
[
InlineKeyboardButton("📖 User Guide & Video", callback_data="nav_howtouse"),
InlineKeyboardButton("📢 Channel Upload Guide", callback_data="nav_channelhelp")
],
[
InlineKeyboardButton("⚡ Slow Speed Reason?", callback_data="nav_speedhelp"),
InlineKeyboardButton("📊 My Status", callback_data="nav_myplan")
],
[
InlineKeyboardButton("🌐 Change Language", callback_data="nav_lang"),
InlineKeyboardButton("💬 Support Group", url=SUPPORT_GROUP)
],
[
InlineKeyboardButton("👤 Contact Owner", url=f"https://t.me/{OWNER_HANDLE.replace('@', '')}")
]
])
else:
admin_tag = "\n👑 **(आप इस बॉट के ओनर हैं - लाइफटाइम एक्सेस)**\n" if is_adm else ""
text = (
f"👋 **Welcome to Save Restricted Content Bot!**{admin_tag}\n"
"━━━━━━━━━━━━━━━━━━━━\n\n"
"Kisi bhi **private ya public** Telegram channel/group se files clone karo — "
"chahe **forwarding band (Restricted)** ho tab bhi. Topics/Threads bhi supported hain.\n\n"
"✅ Dedicated 1 GB RAM per user\n"
"✅ Forward-restricted channel/group supported\n"
"✅ Topics/Threads groups supported\n"
"✅ 2GB+ files · Smart caption & filename editing\n"
"✅ Custom transfer thumbnail support\n\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"नीचे दिए गए मेन्यू में से विकल्प चुनें:"
)
buttons = InlineKeyboardMarkup([
[
InlineKeyboardButton("💎 VIP प्लान्स & कीमतें", callback_data="nav_plans"),
InlineKeyboardButton("💳 पेमेंट कैसे करें?", callback_data="nav_payment")
],
[
InlineKeyboardButton("📖 बॉट कैसे चलाएं (गाइड & वीडियो)", callback_data="nav_howtouse"),
InlineKeyboardButton("📢 चैनल में अपलोड कैसे करें?", callback_data="nav_channelhelp")
],
[
InlineKeyboardButton("⚡ स्पीड कम क्यों मिल रही है?", callback_data="nav_speedhelp"),
InlineKeyboardButton("📊 मेरा स्टेटस", callback_data="nav_myplan")
],
[
InlineKeyboardButton("🌐 भाषा बदलें (Language)", callback_data="nav_lang"),
InlineKeyboardButton("💬 सपोर्ट ग्रुप", url=SUPPORT_GROUP)
],
[
InlineKeyboardButton("👤 ओनर से संपर्क करें", url=f"https://t.me/{OWNER_HANDLE.replace('@', '')}")
]
])
return text, buttons
def get_back_button(lang: str = "hi"):
btn_text = "🔙 Back to Main Menu" if lang == "en" else "🔙 मुख्य मेन्यू पर लौटें"
return InlineKeyboardMarkup([
[InlineKeyboardButton(btn_text, callback_data="nav_home")]
])
def get_plans_text(lang: str = "hi"):
plans = db.get_all_plans()
if lang == "en":
return (
"💎 **Our VIP Membership Plans** 💎\n"
"━━━━━━━━━━━━━━━━━━━━\n"
f"🔹 **1 Day (Trial Plan):** ₹{plans.get('1day', '20')}\n"
f"🔹 **5 Days (Super Saver):** ₹{plans.get('5days', '50')}\n"
f"🔹 **15 Days (Best Value):** ₹{plans.get('15days', '120')}\n"
f"🔹 **30 Days (Monthly Unlimited):** ₹{plans.get('30days', '199')}\n\n"
"🔥 **Features Included in All Plans:**\n"
"• Unlimited files, videos & PDFs transfer\n"
"• 16 parallel workers high-speed download/upload\n"
"• 2GB+ file support with custom thumbnails\n"
"• Auto-caption replace & forum topics support\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"Click **'💳 How to Pay'** below to activate."
)
return (
"💎 **हमारे VIP मेम्बरशिप प्लान्स** 💎\n"
"━━━━━━━━━━━━━━━━━━━━\n"
f"🔹 **1 दिन (ट्रायल प्लान):** ₹{plans.get('1day', '20')}\n"
f"🔹 **5 दिन (सुपर सेवर):** ₹{plans.get('5days', '50')}\n"
f"🔹 **15 दिन (बेस्ट वैल्यू):** ₹{plans.get('15days', '120')}\n"
f"🔹 **30 दिन (मंथली अनलिमिटेड):** ₹{plans.get('30days', '199')}\n\n"
"🔥 **सभी प्लान्स में शामिल:**\n"
"• अनलिमिटेड फाइल्स, वीडियो व PDFs ट्रांसफर\n"
"• 16 पैरेलल वर्कर्स सुपरफास्ट डाउनलोड/अपलोड\n"
"• 2GB+ फ़ाइल सपोर्ट व कस्टम थंबनेल\n"
"• ऑटो-कैप्शन रिप्लेस व टॉपिक ग्रुप सपोर्ट\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"पेमेंट करने के लिए नीचे **'💳 पेमेंट कैसे करें'** बटन दबाएँ।"
)
def get_plans_buttons(lang: str = "hi"):
pay_txt = "💳 How to Pay?" if lang == "en" else "💳 पेमेंट कैसे करें?"
back_txt = "🔙 Back to Main Menu" if lang == "en" else "🔙 मुख्य मेन्यू पर लौटें"
return InlineKeyboardMarkup([
[InlineKeyboardButton(pay_txt, callback_data="nav_payment")],
[InlineKeyboardButton(back_txt, callback_data="nav_home")]
])
def get_payment_caption(lang: str = "hi"):
plans = db.get_all_plans()
if lang == "en":
return (
"💳 **VIP Plan Payment Guide (PhonePe Gift Card)**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"We strictly accept payments via **PhonePe Gift Card**.\n\n"
f"💰 **Plan Prices:** ₹{plans.get('1day', '20')} (1D) | ₹{plans.get('5days', '50')} (5D) | ₹{plans.get('15days', '120')} (15D) | ₹{plans.get('30days', '199')} (30D)\n\n"
"📌 **Simple Payment Steps:**\n"
"1️⃣ Click the link below to open PhonePe directly:\n"
f"👉 [Click here to buy PhonePe Gift Card]({PHONEPE_LINK})\n\n"
"2️⃣ In PhonePe, select **'Buy New Gift Card'**.\n"
"3️⃣ Enter the exact amount for your chosen plan & complete the payment.\n"
"4️⃣ After payment, you will receive a **16-digit Card Number** & a **6-digit PIN** (as shown in the image above).\n"
f"5️⃣ Copy and send the Card Number & PIN to Admin {OWNER_HANDLE}.\n\n"
"⚡ Your VIP Plan will be activated within 2 minutes!"
)
return (
"💳 **VIP प्लान पेमेंट प्रक्रिया (PhonePe Gift Card)**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"हमारा बॉट केवल **PhonePe Gift Card** द्वारा पेमेंट स्वीकार करता है।\n\n"
f"💰 **प्लान राशि:** ₹{plans.get('1day', '20')} (1D) | ₹{plans.get('5days', '50')} (5D) | ₹{plans.get('15days', '120')} (15D) | ₹{plans.get('30days', '199')} (30D)\n\n"
"📌 **आसान पेमेंट स्टेप्स:**\n"
"1️⃣ नीचे दिए गए लिंक पर क्लिक करें (सीधे PhonePe खुलेगा):\n"
f"👉 [यहाँ क्लिक करके PhonePe गिफ्ट कार्ड खरीदें]({PHONEPE_LINK})\n\n"
"2️⃣ PhonePe में **'Buy New Gift Card'** चुनें।\n"
"3️⃣ अपने चुने हुए प्लान की सही राशि दर्ज करके पेमेंट पूरा करें।\n"
"4️⃣ पेमेंट के बाद आपको **16 अंकों का कार्ड नंबर** और **6 अंकों का पिन** मिलेगा (जैसा ऊपर फोटो में दिखाया गया है)।\n"
f"5️⃣ वह कार्ड नंबर और पिन कॉपी करके एडमिन {OWNER_HANDLE} को भेजें।\n\n"
"⚡ आपका VIP प्लान 2 मिनट के अंदर एक्टिवेट कर दिया जाएगा!"
)
def get_payment_buttons(lang: str = "hi"):
link_txt = "🚀 Open PhonePe Gift Card" if lang == "en" else "🚀 PhonePe Gift Card खोलें"
send_txt = "👤 Send Code to Admin" if lang == "en" else "👤 कोड एडमिन को भेजें"
back_txt = "🔙 Back to Main Menu" if lang == "en" else "🔙 मुख्य मेन्यू पर लौटें"
return InlineKeyboardMarkup([
[InlineKeyboardButton(link_txt, url=PHONEPE_LINK)],
[InlineKeyboardButton(send_txt, url=f"https://t.me/{OWNER_HANDLE.replace('@', '')}")],
[InlineKeyboardButton(back_txt, callback_data="nav_home")]
])
def get_howtouse_text(lang: str = "hi"):
if lang == "en":
return (
"📖 **How to Use the Bot (Step-by-Step Guide):**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"1️⃣ **Step 1 — Connect Account:**\n"
"• Send `/login` and provide your phone number with country code (`+91XXXXXXXXXX`).\n"
"• Enter the OTP code received on Telegram.\n\n"
"2️⃣ **Step 2 — Start Transfer:**\n"
"• Send `/clone`.\n"
"• Send the starting post link.\n"
"• Send the ending post link (or `/single` for one file).\n"
"• Send target channel ID or username (or `/skip` to receive directly in bot DM).\n"
"💡 *For forum topics, provide ID as `-100xxxx:topic_id`*\n\n"
"3️⃣ **Step 3 — Settings & Confirmation:**\n"
"• Set custom captions or thumbnails, then click **Confirm & Start**!\n\n"
"🔄 **Resume Task:** If interrupted, send `/resume` to continue.\n"
"🛑 **Cancel Task:** Send `/cancel` to stop immediately.\n\n"
"🎥 **Watch Video Walkthrough:**\n"
f"👉 [Click here to watch the full video tutorial]({TUTORIAL_VIDEO_URL})"
)
return (
"📖 **बॉट इस्तेमाल करने के आसान स्टेप्स:**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"1️⃣ **स्टेप 1 — लॉगिन करें:**\n"
"• `/login` कमांड भेजें और अपना नंबर कंट्री कोड के साथ डालें (`+91XXXXXXXXXX`)।\n"
"• टेलीग्राम से आया हुआ OTP दर्ज करें।\n\n"
"2️⃣ **स्टेप 2 — टास्क शुरू करें:**\n"
"• `/clone` कमांड भेजें।\n"
"• स्टार्ट लिंक (जहाँ से शुरू करना है) भेजें।\n"
"• एंड लिंक भेजें (सिंगल पोस्ट के लिए `/single` लिखें)।\n"
"• टारगेट चैनल की ID/लिंक भेजें (सीधे बॉट में पाने के लिए `/skip` लिखें)।\n"
"💡 *फोरम ग्रुप के लिए `-100xxxx:टॉपिक_ID` फॉर्मेट का इस्तेमाल करें।*\n\n"
"3️⃣ **स्टेप 3 — सेटिंग्स & स्टार्ट:**\n"
"• अपना कस्टम कैप्शन या थंबनेल सेट करें और **Confirm & Start** दबा दें!\n\n"
"🔄 **ऑटो-रिज्यूम:** टास्क बीच में रुकने पर `/resume` भेजें।\n"
"🛑 **रोकने के लिए:** कभी भी `/cancel` भेजें।\n\n"
"🎥 **स्टेप-बाय-स्टेप वीडियो ट्यूटोरियल देखें:**\n"
f"👉 [यहाँ क्लिक करके पूरा वीडियो गाइड देखें]({TUTORIAL_VIDEO_URL})"
)
def get_howtouse_buttons(lang: str = "hi"):
vid_txt = "🎥 Watch Tutorial Video" if lang == "en" else "🎥 वीडियो ट्यूटोरियल देखें"
chan_txt = "📢 Channel Upload Guide" if lang == "en" else "📢 चैनल में अपलोड गाइड"
back_txt = "🔙 Back to Main Menu" if lang == "en" else "🔙 मुख्य मेन्यू पर लौटें"
return InlineKeyboardMarkup([
[InlineKeyboardButton(vid_txt, url=TUTORIAL_VIDEO_URL)],
[InlineKeyboardButton(chan_txt, callback_data="nav_channelhelp")],
[InlineKeyboardButton(back_txt, callback_data="nav_home")]
])
def get_channelhelp_text(lang: str = "hi"):
if lang == "en":
return (
"📢 **How to Upload Files to Your Channel/Group?**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"If you want files uploaded directly into your channel or group, complete these 2 steps:\n\n"
"🔹 **Step 1: Make Bot & Account Admin**\n"
"• Go to Channel Settings ➔ **Administrators** ➔ **Add Admin**.\n"
"• Add our bot and your logged-in Telegram account with **Full Admin Rights** (Post & Edit Messages).\n\n"
"🔹 **Step 2: Get the Channel ID**\n"
"• **Public Channel:** Send the username directly (e.g., `@MyChannelName`).\n"
"• **Private Channel:** Must start with `-100` (e.g., `-1001234567890`).\n"
"• **Topic Group:** Send as `-1001234567890:45` (where 45 is the Topic ID).\n\n"
"💡 **How to find Channel ID:**\n"
"Forward any message from your channel to this bot and send `/id`. The bot will display the exact `-100` ID!\n\n"
"⚠️ **Note:** Telegram will block file uploads if admin permissions are missing."
)
return (
"📢 **अपने चैनल/ग्रुप में फाइल्स कैसे अपलोड करवाएं?**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"यदि आप चाहते हैं कि बॉट फाइल्स सीधे आपके अपने चैनल या ग्रुप में अपलोड करे, तो ये 2 स्टेप्स पूरे करें:\n\n"
"🔹 **स्टेप 1: बॉट और अपने अकाउंट को एडमिन बनाएं**\n"
"• अपने चैनल/ग्रुप की सेटिंग्स ➔ **Administrators** ➔ **Add Admin** में जाएँ।\n"
"• हमारे बॉट और अपने लॉगिन किए गए टेलीग्राम नंबर दोनों को **Full Admin Rights** (Post & Edit Messages) दें।\n\n"
"🔹 **स्टेप 2: सही चैनल ID कैसे डालें?**\n"
"• **पब्लिक चैनल के लिए:** सीधे यूज़रनेम डालें (उदा: `@MyChannelName`)\n"
"• **प्राइवेट चैनल के लिए:** हमेशा `-100` से शुरू होने वाली ID डालें (उदा: `-1001234567890`)\n"
"• **टॉपिक ग्रुप के लिए:** `-1001234567890:45` फॉर्मेट में भेजें (जहाँ 45 टॉपिक ID है)\n\n"
"💡 **चैनल ID निकालने का तरीका:**\n"
"अपने चैनल का कोई भी एक मैसेज इस बॉट में फॉरवर्ड करें और `/id` कमांड भेजें। बॉट आपको चैनल की सही `-100` वाली ID बता देगा!\n\n"
"⚠️ **नोट:** बिना एडमिन परमिशन के टेलीग्राम फ़ाइल पोस्ट करने की अनुमति नहीं देता।"
)
def get_speedhelp_text(lang: str = "hi"):
if lang == "en":
return (
"⚡ **Why is the Speed Slower? (Clarification)**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"Our bot runs on a **16-Worker Parallel Engine** with a dedicated 1 Gbps cloud network pipe. There is zero speed bottleneck from our bot or server side.\n\n"
"🔍 **Actual Reasons for Slower Speed:**\n"
"1. **Telegram Server Rate-Limit:** If large files were transferred recently on your account, Telegram imposes a temporary server-side rate limit (down to 500 KB/s).\n"
"2. **Non-Premium Account Cap:** Official Telegram rules enforce a strict upload speed throttle (1.5 - 2.5 MB/s) on free accounts.\n\n"
"💡 **How to Get High Speed (8 - 10 MB/s+):**\n"
"• `/logout` and log in with a fresh Telegram account. Speed will immediately jump back to maximum.\n"
"• Using a **Telegram Premium** account removes all server throttles (10 - 15 MB/s+)."
)
return (
"⚡ **स्पीड कम क्यों मिल रही है? (Slow Speed Clarification)**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"हमारे बॉट और सर्वर में **16 पैरेलल वर्कर्स (High-Speed Engine)** और 1 Gbps का अल्ट्रा-फास्ट नेटवर्क पाइप सक्रिय है। हमारे सर्वर या बॉट की तरफ से स्पीड में कोई कमी या समस्या नहीं है।\n\n"
"🔍 **धीमी स्पीड की मुख्य वजहें:**\n"
"1. **टेलीग्राम सर्वर पाबंदी (Rate-Limit):** अगर आपके टेलीग्राम अकाउंट से हाल ही में लगातार बहुत सारा डेटा ट्रांसफर हुआ है, तो टेलीग्राम उस अकाउंट पर अस्थायी रूप से सर्वर-साइड स्पीड कैप (600 KB/s) लगा देता है।\n"
"2. **मुफ़्त (Free) टेलीग्राम लिमिट:** टेलीग्राम के आधिकारिक नियमों के तहत फ्री अकाउंट्स पर अपलोड स्पीड को उनके डेटा सेंटर द्वारा 1.5 से 2.5 MB/s पर सीमित रखा जाता है।\n\n"
"💡 **पूरी स्पीड (8 से 10 MB/s+) पाने के तरीके:**\n"
"• बॉट में `/logout` करके किसी दूसरे बिल्कुल साफ़ या नए नंबर से `/login` करें। आपको तुरंत फ़ुल स्पीड मिलने लगेगी।\n"
"• यदि आप **Telegram Premium** अकाउंट से लॉगिन करेंगे, तो स्पीड अनकैप्ड (10 से 15 MB/s+) हो जाएगी।"
)
@bot.on_message(filters.command("start") & filters.private)
async def start_command(client: Client, message: Message):
user_id = message.from_user.id
name = message.from_user.first_name
db.add_user(user_id, name)
lang = db.get_lang(user_id)
text, buttons = get_start_panel(name, is_admin(user_id), lang)
await message.reply_text(text, reply_markup=buttons, disable_web_page_preview=True)
@bot.on_message(filters.command(["lang", "language"]) & filters.private)
async def lang_cmd(client: Client, message: Message):
await message.reply_text(
"🌐 **Choose Your Preferred Language / अपनी पसंदीदा भाषा चुनें:**",
reply_markup=get_lang_prompt_markup()
)
@bot.on_message(filters.command("plans") & filters.private)
async def show_plans_cmd(client: Client, message: Message):
lang = db.get_lang(message.from_user.id)
await message.reply_text(get_plans_text(lang), reply_markup=get_plans_buttons(lang))
@bot.on_message(filters.command(["howtouse", "help"]) & filters.private)
async def howtouse_cmd(client: Client, message: Message):
lang = db.get_lang(message.from_user.id)
await message.reply_text(get_howtouse_text(lang), reply_markup=get_howtouse_buttons(lang), disable_web_page_preview=True)
@bot.on_message(filters.command(["channelhelp"]) & filters.private)
async def channelhelp_cmd(client: Client, message: Message):
lang = db.get_lang(message.from_user.id)
await message.reply_text(get_channelhelp_text(lang), reply_markup=get_back_button(lang))
@bot.on_message(filters.command(["speedhelp", "slowspeed"]) & filters.private)
async def speedhelp_cmd(client: Client, message: Message):
lang = db.get_lang(message.from_user.id)
await message.reply_text(get_speedhelp_text(lang), reply_markup=get_back_button(lang))
@bot.on_message(filters.command(["pay", "buy", "payment"]) & filters.private)
async def payment_cmd(client: Client, message: Message):
lang = db.get_lang(message.from_user.id)
try:
await message.reply_photo(
photo=PAYMENT_IMG_URL,
caption=get_payment_caption(lang),
reply_markup=get_payment_buttons(lang)
)
except Exception:
await message.reply_text(get_payment_caption(lang), reply_markup=get_payment_buttons(lang))
@bot.on_message(filters.command(["myplan", "info"]) & filters.private)
async def my_plan_cmd(client: Client, message: Message):
user_id = message.from_user.id
lang = db.get_lang(user_id)
if is_admin(user_id):
txt = "👑 You are the **Bot Owner** (Lifetime VIP Access)." if lang == "en" else "👑 आप इस बॉट के **ओनर/एडमिन** हैं (लाइफटाइम अनलिमिटेड VIP एक्सेस)।"
return await message.reply_text(txt, reply_markup=get_back_button(lang))
user = db.get_user(user_id)
if not user or not user.get("plan_expiry"):
txt = "❌ **No active VIP Plan found.**\nCheck /plans for options." if lang == "en" else "❌ **आपके पास कोई एक्टिव VIP प्लान नहीं है।**\nप्लान्स और कीमतें देखने के लिए /plans दबाएँ।"
return await message.reply_text(txt, reply_markup=get_plans_buttons(lang))
try:
exp = datetime.fromisoformat(user["plan_expiry"].replace("Z", "+00:00"))
if datetime.now(timezone.utc) > exp:
txt = "⚠️ **Your VIP Plan has expired.** Please renew." if lang == "en" else "⚠️ **आपका VIP प्लान समाप्त हो चुका है।** कृपया नया प्लान रिन्यू करें।"
return await message.reply_text(txt, reply_markup=get_plans_buttons(lang))
expiry_str = exp.strftime("%Y-%m-%d %H:%M:%S UTC")
except Exception:
expiry_str = user["plan_expiry"][:19].replace("T", " ") + " UTC"
if lang == "en":
status_text = (
f"👤 **Your Subscription Info:**\n\n"
f"🆔 **User ID:** `{user_id}`\n"
f"📊 **Status:** VIP Member ✅\n"
f"⏳ **Expiry Date:** `{expiry_str}`\n\n"
f"Support: {OWNER_HANDLE}"
)
else:
status_text = (
f"👤 **आपकी प्लान जानकारी:**\n\n"
f"🆔 **User ID:** `{user_id}`\n"
f"📊 **स्टेटस:** VIP Member ✅\n"
f"⏳ **एक्सपायरी डेट:** `{expiry_str}`\n\n"
f"सपोर्ट: {OWNER_HANDLE}"
)
await message.reply_text(status_text, reply_markup=get_back_button(lang))
@bot.on_callback_query()
async def bot_callback_router(client: Client, query: CallbackQuery):
data = query.data
user_id = query.from_user.id
name = query.from_user.first_name
lang = db.get_lang(user_id)
if data.startswith("setlang_"):
new_lang = data.split("_")[1]
db.set_lang(user_id, new_lang)
confirm_txt = "✅ **Language changed to English!**" if new_lang == "en" else "✅ **भाषा बदलकर हिंदी कर दी गई है!**"
await query.answer(confirm_txt)
text, buttons = get_start_panel(name, is_admin(user_id), new_lang)
try:
await query.message.edit_text(text, reply_markup=buttons, disable_web_page_preview=True)
except Exception:
pass
return
elif data == "nav_lang":
await query.message.edit_text(
"🌐 **Choose Your Preferred Language / अपनी पसंदीदा भाषा चुनें:**",
reply_markup=get_lang_prompt_markup()
)
return
elif data.startswith("bc_"):
if not is_admin(user_id):
return await query.answer("❌ केवल एडमिन के लिए!", show_alert=True)
should_pin = (data == "bc_pin")
msg_id_to_copy = PENDING_BROADCASTS.get(user_id)
if not msg_id_to_copy:
return await query.message.edit_text("⚠️ ब्रॉडकास्ट सेशन समाप्त हो गया। दोबारा `/broadcast` करें।")
await query.message.edit_text("⏳ **ब्रॉडकास्ट शुरू हो रहा है... कृपया इंतज़ार करें।**")
users = db.get_all_users()
total_users = len(users)
success, blocked, failed = 0, 0, 0
for u in users:
u_id = u["user_id"]
try:
sent = await client.copy_message(chat_id=u_id, from_chat_id=user_id, message_id=msg_id_to_copy)
if should_pin:
try:
await sent.pin(both_sides=True)
except Exception:
pass
success += 1
except FloodWait as f:
await asyncio.sleep(f.value)
try:
sent = await client.copy_message(chat_id=u_id, from_chat_id=user_id, message_id=msg_id_to_copy)
if should_pin:
try:
await sent.pin(both_sides=True)
except Exception:
pass
success += 1
except Exception:
failed += 1
except (UserIsBlocked, InputUserDeactivated):
blocked += 1
except Exception:
failed += 1
await asyncio.sleep(0.05)
PENDING_BROADCASTS.pop(user_id, None)
pin_status_str = "हाँ (पिन किया गया ✅)" if should_pin else "नहीं (सामान्य ⏩)"
return await query.message.edit_text(
f"✅ **ब्रॉडकास्ट पूरा हुआ!**\n━━━━━━━━━━━━━━━━━━━━\n"
f"👥 कुल यूज़र्स: `{total_users}`\n"
f"✔️ सफल: `{success}`\n"
f"🚫 बॉट ब्लॉक किया: `{blocked}`\n"
f"❌ असफल: `{failed}`\n"
f"📌 पिन स्टेटस: {pin_status_str}"
)
elif data == "nav_home":
text, buttons = get_start_panel(name, is_admin(user_id), lang)
try:
if query.message.photo:
await query.message.delete()
await client.send_message(user_id, text, reply_markup=buttons, disable_web_page_preview=True)
else:
await query.message.edit_text(text, reply_markup=buttons, disable_web_page_preview=True)
except Exception:
pass
elif data == "nav_plans":
try:
if query.message.photo:
await query.message.delete()
await client.send_message(user_id, get_plans_text(lang), reply_markup=get_plans_buttons(lang))
else:
await query.message.edit_text(get_plans_text(lang), reply_markup=get_plans_buttons(lang))
except Exception:
pass
elif data == "nav_payment":
try:
await query.message.delete()
await client.send_photo(
user_id,
photo=PAYMENT_IMG_URL,
caption=get_payment_caption(lang),
reply_markup=get_payment_buttons(lang)
)
except Exception:
await client.send_message(user_id, get_payment_caption(lang), reply_markup=get_payment_buttons(lang))
elif data == "nav_howtouse":
try:
if query.message.photo:
await query.message.delete()
await client.send_message(user_id, get_howtouse_text(lang), reply_markup=get_howtouse_buttons(lang), disable_web_page_preview=True)
else:
await query.message.edit_text(get_howtouse_text(lang), reply_markup=get_howtouse_buttons(lang), disable_web_page_preview=True)
except Exception:
pass
elif data == "nav_channelhelp":
try:
if query.message.photo:
await query.message.delete()
await client.send_message(user_id, get_channelhelp_text(lang), reply_markup=get_back_button(lang))
else:
await query.message.edit_text(get_channelhelp_text(lang), reply_markup=get_back_button(lang))
except Exception:
pass
elif data == "nav_speedhelp":
try:
if query.message.photo:
await query.message.delete()
await client.send_message(user_id, get_speedhelp_text(lang), reply_markup=get_back_button(lang))
else:
await query.message.edit_text(get_speedhelp_text(lang), reply_markup=get_back_button(lang))
except Exception:
pass
elif data == "nav_myplan":
if is_admin(user_id):
status_text = "👑 You are the **Bot Owner** (Lifetime VIP Access)." if lang == "en" else "👑 आप इस बॉट के **ओनर/एडमिन** हैं (लाइफटाइम अनलिमिटेड VIP एक्सेस)।"
else:
user = db.get_user(user_id)
if not user or not user.get("plan_expiry"):
status_text = "❌ **No active VIP Plan found.**\nCheck /plans for options." if lang == "en" else "❌ **आपके पास कोई एक्टिव VIP प्लान नहीं है।**\nप्लान्स और कीमतें देखने के लिए /plans दबाएँ।"
else:
try:
exp = datetime.fromisoformat(user["plan_expiry"].replace("Z", "+00:00"))
if datetime.now(timezone.utc) > exp:
status_text = "⚠️ **Your VIP Plan has expired.** Please renew." if lang == "en" else "⚠️ **आपका VIP प्लान समाप्त हो चुका है।** कृपया नया प्लान रिन्यू करें।"
else:
expiry_str = exp.strftime("%Y-%m-%d %H:%M:%S UTC")
if lang == "en":
status_text = (
f"👤 **Your Subscription Info:**\n\n"
f"🆔 **User ID:** `{user_id}`\n"
f"📊 **Status:** VIP Member ✅\n"
f"⏳ **Expiry Date:** `{expiry_str}`"
)
else:
status_text = (
f"👤 **आपकी प्लान जानकारी:**\n\n"
f"🆔 **User ID:** `{user_id}`\n"
f"📊 **स्टेटस:** VIP Member ✅\n"
f"⏳ **एक्सपायरी डेट:** `{expiry_str}`"
)
except Exception:
status_text = f"🆔 **User ID:** `{user_id}`\n⏳ **Expiry:** `{user.get('plan_expiry')}`"
try:
if query.message.photo:
await query.message.delete()
await client.send_message(user_id, status_text, reply_markup=get_back_button(lang))
else:
await query.message.edit_text(status_text, reply_markup=get_back_button(lang))
except Exception:
pass
else:
await query.continue_propagation()
# ----------------- ADMIN COMMANDS ----------------- #
@bot.on_message(filters.command("users") & filters.private)
async def list_users_admin(client: Client, message: Message):
if not is_admin(message.from_user.id):
return
all_users = db.get_all_users()
if not all_users:
return await message.reply_text("❌ डेटाबेस में कोई यूज़र नहीं मिला।")
vip_list = []
free_list = []
now = datetime.now(timezone.utc)
for u in all_users:
uid = u["user_id"]
uname = u.get("name") or "User"
exp_str = u.get("plan_expiry")
is_vip = False
exp_display = "Active"
if exp_str:
try:
exp = datetime.fromisoformat(exp_str.replace("Z", "+00:00"))
if exp > now:
is_vip = True
exp_display = exp.strftime("%d-%b-%Y %H:%M")
except Exception:
pass
if is_vip:
vip_list.append(f"• `{uid}` | {uname} | ⏳ {exp_display}")
else:
free_list.append(f"• `{uid}` | {uname}")
out = (
f"👥 **कुल यूज़र्स संख्या:** `{len(all_users)}`\n"
"━━━━━━━━━━━━━━━━━━━━\n\n"
f"💎 **एक्टिव VIP मेंबर्स ({len(vip_list)}):**\n"
)
if vip_list:
out += "\n".join(vip_list[:50]) + ("\n...(अधिक)" if len(vip_list) > 50 else "")
else:
out += "कोई एक्टिव VIP यूजर नहीं है।"
out += f"\n\n👤 **फ्री मेंबर्स ({len(free_list)}):**\n"
if free_list:
out += "\n".join(free_list[:50]) + ("\n...(अधिक)" if len(free_list) > 50 else "")
else:
out += "कोई फ्री यूजर नहीं है।"
await message.reply_text(out)
@bot.on_message(filters.command("setprice") & filters.private)
async def set_price_admin(client: Client, message: Message):
if not is_admin(message.from_user.id):
return
parts = message.text.split()
if len(parts) != 3:
return await message.reply_text(
"❌ गलत फॉर्मेट!\nउपयोग: `/setprice <plan> <price>`\nउपलब्ध प्लान्स: `1day`, `5days`, `15days`, `30days`\nउदाहरण: `/setprice 1day 20`"
)
plan_key = parts[1].lower()
price = parts[2]
if plan_key not in ["1day", "5days", "15days", "30days"]:
return await message.reply_text("❌ मान्य प्लान नाम: `1day`, `5days`, `15days`, `30days`")
db.set_plan_price(plan_key, price)
await message.reply_text(f"✅ **सफलता:** प्लान `{plan_key}` की कीमत ₹{price} सेट कर दी गई है।")
@bot.on_message(filters.command("adduser") & filters.private)
async def add_user_admin(client: Client, message: Message):
if not is_admin(message.from_user.id):
return
parts = message.text.split()
if len(parts) < 2:
return await message.reply_text("❌ गलत फॉर्मेट!\nउदाहरण: `/adduser 123456789 30` (ID दिन)")
try:
target_id = int(parts[1])
days = int(parts[2]) if len(parts) > 2 else 30
db.add_vip_user(target_id, days)
await message.reply_text(f"✅ यूजर `{target_id}` को **{days} दिन** के लिए VIP एक्सेस दे दिया गया है।")
try:
await client.send_message(
target_id,
f"🎉 **बधाई हो!** आपका VIP सब्सक्रिप्शन एक्टिवेट कर दिया गया है ({days} दिन के लिए)।\nअब आप `/clone` कमांड का उपयोग कर सकते हैं।"
)
except Exception:
pass
except Exception as e:
await message.reply_text(f"Error: {e}")
# 🛑 पावरफुल रिमूव यूजर कमांड (लाइव टास्क को तुरंत किल करेगा)
@bot.on_message(filters.command("removeuser") & filters.private)
async def remove_user_admin(client: Client, message: Message):
if not is_admin(message.from_user.id):
return
parts = message.text.split()
if len(parts) != 2:
return await message.reply_text("❌ गलत फॉर्मेट!\nउदाहरण: `/removeuser 123456789`")
try:
target_id = int(parts[1])
db.remove_vip_user(target_id)
# मेमोरी से तुरंत टास्क रोकने का ट्रिगर
try:
from TechVJ.start import batch_temp
batch_temp.IS_BATCH[target_id] = True
except Exception:
pass
await message.reply_text(f"🚫 यूजर `{target_id}` का VIP एक्सेस हटा दिया गया है और उसका चल रहा टास्क तुरंत किल कर दिया गया है।")
try:
await client.send_message(
target_id,
"🚫 **आपका VIP एक्सेस एडमिन द्वारा समाप्त कर दिया गया है और आपका चालू टास्क रोक दिया गया है।**"
)
except Exception:
pass
except Exception as e:
await message.reply_text(f"Error: {e}")
@bot.on_message(filters.command("broadcast") & filters.private)
async def broadcast_command(client: Client, message: Message):
if not is_admin(message.from_user.id):
return
if not message.reply_to_message:
return await message.reply_text("⚠️ **इस्तेमाल का तरीका:** जिस मैसेज को सभी को भेजना है, उस पर रिप्लाई करके `/broadcast` लिखें।")
admin_id = message.from_user.id
PENDING_BROADCASTS[admin_id] = message.reply_to_message.id
pin_ask_buttons = InlineKeyboardMarkup([
[
InlineKeyboardButton("📌 हाँ, सभी के लिए पिन करें", callback_data="bc_pin"),
InlineKeyboardButton("⏩ नहीं, सामान्य भेजें", callback_data="bc_nopin")
]
])
await message.reply_text(
"📢 **ब्रॉडकास्ट पुष्टिकरण:**\n\nक्या आप चाहते हैं कि यह मैसेज सभी यूज़र्स के इनबॉक्स में **पिन (Pin)** भी हो जाए?",
reply_markup=pin_ask_buttons
)
if __name__ == "__main__":
bot.run()