Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,15 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import requests
|
|
|
|
| 3 |
from pyrogram import Client, filters
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
BRIDGE_URL = "https://bridges.torproject.org/bridges?transport=obfs4"
|
| 6 |
|
|
|
|
| 7 |
def fetch_bridges():
|
| 8 |
try:
|
| 9 |
r = requests.get(BRIDGE_URL, timeout=15)
|
|
@@ -14,27 +20,45 @@ def fetch_bridges():
|
|
| 14 |
return f"Error: {str(e)}"
|
| 15 |
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
API_ID = int(os.getenv("API_ID"))
|
| 18 |
API_HASH = os.getenv("API_HASH")
|
| 19 |
BOT_TOKEN = os.getenv("BOT_TOKEN")
|
| 20 |
|
| 21 |
-
|
| 22 |
-
app = Client(
|
| 23 |
"tor_bridge_bot",
|
| 24 |
api_id=API_ID,
|
| 25 |
api_hash=API_HASH,
|
| 26 |
bot_token=BOT_TOKEN
|
| 27 |
)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def start(client, message):
|
| 32 |
message.reply_text(
|
| 33 |
-
"👋 Tor Bridge Bot\n\nUse /bridge to get bridges."
|
| 34 |
)
|
| 35 |
|
| 36 |
|
| 37 |
-
@
|
| 38 |
def bridge(client, message):
|
| 39 |
message.reply_text("🔄 Fetching bridges...")
|
| 40 |
|
|
@@ -46,6 +70,25 @@ def bridge(client, message):
|
|
| 46 |
message.reply_text(f"🌉 Your Tor Bridges:\n\n{bridges}")
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
if __name__ == "__main__":
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import threading
|
| 3 |
import requests
|
| 4 |
+
from flask import Flask
|
| 5 |
from pyrogram import Client, filters
|
| 6 |
|
| 7 |
+
# -------------------
|
| 8 |
+
# Bridge endpoint
|
| 9 |
+
# -------------------
|
| 10 |
BRIDGE_URL = "https://bridges.torproject.org/bridges?transport=obfs4"
|
| 11 |
|
| 12 |
+
|
| 13 |
def fetch_bridges():
|
| 14 |
try:
|
| 15 |
r = requests.get(BRIDGE_URL, timeout=15)
|
|
|
|
| 20 |
return f"Error: {str(e)}"
|
| 21 |
|
| 22 |
|
| 23 |
+
# -------------------
|
| 24 |
+
# Telegram bot config
|
| 25 |
+
# -------------------
|
| 26 |
API_ID = int(os.getenv("API_ID"))
|
| 27 |
API_HASH = os.getenv("API_HASH")
|
| 28 |
BOT_TOKEN = os.getenv("BOT_TOKEN")
|
| 29 |
|
| 30 |
+
app_bot = Client(
|
|
|
|
| 31 |
"tor_bridge_bot",
|
| 32 |
api_id=API_ID,
|
| 33 |
api_hash=API_HASH,
|
| 34 |
bot_token=BOT_TOKEN
|
| 35 |
)
|
| 36 |
|
| 37 |
+
# -------------------
|
| 38 |
+
# Flask heartbeat server
|
| 39 |
+
# -------------------
|
| 40 |
+
web = Flask(__name__)
|
| 41 |
+
|
| 42 |
+
@web.route("/")
|
| 43 |
+
def home():
|
| 44 |
+
return "Tor Bridge Bot is running ✅"
|
| 45 |
|
| 46 |
+
@web.route("/health")
|
| 47 |
+
def health():
|
| 48 |
+
return {"status": "ok"}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# -------------------
|
| 52 |
+
# Telegram handlers
|
| 53 |
+
# -------------------
|
| 54 |
+
@app_bot.on_message(filters.command("start"))
|
| 55 |
def start(client, message):
|
| 56 |
message.reply_text(
|
| 57 |
+
"👋 Tor Bridge Bot is alive!\n\nUse /bridge to get bridges."
|
| 58 |
)
|
| 59 |
|
| 60 |
|
| 61 |
+
@app_bot.on_message(filters.command("bridge"))
|
| 62 |
def bridge(client, message):
|
| 63 |
message.reply_text("🔄 Fetching bridges...")
|
| 64 |
|
|
|
|
| 70 |
message.reply_text(f"🌉 Your Tor Bridges:\n\n{bridges}")
|
| 71 |
|
| 72 |
|
| 73 |
+
# -------------------
|
| 74 |
+
# Run both services
|
| 75 |
+
# -------------------
|
| 76 |
+
def run_bot():
|
| 77 |
+
print("🤖 Bot started")
|
| 78 |
+
app_bot.run()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def run_web():
|
| 82 |
+
print("🌐 Web server started on 7860")
|
| 83 |
+
web.run(host="0.0.0.0", port=7860)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
if __name__ == "__main__":
|
| 87 |
+
t1 = threading.Thread(target=run_bot)
|
| 88 |
+
t2 = threading.Thread(target=run_web)
|
| 89 |
+
|
| 90 |
+
t1.start()
|
| 91 |
+
t2.start()
|
| 92 |
+
|
| 93 |
+
t1.join()
|
| 94 |
+
t2.join()
|