Spaces:
Running on Zero
Running on Zero
File size: 6,353 Bytes
bb71eac 1ef6a70 bb71eac e233f0c bb71eac 1ef6a70 bb71eac 1ef6a70 bb71eac 1ef6a70 bb71eac 1ef6a70 bb71eac eef759e bb71eac 1ef6a70 bb71eac 1ef6a70 bb71eac 1ef6a70 bb71eac eef759e 1ef6a70 bb71eac 1ef6a70 bb71eac eef759e bb71eac 1ef6a70 bb71eac 1ef6a70 bb71eac eef759e bb71eac 1ef6a70 bb71eac eef759e bb71eac 1ef6a70 bb71eac | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | import traceback
import asyncio
from pyrogram.types import Message
from pyrogram import Client, filters
from pyrogram.errors import (
PhoneNumberInvalid,
PhoneCodeInvalid,
PhoneCodeExpired,
SessionPasswordNeeded,
PasswordHashInvalid,
FloodWait
)
from config import API_ID, API_HASH
from db import db
SESSION_STRING_SIZE = 351
@Client.on_message(filters.private & ~filters.forwarded & filters.command(["logout"]))
async def logout(client: Client, message: Message):
user_data = db.get_session(message.from_user.id)
if user_data is None:
return await message.reply("❌ आप अभी लॉगिन नहीं हैं।")
db.remove_session(message.from_user.id)
await message.reply("✅ **सफलतापूर्वक लॉगआउट कर दिया गया है।**")
@Client.on_message(filters.private & ~filters.forwarded & filters.command(["login"]))
async def main(bot: Client, message: Message):
user_id = int(message.from_user.id)
user_data = db.get_session(user_id)
if user_data is not None:
await message.reply("⚠️ **आप पहले से लॉगिन हैं। नया अकाउंट जोड़ने से पहले /logout करें।**")
return
phone_number_msg = await bot.ask(
chat_id=user_id,
text="📱 **कंट्री कोड के साथ अपना फ़ोन नंबर भेजें:**\n(उदाहरण: `+919876543210`)\n\nरद्द करने के लिए /cancel लिखें।",
filters=filters.text,
timeout=300
)
if phone_number_msg.text == '/cancel':
return await phone_number_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
phone_number = phone_number_msg.text.strip()
api_id = API_ID
api_hash = API_HASH
# इन-मेमोरी और यूनिक यूजर सेशन (database locked एरर स्थायी रूप से फिक्स)
client = Client(
name=f"auth_session_{user_id}",
in_memory=True,
api_id=api_id,
api_hash=api_hash,
device_model="Samsung Galaxy S26 Ultra",
system_version="Android 16 (One UI 8.5)",
app_version="Telegram Android 11.2.0",
lang_code="en"
)
try:
await client.connect()
except Exception as e:
return await message.reply(f"❌ कनेक्शन एरर: `{e}`")
await phone_number_msg.reply("📩 OTP भेजा जा रहा है...")
try:
code = await client.send_code(phone_number)
except FloodWait as f:
await client.disconnect()
return await phone_number_msg.reply(
f"⏳ **FloodWait:** कृपया **{f.value} सेकंड** इंतज़ार करें।"
)
except PhoneNumberInvalid:
await client.disconnect()
return await phone_number_msg.reply("❌ अमान्य फ़ोन नंबर। कृपया सही नंबर डालकर दोबारा /login करें।")
except Exception as e:
await client.disconnect()
return await phone_number_msg.reply(f"❌ OTP भेजने में समस्या: `{e}`")
try:
phone_code_msg = await bot.ask(
user_id,
"📲 टेलीग्राम पर आया हुआ OTP यहाँ भेजें (अंकों के बीच स्पेस देकर, जैसे: `1 2 3 4 5`):\n\nरद्द करने के लिए /cancel लिखें।",
filters=filters.text,
timeout=600
)
except Exception:
await client.disconnect()
return
if phone_code_msg.text == '/cancel':
await client.disconnect()
return await phone_code_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
try:
phone_code = phone_code_msg.text.replace(" ", "").replace("-", "")
await client.sign_in(phone_number, code.phone_code_hash, phone_code)
except FloodWait as f:
await client.disconnect()
return await phone_code_msg.reply(f"⏳ कृपया {f.value} सेकंड इंतज़ार करें।")
except PhoneCodeInvalid:
await client.disconnect()
return await phone_code_msg.reply("❌ OTP गलत है।")
except PhoneCodeExpired:
await client.disconnect()
return await phone_code_msg.reply("❌ OTP एक्सपायर हो चुका है।")
except SessionPasswordNeeded:
two_step_msg = await bot.ask(
user_id,
"🔐 Two-Step Verification पासवर्ड भेजें:\n\nरद्द करने के लिए /cancel लिखें।",
filters=filters.text,
timeout=300
)
if two_step_msg.text == '/cancel':
await client.disconnect()
return await two_step_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
try:
await client.check_password(password=two_step_msg.text)
except PasswordHashInvalid:
await client.disconnect()
return await two_step_msg.reply("❌ गलत पासवर्ड दर्ज किया गया है।")
except FloodWait as f:
await client.disconnect()
return await two_step_msg.reply(f"⏳ कृपया {f.value} सेकंड इंतज़ार करें।")
string_session = await client.export_session_string()
await client.disconnect()
if len(string_session) < SESSION_STRING_SIZE:
return await message.reply("❌ सेशन स्ट्रिंग अमान्य है।")
db.set_session(user_id, session=string_session)
db.set_api_id(user_id, api_id=str(api_id))
db.set_api_hash(user_id, api_hash=str(api_hash))
await bot.send_message(user_id, "🎉 **अकाउंट सफलतापूर्वक लॉगिन हो गया है!**\nअब आप `/clone` या `/topicclone` से ट्रांसफर कर सकते हैं।")
|