Offex commited on
Commit
9f99f5f
·
verified ·
1 Parent(s): 8cef27b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import telebot
3
+ import gradio as gr
4
+ import threading
5
+
6
+ # =================== YAHAN APNI DETAILS DAALO ===================
7
+ BOT_TOKEN = os.environ["8019494761:AAF18VXTr7hg3-lK3qTnRtPOicybhe5pssk"] # HF Secrets mein daalna hai
8
+ ADMIN_ID = int(os.environ["8109723300"]) # 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 aane par reply karo.")
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
+ target = pending_questions[message.reply_to_message.message_id]
27
+ try:
28
+ bot.send_message(target, message.text)
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 message ko reply karke jawab do.")
35
+ else:
36
+ try:
37
+ sent = bot.send_message(ADMIN_ID, f"New msg from {user_id}:\n\n{message.text}")
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, baad mein try karo.")
42
+
43
+ # Bot ko background thread mein chalaao
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 space alive rakhne ke liye)
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)