Offex commited on
Commit
ec12441
Β·
verified Β·
1 Parent(s): 9f99f5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -20
app.py CHANGED
@@ -3,53 +3,67 @@ 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)
 
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)