Agnivesh10M commited on
Commit
bb71eac
·
verified ·
1 Parent(s): eef759e

Update generate.py

Browse files
Files changed (1) hide show
  1. generate.py +93 -185
generate.py CHANGED
@@ -1,4 +1,4 @@
1
- import uuid
2
  import asyncio
3
  from pyrogram.types import Message
4
  from pyrogram import Client, filters
@@ -15,214 +15,122 @@ from db import db
15
 
16
  SESSION_STRING_SIZE = 351
17
 
18
- # बिना pyromod (bot.ask) के 100% अचूक नेटिव लॉगिन स्टेट
19
- LOGIN_STATE = {}
20
-
21
- @Client.on_message(filters.private & ~filters.forwarded & filters.command(["logout"]), group=-2)
22
  async def logout(client: Client, message: Message):
23
- user_id = int(message.from_user.id)
24
- if user_id in LOGIN_STATE:
25
- try:
26
- await LOGIN_STATE[user_id]["client"].disconnect()
27
- except Exception:
28
- pass
29
- LOGIN_STATE.pop(user_id, None)
30
-
31
- user_data = db.get_session(user_id)
32
- if not user_data:
33
  return await message.reply("❌ आप अभी लॉगिन नहीं हैं।")
34
- db.remove_session(user_id)
35
  await message.reply("✅ **सफलतापूर्वक लॉगआउट कर दिया गया है।**")
36
 
37
- @Client.on_message(filters.private & ~filters.forwarded & filters.command(["login"]), group=-2)
38
- async def start_login(bot: Client, message: Message):
39
  user_id = int(message.from_user.id)
40
-
41
- # पुराना कोई अधूरा लॉगिन स्टेट हो तो साफ़ करें
42
- if user_id in LOGIN_STATE:
43
- try:
44
- await LOGIN_STATE[user_id]["client"].disconnect()
45
- except Exception:
46
- pass
47
- LOGIN_STATE.pop(user_id, None)
48
-
49
  user_data = db.get_session(user_id)
50
- if user_data and len(str(user_data)) > 10:
51
- return await message.reply("⚠️ **आप पहले से लॉगिन हैं। नया अकाउंट जोड़ने से पहले /logout करें।**")
52
-
53
- LOGIN_STATE[user_id] = {"step": "WAIT_PHONE"}
54
- await message.reply(
55
- "📱 **कंट्री कोड के साथ अपना फ़ोन नंबर भेजें:**\n"
56
- "(उदाहरण: `+919876543210`)\n\n"
57
- "रद्द करने के लिए /cancel लिखें।"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  )
59
 
60
- @Client.on_message(filters.private & filters.text & ~filters.forwarded, group=-2)
61
- async def handle_login_steps(bot: Client, message: Message):
62
- user_id = int(message.from_user.id)
63
- if user_id not in LOGIN_STATE:
64
- return
65
-
66
- text = message.text.strip()
67
-
68
- # यदि यूज़र ने कोई दूसरा कमांड या /cancel भेजा
69
- if text == "/cancel":
70
- try:
71
- if "client" in LOGIN_STATE[user_id]:
72
- await LOGIN_STATE[user_id]["client"].disconnect()
73
- except Exception:
74
- pass
75
- LOGIN_STATE.pop(user_id, None)
76
- await message.reply("❌ लॉगिन प्रोसेस रद्द कर दिया गया।")
77
- message.stop_propagation()
78
- return
79
-
80
- if text.startswith("/") and text != "/login":
81
- # अन्य कमांड्स के लिए लॉगिन स्टेट साफ़ करें ताकि कमांड सामान्य रूप से चले
82
- try:
83
- if "client" in LOGIN_STATE[user_id]:
84
- await LOGIN_STATE[user_id]["client"].disconnect()
85
- except Exception:
86
- pass
87
- LOGIN_STATE.pop(user_id, None)
88
- return
89
-
90
- if text == "/login":
91
- return
92
-
93
- state = LOGIN_STATE[user_id]
94
- step = state.get("step")
95
-
96
- # रोकें ताकि कोई दूसरा हैंडलर इस मैसेज को न पकड़े
97
- message.stop_propagation()
98
-
99
- # ==================== STEP 1: फ़ोन नंबर प्राप्त करना ====================
100
- if step == "WAIT_PHONE":
101
- phone_number = text
102
- if not phone_number.startswith("+"):
103
- phone_number = "+" + phone_number
104
-
105
- api_id = int(API_ID)
106
- api_hash = str(API_HASH)
107
 
108
- unique_name = f"auth_{user_id}_{uuid.uuid4().hex[:8]}"
109
- client = Client(
110
- name=unique_name,
111
- in_memory=True,
112
- api_id=api_id,
113
- api_hash=api_hash,
114
- device_model="Samsung Galaxy S24 Ultra",
115
- system_version="Android 14 (One UI 6.1)",
116
- app_version="Telegram Android 10.9.1",
117
- lang_code="en"
118
  )
 
 
 
 
 
 
119
 
120
- status_msg = await message.reply("📩 OTP भेजा जा रहा है...")
121
-
122
- try:
123
- await asyncio.wait_for(client.connect(), timeout=25.0)
124
- code = await asyncio.wait_for(client.send_code(phone_number), timeout=30.0)
125
- except FloodWait as f:
126
- await client.disconnect()
127
- LOGIN_STATE.pop(user_id, None)
128
- return await status_msg.edit_text(f"⏳ **FloodWait:** कृपया **{f.value} सेकंड** इंतज़ार करें।")
129
- except PhoneNumberInvalid:
130
- await client.disconnect()
131
- LOGIN_STATE.pop(user_id, None)
132
- return await status_msg.edit_text("❌ अमान्य फ़ोन नंबर। सही नंबर डालकर दोबारा /login करें।")
133
- except Exception as e:
134
- await client.disconnect()
135
- LOGIN_STATE.pop(user_id, None)
136
- return await status_msg.edit_text(f"❌ OTP भेजने में समस्या: `{e}`")
137
-
138
- # अगला स्टेप सेट करें और सीधा OTP माँगें
139
- LOGIN_STATE[user_id] = {
140
- "step": "WAIT_OTP",
141
- "client": client,
142
- "phone_number": phone_number,
143
- "phone_code_hash": code.phone_code_hash,
144
- "api_id": api_id,
145
- "api_hash": api_hash
146
- }
147
- await status_msg.edit_text(
148
- "📲 **टेलीग्राम पर आया हुआ OTP यहाँ भेजें** (अंकों के बीच स्पेस देकर, जैसे: `1 2 3 4 5`):\n\n"
149
- "रद्द करने के लिए /cancel लिखें।"
150
  )
 
 
151
  return
152
 
153
- # ==================== STEP 2: OTP सत्यापन ====================
154
- elif step == "WAIT_OTP":
155
- client = state["client"]
156
- phone_number = state["phone_number"]
157
- phone_code_hash = state["phone_code_hash"]
158
- phone_code = text.replace(" ", "").replace("-", "")
159
 
160
- try:
161
- await client.sign_in(phone_number, phone_code_hash, phone_code)
162
- except FloodWait as f:
163
- await client.disconnect()
164
- LOGIN_STATE.pop(user_id, None)
165
- return await message.reply(f"⏳ कृपया {f.value} सेकंड इंतज़ार करें।")
166
- except PhoneCodeInvalid:
167
- return await message.reply("❌ OTP गलत है। कृपया सही OTP दोबारा भेजें (या /cancel करें):")
168
- except PhoneCodeExpired:
169
- await client.disconnect()
170
- LOGIN_STATE.pop(user_id, None)
171
- return await message.reply("❌ OTP एक्सपायर हो चुका है। दोबारा /login करें।")
172
- except SessionPasswordNeeded:
173
- LOGIN_STATE[user_id]["step"] = "WAIT_2FA"
174
- return await message.reply(
175
- "🔐 **आपके अकाउंट पर Two-Step Verification लगा है। अपना पासवर्ड भेजें:**\n\n"
176
- "रद्द करने के लिए /cancel लिखें।"
177
- )
178
- except Exception as e:
 
179
  await client.disconnect()
180
- LOGIN_STATE.pop(user_id, None)
181
- return await message.reply(f"❌ लॉगिन एरर: `{e}`")
182
-
183
- # यदि 2FA नहीं है तो सीधा सेशन सेव करें
184
- await finalize_session(bot, message, user_id, client, state["api_id"], state["api_hash"])
185
- return
186
-
187
- # ==================== STEP 3: 2FA पासवर्ड सत्यापन ====================
188
- elif step == "WAIT_2FA":
189
- client = state["client"]
190
  try:
191
- await client.check_password(password=text)
192
  except PasswordHashInvalid:
193
- return await message.reply("❌ गलत पासवर्ड दर्ज किया गया है। कृपया सही पासवर्ड दोबारा भेजें:")
194
- except FloodWait as f:
195
  await client.disconnect()
196
- LOGIN_STATE.pop(user_id, None)
197
- return await message.reply(f"⏳ कृपया {f.value} सेकंड इंतज़ार करें।")
198
- except Exception as e:
199
  await client.disconnect()
200
- LOGIN_STATE.pop(user_id, None)
201
- return await message.reply(f"❌ पासवर्ड एरर: `{e}`")
202
 
203
- await finalize_session(bot, message, user_id, client, state["api_id"], state["api_hash"])
204
- return
205
-
206
-
207
- async def finalize_session(bot: Client, message: Message, user_id: int, client: Client, api_id: int, api_hash: str):
208
- try:
209
- string_session = await client.export_session_string()
210
- await client.disconnect()
211
- except Exception as e:
212
- LOGIN_STATE.pop(user_id, None)
213
- return await message.reply(f"❌ सेशन एक्सपोर्ट एरर: `{e}`")
214
 
215
- LOGIN_STATE.pop(user_id, None)
216
-
217
- if not string_session or len(string_session) < SESSION_STRING_SIZE:
218
- return await message.reply("❌ सेशन स्ट्रिंग अमान्य है। दोबारा /login करें।")
219
 
220
  db.set_session(user_id, session=string_session)
221
  db.set_api_id(user_id, api_id=str(api_id))
222
  db.set_api_hash(user_id, api_hash=str(api_hash))
223
 
224
- await bot.send_message(
225
- user_id,
226
- "🎉 **अकाउंट सफलतापूर्वक लॉगिन ��ो गया है!**\n"
227
- "अब आप `/clone` कमांड से कंटेंट ट्रांसफर कर सकते हैं।"
228
- )
 
1
+ import traceback
2
  import asyncio
3
  from pyrogram.types import Message
4
  from pyrogram import Client, filters
 
15
 
16
  SESSION_STRING_SIZE = 351
17
 
18
+ @Client.on_message(filters.private & ~filters.forwarded & filters.command(["logout"]))
 
 
 
19
  async def logout(client: Client, message: Message):
20
+ user_data = db.get_session(message.from_user.id)
21
+ if user_data is None:
 
 
 
 
 
 
 
 
22
  return await message.reply("❌ आप अभी लॉगिन नहीं हैं।")
23
+ db.remove_session(message.from_user.id)
24
  await message.reply("✅ **सफलतापूर्वक लॉगआउट कर दिया गया है।**")
25
 
26
+ @Client.on_message(filters.private & ~filters.forwarded & filters.command(["login"]))
27
+ async def main(bot: Client, message: Message):
28
  user_id = int(message.from_user.id)
 
 
 
 
 
 
 
 
 
29
  user_data = db.get_session(user_id)
30
+ if user_data is not None:
31
+ await message.reply("⚠️ **आप पहले से लॉगिन हैं। नया अकाउंट जोड़ने से पहले /logout करें।**")
32
+ return
33
+
34
+ phone_number_msg = await bot.ask(
35
+ chat_id=user_id,
36
+ text="📱 **कंट्री कोड के साथ अपना फ़ोन नंबर भेजें:**\n(उदाहरण: `+919876543210`)\n\nरद्द करने के लिए /cancel लिखें।",
37
+ filters=filters.text,
38
+ timeout=300
39
+ )
40
+ if phone_number_msg.text == '/cancel':
41
+ return await phone_number_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
42
+
43
+ phone_number = phone_number_msg.text.strip()
44
+ api_id = API_ID
45
+ api_hash = API_HASH
46
+
47
+ # इन-मेमोरी और यूनिक यूजर सेशन (database locked एरर स्थायी रूप से फिक्स)
48
+ client = Client(
49
+ name=f"auth_session_{user_id}",
50
+ in_memory=True,
51
+ api_id=api_id,
52
+ api_hash=api_hash,
53
+ device_model="Samsung Galaxy S26 Ultra",
54
+ system_version="Android 16 (One UI 8.5)",
55
+ app_version="Telegram Android 11.2.0",
56
+ lang_code="en"
57
  )
58
 
59
+ try:
60
+ await client.connect()
61
+ except Exception as e:
62
+ return await message.reply(f"❌ कनेक्शन एरर: `{e}`")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
+ await phone_number_msg.reply("📩 OTP भेजा जा रहा है...")
65
+
66
+ try:
67
+ code = await client.send_code(phone_number)
68
+ except FloodWait as f:
69
+ await client.disconnect()
70
+ return await phone_number_msg.reply(
71
+ f"⏳ **FloodWait:** कृपया **{f.value} सेकंड** इंतज़ार करें।"
 
 
72
  )
73
+ except PhoneNumberInvalid:
74
+ await client.disconnect()
75
+ return await phone_number_msg.reply("❌ अमान्य फ़ोन नंबर। कृपया सही नंबर डालकर दोबारा /login करें।")
76
+ except Exception as e:
77
+ await client.disconnect()
78
+ return await phone_number_msg.reply(f"❌ OTP भेजने में समस्या: `{e}`")
79
 
80
+ try:
81
+ phone_code_msg = await bot.ask(
82
+ user_id,
83
+ "📲 टेलीग्राम पर आया हुआ OTP यहाँ भेजें (अंकों के बीच स्पेस देकर, जैसे: `1 2 3 4 5`):\n\nरद्द करने के लिए /cancel लिखें।",
84
+ filters=filters.text,
85
+ timeout=600
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  )
87
+ except Exception:
88
+ await client.disconnect()
89
  return
90
 
91
+ if phone_code_msg.text == '/cancel':
92
+ await client.disconnect()
93
+ return await phone_code_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
 
 
 
94
 
95
+ try:
96
+ phone_code = phone_code_msg.text.replace(" ", "").replace("-", "")
97
+ await client.sign_in(phone_number, code.phone_code_hash, phone_code)
98
+ except FloodWait as f:
99
+ await client.disconnect()
100
+ return await phone_code_msg.reply(f"⏳ कृपया {f.value} सेकंड इंतज़ार करें।")
101
+ except PhoneCodeInvalid:
102
+ await client.disconnect()
103
+ return await phone_code_msg.reply("❌ OTP गलत है।")
104
+ except PhoneCodeExpired:
105
+ await client.disconnect()
106
+ return await phone_code_msg.reply("❌ OTP एक्सपायर हो चुका है।")
107
+ except SessionPasswordNeeded:
108
+ two_step_msg = await bot.ask(
109
+ user_id,
110
+ "🔐 Two-Step Verification पासवर्ड भेजें:\n\nरद्द करने के लिए /cancel लिखें।",
111
+ filters=filters.text,
112
+ timeout=300
113
+ )
114
+ if two_step_msg.text == '/cancel':
115
  await client.disconnect()
116
+ return await two_step_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
 
 
 
 
 
 
 
 
 
117
  try:
118
+ await client.check_password(password=two_step_msg.text)
119
  except PasswordHashInvalid:
 
 
120
  await client.disconnect()
121
+ return await two_step_msg.reply("❌ गलत पासवर्ड दर्ज किया गया है।")
122
+ except FloodWait as f:
 
123
  await client.disconnect()
124
+ return await two_step_msg.reply(f"⏳ कृपया {f.value} सेकंड इंतज़ार करें।")
 
125
 
126
+ string_session = await client.export_session_string()
127
+ await client.disconnect()
 
 
 
 
 
 
 
 
 
128
 
129
+ if len(string_session) < SESSION_STRING_SIZE:
130
+ return await message.reply("❌ सेशन स्ट्रिंग अमान्य है।")
 
 
131
 
132
  db.set_session(user_id, session=string_session)
133
  db.set_api_id(user_id, api_id=str(api_id))
134
  db.set_api_hash(user_id, api_hash=str(api_hash))
135
 
136
+ await bot.send_message(user_id, "🎉 **अकाउंट सफलतापूर्वक लॉगिन हो गया है!**\nअब आप `/clone` या `/topicclone` से ट्रांसफर कर सकते हैं।")