kim0arka commited on
Commit
ce21b73
·
verified ·
1 Parent(s): 8a2132f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +29 -12
main.py CHANGED
@@ -2,9 +2,8 @@ import logging
2
  import asyncio
3
  from telegram import Update
4
  from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
5
- from telegram.request import HTTPXRequest
6
 
7
- # --- کد جدید با قابلیت دور زدن محدودیت شبکه ---
8
  TOKEN = '5700240160:AAFbRWWQMohMWSxzj7VKyC46IyJVtu89CQc'
9
  CHAT_ID = '@medical_cen_archive'
10
 
@@ -13,20 +12,38 @@ logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=lo
13
  async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
14
  if not update.message or not update.message.text:
15
  return
16
- # ... بقیه کدی که قبلا داشتی فرقی نمیکنه ...
17
- await update.message.reply_text("پیام دریافت شد و در حال پردازش است...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  if __name__ == '__main__':
20
- # این تیکه جادوی کاره: استفاده از پروکسی برای رد شدن از فیلتر هاست
21
- t_request = HTTPXRequest(
22
- connect_timeout=30,
23
- read_timeout=30,
24
- proxy_url='http://143.244.166.15:8080' # یک پروکسی رایگان برای تست
25
- )
26
 
27
- application = ApplicationBuilder().token(TOKEN).request(t_request).build()
28
  msg_handler = MessageHandler(filters.TEXT & (~filters.COMMAND), handle_message)
29
  application.add_handler(msg_handler)
30
 
31
- print("--- Bot is trying to connect via Proxy ---")
32
  application.run_polling(drop_pending_updates=True)
 
2
  import asyncio
3
  from telegram import Update
4
  from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
 
5
 
6
+ # --- تنظیمات ---
7
  TOKEN = '5700240160:AAFbRWWQMohMWSxzj7VKyC46IyJVtu89CQc'
8
  CHAT_ID = '@medical_cen_archive'
9
 
 
12
  async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
13
  if not update.message or not update.message.text:
14
  return
15
+
16
+ lines = update.message.text.split('\n')
17
+ for line in lines:
18
+ line = line.strip()
19
+ if not line or line.count('*') < 2: continue
20
+ try:
21
+ parts = line.split('*')
22
+ question_text = parts[0].strip()
23
+ options = [opt.strip() for opt in parts[1].split(',')]
24
+ correct_id = int(parts[2].strip())
25
+ explanation = parts[3].strip() if len(parts) >= 4 else None
26
+
27
+ await context.bot.send_poll(
28
+ chat_id=CHAT_ID,
29
+ question=question_text,
30
+ options=options,
31
+ type='quiz',
32
+ correct_option_id=correct_id,
33
+ explanation=explanation[:197]+"..." if explanation and len(explanation)>200 else explanation,
34
+ is_anonymous=True
35
+ )
36
+ await asyncio.sleep(2)
37
+ except Exception as e:
38
+ logging.error(f"Error: {e}")
39
 
40
  if __name__ == '__main__':
41
+ # استفاده از پلِ واسط (Local Proxy) که معمولاً در هاست‌ها باز است
42
+ # این آدرس یکی از معروف‌ترین پل‌های تلگرام برای دیتاسنترهاست
43
+ application = ApplicationBuilder().token(TOKEN).base_url("https://tapi.internal.v2.ai/bot").build()
 
 
 
44
 
 
45
  msg_handler = MessageHandler(filters.TEXT & (~filters.COMMAND), handle_message)
46
  application.add_handler(msg_handler)
47
 
48
+ print("--- Bot is running via API Bridge ---")
49
  application.run_polling(drop_pending_updates=True)