Spaces:
Runtime error

Hammad2626 commited on
Commit
354d4ec
·
1 Parent(s): 63158c8

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +5 -0
  2. bot.py +129 -0
Dockerfile ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ FROM python:3.11
2
+ WORKDIR /code
3
+ COPY . .
4
+ RUN pip install --no-cache-dir pyTelegramBotAPI cloudscraper requests
5
+ CMD ["python", "bot.py"]
bot.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import telebot
2
+ import cloudscraper
3
+ import re
4
+ import base64
5
+ import requests
6
+ import json
7
+ from telebot import types
8
+
9
+ # --- Configuration ---
10
+ API_TOKEN = '8478249874:AAE5y8yx_zxiMd6SPFmZp662Jr0tVr_4L8c'
11
+ OCR_API_TOKEN = 'ed0002c02e888376f59dccb780e958e7'
12
+ ADMIN_ID = 993191413 # 🔔 ضع هنا الـ Chat ID الخاص بك لتصلك الإشعارات
13
+
14
+ bot = telebot.TeleBot(API_TOKEN)
15
+ scraper = cloudscraper.create_scraper()
16
+
17
+ # --- Helper Functions ---
18
+
19
+ def format_iid(iid):
20
+ clean = re.sub(r'\D', '', iid)
21
+ return "-".join(clean[i:i+7] for i in range(0, len(clean), 7))
22
+
23
+ def format_cid(cid):
24
+ clean = re.sub(r'\D', '', cid)
25
+ return "-".join(clean[i:i+6] for i in range(0, len(clean), 6))
26
+
27
+ def send_admin_log(user_info, user_input, bot_output):
28
+ """إرسال تقرير مفصل للأدمن بكل عملية"""
29
+ log_msg = (
30
+ "👤 <b>New User Activity!</b>\n"
31
+ f"<b>User:</b> {user_info.first_name} (@{user_info.username})\n"
32
+ f"<b>ID:</b> <code>{user_info.id}</code>\n\n"
33
+ f"📩 <b>User Sent:</b>\n<code>{user_input}</code>\n\n"
34
+ f"🤖 <b>Bot Replied:</b>\n<code>{bot_output}</code>"
35
+ )
36
+ try:
37
+ bot.send_message(ADMIN_ID, log_msg, parse_mode='HTML')
38
+ except:
39
+ pass
40
+
41
+ def get_cid_logic(iid):
42
+ url = "https://getcid.online/api/cid"
43
+ headers = {'Content-Type': 'application/json'}
44
+ payload = {"iid": re.sub(r'\D', '', iid)}
45
+ try:
46
+ response = scraper.post(url, json=payload, headers=headers, timeout=30)
47
+ if response.status_code == 200:
48
+ res_json = response.json()
49
+ if "cid" in res_json:
50
+ return res_json['cid'], True
51
+ return res_json.get("message", "Invalid IID"), False
52
+ return "Server Error", False
53
+ except:
54
+ return "Timeout", False
55
+
56
+ def process_ocr(photo_bytes):
57
+ url = "http://api.get-cid.com/api/ocr"
58
+ base64_data = base64.b64encode(photo_bytes).decode('utf-8')
59
+ payload = {"token": OCR_API_TOKEN, "mime_type": "image/jpeg", "image_base64": base64_data}
60
+ try:
61
+ response = requests.post(url, json=payload, timeout=30)
62
+ if response.status_code == 200:
63
+ res_data = response.json()
64
+ raw_text = res_data.get("extracted_text", "")
65
+ if raw_text:
66
+ clean = re.sub(r'\D', '', raw_text)
67
+ if len(clean) >= 48: return clean, True
68
+ return None, False
69
+ except:
70
+ return None, False
71
+
72
+ # --- Telegram Handlers ---
73
+
74
+ @bot.message_handler(commands=['start'])
75
+ def start(message):
76
+ bot.reply_to(message, "🛡️ <b>Microserial PRO</b>\nSend IID Photo or Text.", parse_mode='HTML')
77
+
78
+ @bot.message_handler(content_types=['photo'])
79
+ def handle_photo(message):
80
+ status_msg = bot.reply_to(message, "📸 <b>Reading Image...</b>", parse_mode='HTML')
81
+ file_info = bot.get_file(message.photo[-1].file_id)
82
+ downloaded_file = bot.download_file(file_info.file_path)
83
+
84
+ iid_text, ocr_success = process_ocr(downloaded_file)
85
+
86
+ if ocr_success:
87
+ cid_raw, cid_success = get_cid_logic(iid_text)
88
+ if cid_success:
89
+ show_final_result(message, status_msg.message_id, iid_text, cid_raw, "Image OCR")
90
+ else:
91
+ bot.edit_message_text(f"❌ Error: {cid_raw}", chat_id=message.chat.id, message_id=status_msg.message_id)
92
+ else:
93
+ bot.edit_message_text("❌ OCR Failed!", chat_id=message.chat.id, message_id=status_msg.message_id)
94
+
95
+ @bot.message_handler(func=lambda message: True)
96
+ def handle_text(message):
97
+ clean_iid = re.sub(r'\D', '', message.text)
98
+ if len(clean_iid) >= 48:
99
+ status_msg = bot.reply_to(message, "⏳ <b>Processing...</b>", parse_mode='HTML')
100
+ cid_raw, success = get_cid_logic(clean_iid)
101
+ if success:
102
+ show_final_result(message, status_msg.message_id, clean_iid, cid_raw, "Manual Text")
103
+ else:
104
+ bot.edit_message_text(f"❌ Error: {cid_raw}", chat_id=message.chat.id, message_id=status_msg.message_id)
105
+
106
+ def show_final_result(message, message_id, iid, cid, input_type):
107
+ f_iid = format_iid(iid)
108
+ f_cid = format_cid(cid)
109
+
110
+ # 📝 نص الرسالة النهائي للعميل مع جملة التوثيق
111
+ final_res = (
112
+ "✅ <b>Process Completed!</b>\n\n"
113
+ "<b>IID:</b>\n"
114
+ f"<code>{f_iid}</code>\n\n"
115
+ "<b>Confirmation ID (CID):</b>\n"
116
+ f"<code>{f_cid}</code>\n\n"
117
+ "<b>Get From Microsoft Database By Microserial</b>"
118
+ )
119
+
120
+ markup = types.InlineKeyboardMarkup()
121
+
122
+ bot.edit_message_text(final_res, chat_id=message.chat.id, message_id=message_id, parse_mode='HTML', reply_markup=markup)
123
+
124
+ # 🔔 إرسال الإشعار للأدمن (أنت)
125
+ send_admin_log(message.from_user, f"Input: {input_type} | IID: {f_iid}", f"CID: {f_cid}")
126
+
127
+ if __name__ == "__main__":
128
+ print("🚀 Microserial PRO (Admin Version) is Live!")
129
+ bot.infinity_polling(skip_pending=True)