Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,13 @@
|
|
| 1 |
import asyncio
|
| 2 |
-
from flask import Flask
|
| 3 |
from threading import Thread
|
| 4 |
import random
|
| 5 |
import time
|
| 6 |
import requests
|
| 7 |
import logging
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
try:
|
| 11 |
-
import uvloop
|
| 12 |
-
except:
|
| 13 |
-
print("uvloop is not installed")
|
| 14 |
-
|
| 15 |
-
from pyrogram import Client
|
| 16 |
from config import API_ID, API_HASH, BOT_TOKEN, REPL_URL
|
| 17 |
|
| 18 |
app = Flask("")
|
|
@@ -21,50 +16,58 @@ app = Flask("")
|
|
| 21 |
def home():
|
| 22 |
return "You have found the home of a Python program!"
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def run():
|
| 25 |
app.run()
|
| 26 |
|
| 27 |
-
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
# log.disabled = True
|
| 38 |
-
# app.logger.disabled = True
|
| 39 |
-
# t = Thread(target=run)
|
| 40 |
-
# r = Thread(
|
| 41 |
-
# target=ping,
|
| 42 |
-
# args=(
|
| 43 |
-
# target,
|
| 44 |
-
# debug,
|
| 45 |
-
# ),
|
| 46 |
-
# )
|
| 47 |
-
# t.start()
|
| 48 |
-
# r.start()
|
| 49 |
|
| 50 |
if __name__ == '__main__':
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
except:
|
| 60 |
-
print("Could not apply uvloop on project")
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
api_id=API_ID,
|
| 68 |
-
api_hash=API_HASH,
|
| 69 |
-
bot_token=BOT_TOKEN,
|
| 70 |
-
plugins=plugins).run()
|
|
|
|
| 1 |
import asyncio
|
| 2 |
+
from flask import Flask, request
|
| 3 |
from threading import Thread
|
| 4 |
import random
|
| 5 |
import time
|
| 6 |
import requests
|
| 7 |
import logging
|
| 8 |
+
import json
|
| 9 |
|
| 10 |
+
from pyrogram import Client, Filters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
from config import API_ID, API_HASH, BOT_TOKEN, REPL_URL
|
| 12 |
|
| 13 |
app = Flask("")
|
|
|
|
| 16 |
def home():
|
| 17 |
return "You have found the home of a Python program!"
|
| 18 |
|
| 19 |
+
# Handle updates sent by Telegram
|
| 20 |
+
@app.route(f"/{BOT_TOKEN}", methods=["POST"])
|
| 21 |
+
def handle_updates():
|
| 22 |
+
update = json.loads(request.data)
|
| 23 |
+
# Do something with the update, e.g., process incoming messages
|
| 24 |
+
# For example, you can forward incoming messages to another chat:
|
| 25 |
+
# app.send_message(chat_id="@your_chat", text=update["message"]["text"])
|
| 26 |
+
return "OK"
|
| 27 |
+
|
| 28 |
def run():
|
| 29 |
app.run()
|
| 30 |
|
| 31 |
+
def set_webhook():
|
| 32 |
+
# Set the webhook URL to your bot on Telegram's server
|
| 33 |
+
url = f"https://api.telegram.org/bot{BOT_TOKEN}/setWebhook"
|
| 34 |
+
data = {"url": f"https://manishx-genatoz.hf.space/{BOT_TOKEN}"}
|
| 35 |
+
r = requests.post(url, json=data)
|
| 36 |
+
if r.status_code != 200:
|
| 37 |
+
print(f"Failed to set webhook: {r.text}")
|
| 38 |
+
return False
|
| 39 |
+
print("Webhook set successfully")
|
| 40 |
+
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
if __name__ == '__main__':
|
| 43 |
|
| 44 |
+
# Set the webhook URL
|
| 45 |
+
if not set_webhook():
|
| 46 |
+
exit(1)
|
| 47 |
+
|
| 48 |
+
# Setting up uvloop
|
| 49 |
+
try:
|
| 50 |
+
import uvloop
|
| 51 |
+
uvloop.install()
|
| 52 |
+
except:
|
| 53 |
+
print("Could not apply uvloop on project")
|
| 54 |
+
|
| 55 |
+
# Defining path to plugins
|
| 56 |
+
plugins = dict(root="plugins")
|
| 57 |
+
|
| 58 |
+
# Defining the pyrogram client's instance
|
| 59 |
+
client = Client("UploadBot",
|
| 60 |
+
api_id=API_ID,
|
| 61 |
+
api_hash=API_HASH,
|
| 62 |
+
bot_token=BOT_TOKEN,
|
| 63 |
+
plugins=plugins)
|
| 64 |
|
| 65 |
+
# Start the Flask app in a separate thread
|
| 66 |
+
t = Thread(target=run)
|
| 67 |
+
t.start()
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
# Start the Pyrogram client
|
| 70 |
+
client.start()
|
| 71 |
|
| 72 |
+
# Keep the client running
|
| 73 |
+
client.idle()
|
|
|
|
|
|
|
|
|
|
|
|