Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,41 @@
|
|
| 1 |
import os
|
| 2 |
import telebot
|
| 3 |
-
import gradio as gr
|
| 4 |
-
import threading
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
ADMIN_ID = int(os.environ["ADMIN_ID"]) # HF Secrets mein daalna hai
|
| 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\nAb questions
|
| 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
|
| 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 |
-
|
| 29 |
try:
|
| 30 |
-
bot.send_message(
|
| 31 |
-
bot.reply_to(message, f"β
Reply bhej diya
|
| 32 |
del pending_questions[message.reply_to_message.message_id]
|
| 33 |
except:
|
| 34 |
-
bot.reply_to(message, "β
|
| 35 |
else:
|
| 36 |
-
bot.reply_to(message, "π Kisi
|
| 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, "β
|
| 47 |
except:
|
| 48 |
-
bot.reply_to(message, "β οΈ
|
| 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 |
-
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import telebot
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
BOT_TOKEN = os.getenv("BOT_TOKEN")
|
| 5 |
+
ADMIN_ID = int(os.getenv("ADMIN_ID"))
|
|
|
|
|
|
|
| 6 |
|
| 7 |
bot = telebot.TeleBot(BOT_TOKEN)
|
| 8 |
+
pending_questions = {} # {msg_id: user_id}
|
| 9 |
|
| 10 |
@bot.message_handler(commands=['start'])
|
| 11 |
def start(message):
|
| 12 |
if message.chat.id == ADMIN_ID:
|
| 13 |
+
bot.reply_to(message, "β
Admin mode ON\nAb questions ka reply karo!")
|
| 14 |
else:
|
| 15 |
bot.reply_to(message, "π© Message bhejo, admin ko anonymously pahunch jayega!")
|
| 16 |
|
| 17 |
@bot.message_handler(func=lambda msg: True)
|
| 18 |
+
def handle_all(message):
|
| 19 |
user_id = message.from_user.id
|
| 20 |
|
| 21 |
if user_id == ADMIN_ID:
|
|
|
|
| 22 |
if message.reply_to_message and message.reply_to_message.message_id in pending_questions:
|
| 23 |
+
target = pending_questions[message.reply_to_message.message_id]
|
| 24 |
try:
|
| 25 |
+
bot.send_message(target, message.text)
|
| 26 |
+
bot.reply_to(message, f"β
Reply bhej diya!")
|
| 27 |
del pending_questions[message.reply_to_message.message_id]
|
| 28 |
except:
|
| 29 |
+
bot.reply_to(message, "β User ne bot block kar diya.")
|
| 30 |
else:
|
| 31 |
+
bot.reply_to(message, "π Kisi question ko reply karke jawab do.")
|
|
|
|
| 32 |
else:
|
|
|
|
| 33 |
try:
|
| 34 |
+
sent = bot.send_message(ADMIN_ID, f"π New from {user_id}:\n\n{message.text}")
|
|
|
|
|
|
|
|
|
|
| 35 |
pending_questions[sent.message_id] = user_id
|
| 36 |
+
bot.reply_to(message, "β
Message admin tak pahunch gaya!")
|
| 37 |
except:
|
| 38 |
+
bot.reply_to(message, "β οΈ Thodi der baad try karo.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
print("π€ Bot shuru ho gaya...")
|
| 41 |
+
bot.infinity_polling()
|