Offex commited on
Commit
8e8481e
Β·
verified Β·
1 Parent(s): ec12441

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -43
app.py CHANGED
@@ -1,69 +1,41 @@
1
  import os
2
  import telebot
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)
 
 
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()