Update app.py
Browse files
app.py
CHANGED
|
@@ -3,53 +3,67 @@ import telebot
|
|
| 3 |
import gradio as gr
|
| 4 |
import threading
|
| 5 |
|
| 6 |
-
# ===================
|
| 7 |
-
BOT_TOKEN = os.environ["
|
| 8 |
-
ADMIN_ID = int(os.environ["
|
| 9 |
-
# ============================================================
|
| 10 |
|
| 11 |
bot = telebot.TeleBot(BOT_TOKEN)
|
| 12 |
-
pending_questions = {}
|
| 13 |
|
| 14 |
@bot.message_handler(commands=['start'])
|
| 15 |
def start(message):
|
| 16 |
if message.chat.id == ADMIN_ID:
|
| 17 |
-
bot.reply_to(message, "Admin mode ON
|
| 18 |
else:
|
| 19 |
-
bot.reply_to(message, "Message bhejo, admin ko anonymously pahunch jayega!")
|
| 20 |
|
| 21 |
@bot.message_handler(func=lambda msg: True)
|
| 22 |
def handle_all_messages(message):
|
| 23 |
user_id = message.from_user.id
|
|
|
|
| 24 |
if user_id == ADMIN_ID:
|
|
|
|
| 25 |
if message.reply_to_message and message.reply_to_message.message_id in pending_questions:
|
| 26 |
-
|
| 27 |
try:
|
| 28 |
-
bot.send_message(
|
| 29 |
-
bot.reply_to(message, f"β
Reply bhej diya!")
|
| 30 |
del pending_questions[message.reply_to_message.message_id]
|
| 31 |
except:
|
| 32 |
-
bot.reply_to(message, "Error: User ne bot block kiya hoga.")
|
| 33 |
else:
|
| 34 |
-
bot.reply_to(message, "Kisi
|
|
|
|
| 35 |
else:
|
|
|
|
| 36 |
try:
|
| 37 |
-
sent = bot.send_message(
|
|
|
|
|
|
|
|
|
|
| 38 |
pending_questions[sent.message_id] = user_id
|
| 39 |
-
bot.reply_to(message, "β
Aapka message admin tak pahunch gaya!")
|
| 40 |
except:
|
| 41 |
-
bot.reply_to(message, "Kuch issue hai,
|
| 42 |
|
| 43 |
-
# Bot ko background
|
| 44 |
def run_bot():
|
| 45 |
-
print("π€ Bot shuru ho gaya...")
|
| 46 |
bot.infinity_polling()
|
| 47 |
|
| 48 |
threading.Thread(target=run_bot, daemon=True).start()
|
| 49 |
|
| 50 |
-
# HF ke liye dummy Gradio (zaroori hai
|
| 51 |
def keep_alive(x):
|
| 52 |
-
return "Bot background mein chal raha hai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
demo = gr.Interface(keep_alive, gr.Textbox(), gr.Textbox(), title="Secret Reply Bot - Running")
|
| 55 |
demo.launch(server_name="0.0.0.0", server_port=7860, prevent_thread_lock=True)
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import threading
|
| 5 |
|
| 6 |
+
# =================== SECRETS SE AA RAHA HAI ===================
|
| 7 |
+
BOT_TOKEN = os.environ["BOT_TOKEN"] # HF Secrets mein daalna hai
|
| 8 |
+
ADMIN_ID = int(os.environ["ADMIN_ID"]) # HF Secrets mein daalna hai
|
| 9 |
+
# ============================================================
|
| 10 |
|
| 11 |
bot = telebot.TeleBot(BOT_TOKEN)
|
| 12 |
+
pending_questions = {} # {message_id: user_id}
|
| 13 |
|
| 14 |
@bot.message_handler(commands=['start'])
|
| 15 |
def start(message):
|
| 16 |
if message.chat.id == ADMIN_ID:
|
| 17 |
+
bot.reply_to(message, "β
Admin mode ON\nAb questions aane par reply karke jawab dena.")
|
| 18 |
else:
|
| 19 |
+
bot.reply_to(message, "π© Message bhejo, admin ko anonymously pahunch jayega!")
|
| 20 |
|
| 21 |
@bot.message_handler(func=lambda msg: True)
|
| 22 |
def handle_all_messages(message):
|
| 23 |
user_id = message.from_user.id
|
| 24 |
+
|
| 25 |
if user_id == ADMIN_ID:
|
| 26 |
+
# Admin reply kar raha hai
|
| 27 |
if message.reply_to_message and message.reply_to_message.message_id in pending_questions:
|
| 28 |
+
target_user = pending_questions[message.reply_to_message.message_id]
|
| 29 |
try:
|
| 30 |
+
bot.send_message(target_user, message.text)
|
| 31 |
+
bot.reply_to(message, f"β
Reply bhej diya user {target_user} ko!")
|
| 32 |
del pending_questions[message.reply_to_message.message_id]
|
| 33 |
except:
|
| 34 |
+
bot.reply_to(message, "β Error: User ne bot block kiya hoga.")
|
| 35 |
else:
|
| 36 |
+
bot.reply_to(message, "π Kisi incoming question ko reply karke jawab do.")
|
| 37 |
+
|
| 38 |
else:
|
| 39 |
+
# Normal user ka message β admin ko forward
|
| 40 |
try:
|
| 41 |
+
sent = bot.send_message(
|
| 42 |
+
ADMIN_ID,
|
| 43 |
+
f"π New message from {user_id}:\n\n{message.text}"
|
| 44 |
+
)
|
| 45 |
pending_questions[sent.message_id] = user_id
|
| 46 |
+
bot.reply_to(message, "β
Aapka message admin tak pahunch gaya! Jawab bot se milega.")
|
| 47 |
except:
|
| 48 |
+
bot.reply_to(message, "β οΈ Kuch issue hai, thodi der baad try karo.")
|
| 49 |
|
| 50 |
+
# Bot ko background mein chalaao
|
| 51 |
def run_bot():
|
| 52 |
+
print("π€ Bot shuru ho gaya... 24/7 chalega!")
|
| 53 |
bot.infinity_polling()
|
| 54 |
|
| 55 |
threading.Thread(target=run_bot, daemon=True).start()
|
| 56 |
|
| 57 |
+
# HF Spaces ke liye dummy Gradio interface (zaroori hai)
|
| 58 |
def keep_alive(x):
|
| 59 |
+
return "Bot background mein chal raha hai β
"
|
| 60 |
+
|
| 61 |
+
demo = gr.Interface(
|
| 62 |
+
keep_alive,
|
| 63 |
+
gr.Textbox(),
|
| 64 |
+
gr.Textbox(),
|
| 65 |
+
title="Secret Reply Bot - Running 24/7",
|
| 66 |
+
description="Admin apne bot chat mein reply karega"
|
| 67 |
+
)
|
| 68 |
|
|
|
|
| 69 |
demo.launch(server_name="0.0.0.0", server_port=7860, prevent_thread_lock=True)
|