pmrony commited on
Commit
200345f
·
verified ·
1 Parent(s): 9e5271f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -3,6 +3,7 @@ import time
3
  import threading
4
  import requests
5
  import asyncio
 
6
  import urllib3
7
  from flask import Flask, jsonify, make_response, request
8
  from supabase import create_client
@@ -23,6 +24,10 @@ WEB_APP_URL = "https://rony90790.github.io/Forward-bot/app.html"
23
  BYSE_API_KEY = "133323knboif885fhgwxvf"
24
  ADMIN_IDS = [7307789267]
25
 
 
 
 
 
26
  app = Flask(__name__)
27
  supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
28
  admin_states = {}
@@ -31,13 +36,11 @@ temp_clients = {}
31
  main_loop = asyncio.get_event_loop()
32
 
33
  def run_async(coro):
34
- """Flask থেকে অ্যাসিঙ্ক্রোনাস কোড কল করার জন্য সেফ মেথড (Timeout সহ)"""
35
  future = asyncio.run_coroutine_threadsafe(coro, main_loop)
36
  try:
37
- # সর্বোচ্চ ২৫ সেকেন্ড অপেক্ষা করবে, না হলে টাইমআউট এরর দিবে
38
  return future.result(timeout=25)
39
  except asyncio.TimeoutError:
40
- return {"status": "error", "msg": "Telegram Server Timeout! Please try again."}
41
  except Exception as e:
42
  return {"status": "error", "msg": f"System Error: {str(e)}"}
43
 
@@ -78,11 +81,19 @@ def api_send_code():
78
  return add_cors_headers(make_response(jsonify({"status": "error", "msg": "Please Open WebApp inside Telegram Bot!"})))
79
 
80
  async def process_send_code():
81
- # ক্লাউড সার্ভার ব্লক এড়াতে কাস্টম ডিভাইস মডেল অ্যাড করা হলো
82
- client = Client(f"session_{phone}", api_id=API_ID, api_hash=API_HASH, in_memory=True, device_model="PC Windows", app_version="1.0")
 
 
 
 
 
 
 
 
 
83
  try:
84
  await asyncio.wait_for(client.connect(), timeout=10)
85
- # কোড রিকোয়েস্ট (সর্বোচ্চ ১৫ সেকেন্ড অপেক্ষা করবে)
86
  code_info = await asyncio.wait_for(client.send_code(phone), timeout=15)
87
 
88
  temp_clients[phone] = {'client': client, 'hash': code_info.phone_code_hash}
@@ -90,11 +101,10 @@ def api_send_code():
90
 
91
  except FloodWait as e:
92
  await client.disconnect()
93
- return {"status": "error", "msg": f"Telegram Rate Limited! Wait {e.value} seconds."}
94
  except Exception as e:
95
  try: await client.disconnect()
96
  except: pass
97
- # হুবহু এরর মেসেজটি ফন্টএন্ডে পাঠিয়ে দিবে
98
  return {"status": "error", "msg": f"TG Error: {type(e).__name__}"}
99
 
100
  result = run_async(process_send_code())
 
3
  import threading
4
  import requests
5
  import asyncio
6
+ import re
7
  import urllib3
8
  from flask import Flask, jsonify, make_response, request
9
  from supabase import create_client
 
24
  BYSE_API_KEY = "133323knboif885fhgwxvf"
25
  ADMIN_IDS = [7307789267]
26
 
27
+ # সেশন তৈরি করার জন্য অফিশিয়াল Android API ব্যবহার করা হলো যাতে ক্লাউড থেকে ব্লক না খায়
28
+ SESSION_API_ID = 6
29
+ SESSION_API_HASH = "eb06d4abfb49dc3eeb1aeb98ae0f581e"
30
+
31
  app = Flask(__name__)
32
  supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
33
  admin_states = {}
 
36
  main_loop = asyncio.get_event_loop()
37
 
38
  def run_async(coro):
 
39
  future = asyncio.run_coroutine_threadsafe(coro, main_loop)
40
  try:
 
41
  return future.result(timeout=25)
42
  except asyncio.TimeoutError:
43
+ return {"status": "error", "msg": "Telegram Server Timeout! Try again."}
44
  except Exception as e:
45
  return {"status": "error", "msg": f"System Error: {str(e)}"}
46
 
 
81
  return add_cors_headers(make_response(jsonify({"status": "error", "msg": "Please Open WebApp inside Telegram Bot!"})))
82
 
83
  async def process_send_code():
84
+ clean_phone = phone.replace("+", "")
85
+ # Official Android profile added to bypass spam filters
86
+ client = Client(
87
+ f"session_{clean_phone}",
88
+ api_id=SESSION_API_ID,
89
+ api_hash=SESSION_API_HASH,
90
+ in_memory=True,
91
+ device_model="Samsung Galaxy S23",
92
+ system_version="Android 13",
93
+ app_version="10.2.1"
94
+ )
95
  try:
96
  await asyncio.wait_for(client.connect(), timeout=10)
 
97
  code_info = await asyncio.wait_for(client.send_code(phone), timeout=15)
98
 
99
  temp_clients[phone] = {'client': client, 'hash': code_info.phone_code_hash}
 
101
 
102
  except FloodWait as e:
103
  await client.disconnect()
104
+ return {"status": "error", "msg": f"Too many requests! Wait {e.value} seconds."}
105
  except Exception as e:
106
  try: await client.disconnect()
107
  except: pass
 
108
  return {"status": "error", "msg": f"TG Error: {type(e).__name__}"}
109
 
110
  result = run_async(process_send_code())