-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHe hosted .py
More file actions
6266 lines (5367 loc) · 490 KB
/
Copy pathHe hosted .py
File metadata and controls
6266 lines (5367 loc) · 490 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
╔══════════════════════════════════════════════════════════════╗
║ 24xRaven Telegram Bot ║
║ Developed by ✘ 𝙍𝘼𝙑𝙀𝙉 ║
║ ║
║ GitHub: https://github.com/hsh34811-hash ║
║ Telegram: @P_X_24 ║
║ Channel: https://t.me/Raven_xx24 ║
║ ║
║ Copyright © 2026 ✘ 𝙍𝘼𝙑𝙀𝙉 - All Rights Reserved ║
╚══════════════════════════════════════════════════════════════╝
"""
import sys
import telebot
from telebot import types
import io
import tokenize
import requests
import time
from threading import Thread
import subprocess
import string
from collections import defaultdict
from datetime import datetime
import psutil
import random
import sys
import random
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
import string
import re
import chardet
import difflib
# import google.generativeai as genai # تم تعطيلها مؤقتاً
from bs4 import BeautifulSoup
# إعدادات البوتات
from deep_translator import GoogleTranslator
from concurrent.futures import ThreadPoolExecutor
from sympy import sympify
import segno
import os
import logging
import telebot
from telebot import types
import threading
# إعدادات البوتات
mandatory_subscription_channel = 'https://t.me/YOUR_CHANNEL' # هنا هتحط قناتك اشتراك اجباري
BOT_TOKEN = 'YOUR_BOT_TOKEN_HERE' # ضع التوكن الخاص بك هنا
ADMIN_ID = 'YOUR_TELEGRAM_ID' # ضع الـ ID الخاص بك هنا
# نظام التحكم في الاشتراك الإجباري
FORCE_SUBSCRIPTION = True # True = مفعل، False = معطل
# تحميل قائمة القنوات من ملف أو استخدام القيمة الافتراضية
def load_subscription_channels():
try:
if os.path.exists('subscription_channels.txt'):
with open('subscription_channels.txt', 'r', encoding='utf-8') as f:
channels = [line.strip() for line in f.readlines() if line.strip()]
return channels if channels else ['@Raven_xx24']
else:
return ['@Raven_xx24']
except:
return ['@Raven_xx24']
def save_subscription_channels():
try:
with open('subscription_channels.txt', 'w', encoding='utf-8') as f:
for channel in SUBSCRIPTION_CHANNELS:
f.write(channel + '\n')
except Exception as e:
print(f"Error saving channels: {e}")
SUBSCRIPTION_CHANNELS = load_subscription_channels() # قائمة القنوات للاشتراك الإجباري
#### اختياري - يمكنك تركها فارغة
VIRUSTOTAL_API_KEY = 'YOUR_VIRUSTOTAL_API_KEY' # اختياري - للفحص الأمني المتقدم
API_GEMINI = 'YOUR_GEMINI_API_KEY' # اختياري - لميزة الذكاء الاصطناعي
bot_creator = "@P_X_24" # معرف المطور
banned_libraries = ['examplelib', 'badlib'] # قائمة المكتبات المحظورة
###### طبعا كل حاجه هتحطها بدون ما تشيل اي اقواس او علامات تنصيص
### متلعبش ف الحجات دي
banned_users = set()
bot_scripts1 = defaultdict(lambda: {'processes': [], 'name': '', 'path': '', 'uploader': ''}) # لإدارة العمليات
user_files = {}
lock = threading.Lock()
executor = ThreadPoolExecutor(max_workers=3000)
bot = telebot.TeleBot(BOT_TOKEN)
bot_scripts = {}
uploaded_files_dir = "uploaded_files"
user_chats = {}
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
#################### حذف أي webhook نشط لضمان استخدام polling ############
def display_copyright():
"""عرض حقوق الملكية عند بدء تشغيل البوت"""
print("╔══════════════════════════════════════════════════════════════╗")
print("║ 24xRaven Telegram Bot ║")
print("║ Developed by ✘ 𝙍𝘼𝙑𝙀𝙉 ║")
print("║ ║")
print("║ GitHub: https://github.com/hsh34811-hash ║")
print("║ Telegram: @P_X_24 ║")
print("║ Channel: https://t.me/Raven_xx24 ║")
print("║ ║")
print("║ Copyright © 2026 ✘ 𝙍𝘼𝙑𝙀𝙉 - All Rights Reserved ║")
print("╚══════════════════════════════════════════════════════════════╝")
# عرض حقوق الملكية عند بدء التشغيل
display_copyright()
bot.remove_webhook()
#################### إنشاء مجلد uploaded_files إذا لم يكن موجوداً####################
if not os.path.exists(uploaded_files_dir):
os.makedirs(uploaded_files_dir)
#################### تحقق من الاشتراك في القناه ###########################
def check_subscription(user_id):
print(f"[DEBUG] Checking subscription for user {user_id}")
print(f"[DEBUG] FORCE_SUBSCRIPTION: {FORCE_SUBSCRIPTION}")
print(f"[DEBUG] ADMIN_ID: {ADMIN_ID}")
print(f"[DEBUG] SUBSCRIPTION_CHANNELS: {SUBSCRIPTION_CHANNELS}")
# إذا كان نظام الاشتراك معطل، السماح للجميع
if not FORCE_SUBSCRIPTION:
print(f"[DEBUG] FORCE_SUBSCRIPTION is False, allowing user {user_id}")
return True
# إذا كان المستخدم هو الأدمن، السماح له دائماً
if str(user_id) == ADMIN_ID:
print(f"[DEBUG] User {user_id} is admin, allowing access")
return True
# إذا لم تكن هناك قنوات محددة، منع الجميع (لأن النظام مفعل لكن لا توجد قنوات)
if not SUBSCRIPTION_CHANNELS:
print(f"[DEBUG] No subscription channels defined but FORCE_SUBSCRIPTION is True, blocking user {user_id}")
return False
print(f"[DEBUG] Checking subscription for user {user_id} in channels: {SUBSCRIPTION_CHANNELS}")
try:
# فحص الاشتراك في جميع القنوات المطلوبة
for channel in SUBSCRIPTION_CHANNELS:
print(f"[DEBUG] Checking subscription in channel {channel} for user {user_id}")
try:
member_status = bot.get_chat_member(channel, user_id).status
print(f"[DEBUG] User {user_id} status in {channel}: {member_status}")
if member_status not in ['member', 'administrator', 'creator']:
print(f"[DEBUG] User {user_id} is not subscribed to {channel}")
return False
except Exception as channel_error:
print(f"[DEBUG] Error checking channel {channel} for user {user_id}: {channel_error}")
# في حالة خطأ في فحص قناة معينة، اعتبر المستخدم غير مشترك
return False
print(f"[DEBUG] User {user_id} is subscribed to all channels")
return True
except Exception as e:
print(f"[DEBUG] General error checking subscription for user {user_id}: {e}")
logging.error(f"Error checking subscription: {e}")
return False # في حالة الخطأ، منع المستخدم من الدخول
#################### دالة مساعدة لإرسال الملفات مع فحص الحجم ####################
def safe_send_document(chat_id, file_path, caption=None, max_size_mb=50):
"""
إرسال ملف مع فحص الحجم
chat_id: معرف المحادثة
file_path: مسار الملف
caption: وصف الملف (اختياري)
max_size_mb: الحد الأقصى للحجم بالميجابايت (افتراضي 50)
"""
try:
# فحص حجم الملف
file_size = os.path.getsize(file_path)
file_size_mb = file_size / (1024 * 1024) # تحويل إلى ميجابايت
if file_size_mb > max_size_mb:
bot.send_message(
chat_id,
f"❌ عذراً، حجم الملف ({file_size_mb:.2f} MB) أكبر من الحد المسموح ({max_size_mb} MB).\n\n"
f"💡 يمكنك:\n"
f"• ضغط الملف\n"
f"• تقسيمه إلى أجزاء أصغر\n"
f"• رفعه على خدمة تخزين سحابي ومشاركة الرابط"
)
return False
# إرسال الملف
with open(file_path, 'rb') as file:
if caption:
bot.send_document(chat_id, file, caption=caption)
else:
bot.send_document(chat_id, file)
return True
except Exception as e:
error_msg = str(e)
if "file is too big" in error_msg.lower():
bot.send_message(
chat_id,
f"❌ الملف كبير جداً للإرسال عبر تيليجرام.\n"
f"الحد الأقصى: {max_size_mb} MB"
)
else:
bot.send_message(chat_id, f"❌ حدث خطأ أثناء إرسال الملف: {error_msg}")
return False
##################### بدايه حظر اشاء معينه وحمايه ########################
def is_safe_file(file_path):
"""دالة للتحقق من أن الملف لا يحتوي على تعليمات لإنشاء أرشيفات أو إرسالها عبر بوت"""
try:
with open(file_path, 'rb') as f:
raw_content = f.read()
# تحقق من ترميز الملف
encoding_info = chardet.detect(raw_content)
encoding = encoding_info['encoding']
if encoding is None:
logging.warning("Unable to detect encoding, file may be binary or encrypted.")
return "لم يتم رفع الملف فيه اوامر غير مسموح بها"
# تحويل المحتوى إلى نص باستخدام الترميز المكتشف
content = raw_content.decode(encoding)
dangerous_patterns = [
r'\bshutil\.make_archive\b', # إنشاء أرشيف
r'bot\.send_document\b', # إرسال ملفات عبر بوت
r'\bopen\s*\(\s*.*,\s*[\'\"]w[\'\"]\s*\)', # فتح ملف للكتابة
r'\bopen\s*\(\s*.*,\s*[\'\"]a[\'\"]\s*\)', # فتح ملف للإلحاق
r'\bopen\s*\(\s*.*,\s*[\'\"]wb[\'\"]\s*\)', # فتح ملف للكتابة الثنائية
r'\bopen\s*\(\s*.*,\s*[\'\"]ab[\'\"]\s*\)', # فتح ملف للإلحاق الثنائي
]
for pattern in dangerous_patterns:
if re.search(pattern, content):
return "لم يتم رفع الملف فيه اوامر غير مسموح بها"
# تحقق من أن المحتوى نصي وليس مشفرًا
if not is_text(content):
return "لم يتم رفع الملف فيه اوامر غير مسموح بها"
return "الملف آمن"
except Exception as e:
logging.error(f"Error checking file safety: {e}")
return "لم يتم رفع الملف فيه اوامر غير مسموح بها"
def is_text(content):
"""دالة للتحقق مما إذا كان المحتوى نصيًا"""
for char in content:
if char not in string.printable:
return False
return True
####################### بدايه الدوال #######################
### حفظ id شات
def save_chat_id(chat_id):
"""دالة لحفظ chat_id للمستخدمين الذين يتفاعلون مع البوت."""
if chat_id not in user_chats:
user_chats[chat_id] = True # يمكنك تخزين معلومات إضافية هنا إذا لزم الأمر
print(f"تم حفظ chat_id: {chat_id}")
else:
print(f"chat_id: {chat_id} موجود بالفعل.")
################################################################## داله البدأ
# قائمة لحفظ معرفات المستخدمين
user_ids = set()
def save_chat_id(chat_id):
# إضافة chat_id إلى المجموعة لضمان عدم التكرار
user_ids.add(chat_id)
@bot.message_handler(commands=['start'])
def start(message):
# حفظ chat_id عند بدء التفاعل
save_chat_id(message.chat.id)
if message.from_user.username in banned_users:
bot.send_message(message.chat.id, "تم حظرك من البوت. تواصل مع المطور @P_X_24")
return
# إذا كان المستخدم هو الأدمن، تخطي فحص الاشتراك تماماً
is_admin = str(message.from_user.id) == ADMIN_ID
print(f"[DEBUG] User {message.from_user.id}, is_admin: {is_admin}, ADMIN_ID: {ADMIN_ID}")
print(f"[DEBUG] FORCE_SUBSCRIPTION: {FORCE_SUBSCRIPTION}, SUBSCRIPTION_CHANNELS: {SUBSCRIPTION_CHANNELS}")
# فحص الاشتراك للمستخدمين العاديين فقط
if not is_admin and FORCE_SUBSCRIPTION and len(SUBSCRIPTION_CHANNELS) > 0:
print(f"[DEBUG] Checking subscription for regular user {message.from_user.id}")
# فحص الاشتراك
is_subscribed = check_subscription(message.from_user.id)
print(f"[DEBUG] User {message.from_user.id} subscription status: {is_subscribed}")
if not is_subscribed:
print(f"[DEBUG] User {message.from_user.id} is not subscribed, showing subscription UI")
# تصميم قائمة الاشتراك الجميلة
markup = types.InlineKeyboardMarkup()
# إضافة أزرار للقنوات المطلوبة (كل قناة في صف منفصل)
for i, channel in enumerate(SUBSCRIPTION_CHANNELS, 1):
channel_name = channel.replace('@', '') if channel.startswith('@') else channel
channel_url = f"https://t.me/{channel[1:]}" if channel.startswith('@') else channel
# أيقونات مختلفة لكل قناة
icons = ['📢', '🔔', '⭐', '💎', '🎯', '🚀', '⚡', '🔥']
icon = icons[(i-1) % len(icons)]
subscribe_button = types.InlineKeyboardButton(
f"{icon} اشترك في {channel_name}",
url=channel_url
)
markup.add(subscribe_button)
# زر التحقق من الاشتراك (مميز)
check_button = types.InlineKeyboardButton("✅ تحقق من الاشتراك", callback_data='check_subscription')
markup.add(check_button)
# زر المساعدة
help_button = types.InlineKeyboardButton("❓ المساعدة", callback_data='subscription_help')
markup.add(help_button)
# رسالة ترحيب جميلة
welcome_msg = f"""🎉 مرحباً بك في البوت!
👋 أهلاً {message.from_user.first_name or 'صديقي'}!
🔐 للاستمتاع بجميع مميزات البوت، يرجى الاشتراك في القنوات التالية:
"""
# إضافة قائمة القنوات بتنسيق جميل
for i, channel in enumerate(SUBSCRIPTION_CHANNELS, 1):
channel_name = channel.replace('@', '') if channel.startswith('@') else channel
icons = ['📢', '🔔', '⭐', '💎', '🎯', '🚀', '⚡', '🔥']
icon = icons[(i-1) % len(icons)]
welcome_msg += f"{icon} القناة {i}: {channel_name}\n"
welcome_msg += f"""
🎯 بعد الاشتراك في جميع القنوات:
• اضغط على زر "✅ تحقق من الاشتراك"
• ستحصل على وصول كامل لجميع مميزات البوت
💡 ملاحظة: الاشتراك مجاني ويساعدنا في تطوير البوت!
تم تطوير البوت بواسطة: @P_X_24"""
bot.send_message(
message.chat.id,
welcome_msg,
reply_markup=markup
)
return # إيقاف المسار هنا - المستخدم لن يرى أي شيء آخر
else:
print(f"[DEBUG] User {message.from_user.id} is subscribed, allowing access")
else:
print(f"[DEBUG] Skipping subscription check for user {message.from_user.id} (admin: {is_admin}, force_sub: {FORCE_SUBSCRIPTION}, channels: {len(SUBSCRIPTION_CHANNELS)})")
# إضافة المستخدم إلى bot_scripts
bot_scripts[message.chat.id] = {
'name': message.from_user.username,
'uploader': message.from_user.username,
}
# إعداد الأزرار والرسائل العامة
markup = types.InlineKeyboardMarkup()
upload_button = types.InlineKeyboardButton("رفع ملف 📤", callback_data='upload')
libraries_button = types.InlineKeyboardButton("رفع مكتبات 📚", callback_data='upload_libraries')
developer_button = types.InlineKeyboardButton("قناة مطور البوت", url=mandatory_subscription_channel)
commands_button = types.InlineKeyboardButton("الأوامر", callback_data='commands')
instructions_button = types.InlineKeyboardButton("تعليمات", callback_data='instructions')
# إضافة أزرار خاصة للأدمن
if is_admin:
admin_panel_button = types.InlineKeyboardButton("🔧 لوحة الأدمن", callback_data='admin_panel')
subscription_button = types.InlineKeyboardButton("📋 إدارة الاشتراك", callback_data='subscription_panel')
markup.row(admin_panel_button, subscription_button)
markup.row(upload_button, libraries_button)
markup.row(developer_button)
markup.row(commands_button, instructions_button)
# رسالة ترحيب مختلفة للأدمن
welcome_message = f"_____________________________________________\n"
if is_admin:
welcome_message += f"👑 مرحباً بك أيها المالك!\n"
welcome_message += f"🆔 معرفك: {message.from_user.id}\n"
welcome_message += f"📊 حالة الاشتراك الإجباري: {'مفعل ✅' if FORCE_SUBSCRIPTION else 'معطل ❌'}\n"
welcome_message += f"📋 عدد القنوات: {len(SUBSCRIPTION_CHANNELS)}\n\n"
welcome_message += "مرحبًا بك في بوت رفع وتشغيل ملفات بايثون.\n"
welcome_message += "استخدم الأزرار بالأسفل للتفاعل.\n"
welcome_message += "_____________________________________________\n"
welcome_message += f"BOT BY : {bot_creator}"
bot.send_message(
message.chat.id,
welcome_message,
reply_markup=markup
)
# عند استقبال الضغط على زر الأوامر
@bot.callback_query_handler(func=lambda call: call.data == 'commands')
def process_commands_callback(call):
bot.answer_callback_query(call.id)
markup = types.InlineKeyboardMarkup()
back_button = types.InlineKeyboardButton("🔙 الرجوع للقائمة الرئيسية", callback_data='back_to_main')
markup.add(back_button)
bot.send_message(
call.message.chat.id,
"مرحبا بك !\n"
"الاوامر في البوت هيا\n"
"/help للمساعده.\n"
"/cmd اوامر مهمه في البوت \n"
"/cr اوامر عشوائيه بس تفيد \n"
"/adm دي طبعا بتاعت الادمن يقدر يتحكم في البوت من خلال للوحه \n"
"دي اوامر البوت فقط ليس شرح كامل .",
reply_markup=markup
)
#####################################################################لوحه الادمن
blocked_users = set()
def is_user_blocked(user_id):
return user_id in blocked_users
# رسالة للمستخدمين المحظورين
BLOCKED_MESSAGE = f"تم حظرك من البوت. تواصل مع المطور {bot_creator}"
# دالة لإيقاف ملف معين
def stop_bot(script_path, chat_id):
try:
script_name = script_path.split('/')[-1]
process = bot_scripts.get(chat_id, {}).get('process')
if process and psutil.pid_exists(process.pid):
parent = psutil.Process(process.pid)
for child in parent.children(recursive=True):
child.terminate()
parent.terminate()
parent.wait() # التأكد من أن العملية توقفت
bot_scripts[chat_id]['process'] = None
bot.send_message(chat_id, f"تم إيقاف {script_name} بنجاح.")
return True
else:
bot.send_message(chat_id, f"عملية {script_name} غير موجودة أو أنها قد توقفت بالفعل.")
return False
except Exception as e:
logging.error(f"Error stopping bot: {e}")
bot.send_message(chat_id, f"حدث خطأ أثناء إيقاف {script_name}: {e}")
return False
def start_file(script_path, chat_id):
try:
script_name = script_path.split('/')[-1]
if bot_scripts.get(chat_id, {}).get('process') and psutil.pid_exists(bot_scripts[chat_id]['process'].pid):
bot.send_message(chat_id, f"الملف {script_name} يعمل بالفعل.")
return False
else:
p = subprocess.Popen([sys.executable, script_path])
bot_scripts[chat_id] = {'process': p, 'path': script_path, 'name': script_name}
bot.send_message(chat_id, f"تم تشغيل {script_name} بنجاح.")
return True
except Exception as e:
logging.error(f"Error starting bot: {e}")
bot.send_message(chat_id, f"حدث خطأ أثناء تشغيل {script_name}: {e}")
return False
def stop_all_files(chat_id):
if is_user_blocked(chat_id):
bot.send_message(chat_id, BLOCKED_MESSAGE)
return
stopped_files = []
for chat_id, script_info in list(bot_scripts.items()):
if stop_bot(script_info['path'], chat_id):
stopped_files.append(script_info['name'])
if stopped_files:
bot.send_message(chat_id, f"تم إيقاف الملفات التالية بنجاح: {', '.join(stopped_files)}")
else:
bot.send_message(chat_id, "لا توجد ملفات قيد التشغيل لإيقافها.")
def start_all_files(chat_id):
if is_user_blocked(chat_id):
bot.send_message(chat_id, BLOCKED_MESSAGE)
return
started_files = []
for chat_id, script_info in list(bot_scripts.items()):
if start_file(script_info['path'], chat_id):
started_files.append(script_info['name'])
if started_files:
bot.send_message(chat_id, f"تم تشغيل الملفات التالية بنجاح: {', '.join(started_files)}")
else:
bot.send_message(chat_id, "لا توجد ملفات متوقفة لتشغيلها.")
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
banned_users = set()
instructions_text = ""
instructions_file = "instructions.txt"
if os.path.exists(instructions_file):
with open(instructions_file, 'r', encoding='utf-8') as file:
instructions_text = file.read()
@bot.message_handler(commands=['adm'])
def admin_panel(message):
try:
if str(message.from_user.id) != ADMIN_ID:
bot.reply_to(message, "🚫 ليس لديك صلاحية استخدام هذا الأمر.")
return
markup = types.InlineKeyboardMarkup()
stats_button = types.InlineKeyboardButton("إحصائيات 📊", callback_data='stats')
ban_button = types.InlineKeyboardButton("حظر مستخدم 🚫", callback_data='ban_user')
uban_button = types.InlineKeyboardButton("فك حظر مستخدم ✅", callback_data='unban_user')
rck_button = types.InlineKeyboardButton("إرسال رسالة للجميع 📢", callback_data='broadcast')
add_instructions_button = types.InlineKeyboardButton("إضافة تعليمات 📝", callback_data='add_instructions')
markup.add(stats_button)
markup.add(ban_button, uban_button)
markup.add(rck_button)
markup.add(add_instructions_button)
bot.send_message(message.chat.id, "🔧 لوحة تحكم الأدمن:", reply_markup=markup)
except Exception as e:
logging.error(f"Error in admin_panel: {e}")
bot.reply_to(message, "⚠️ حدث خطأ أثناء محاولة عرض لوحة التحكم.")
# أوامر التحكم في نظام الاشتراك الإجباري
@bot.message_handler(commands=['subscription'])
def subscription_control(message):
if str(message.from_user.id) != ADMIN_ID:
bot.reply_to(message, "🚫 ليس لديك صلاحية استخدام هذا الأمر.")
return
global FORCE_SUBSCRIPTION
status = "مفعل ✅" if FORCE_SUBSCRIPTION else "معطل ❌"
channels_list = "\n".join([f"• {ch}" for ch in SUBSCRIPTION_CHANNELS]) if SUBSCRIPTION_CHANNELS else "لا توجد قنوات"
markup = types.InlineKeyboardMarkup()
toggle_btn = types.InlineKeyboardButton(
"تعطيل الاشتراك ❌" if FORCE_SUBSCRIPTION else "تفعيل الاشتراك ✅",
callback_data='toggle_subscription'
)
add_channel_btn = types.InlineKeyboardButton("إضافة قناة ➕", callback_data='add_channel')
remove_channel_btn = types.InlineKeyboardButton("حذف قناة ➖", callback_data='remove_channel')
list_channels_btn = types.InlineKeyboardButton("عرض القنوات 📋", callback_data='list_channels')
markup.add(toggle_btn)
markup.add(add_channel_btn, remove_channel_btn)
markup.add(list_channels_btn)
bot.send_message(
message.chat.id,
f"🔧 **إدارة نظام الاشتراك الإجباري**\n\n"
f"الحالة: {status}\n"
f"عدد القنوات: {len(SUBSCRIPTION_CHANNELS)}\n\n"
f"**القنوات المضافة:**\n{channels_list}",
reply_markup=markup,
parse_mode="Markdown"
)
@bot.callback_query_handler(func=lambda call: call.data == 'toggle_subscription')
def toggle_subscription(call):
if str(call.from_user.id) != ADMIN_ID:
bot.answer_callback_query(call.id, "ليس لديك صلاحية!")
return
global FORCE_SUBSCRIPTION
FORCE_SUBSCRIPTION = not FORCE_SUBSCRIPTION
status = "مفعل ✅" if FORCE_SUBSCRIPTION else "معطل ❌"
bot.answer_callback_query(call.id, f"تم! النظام الآن {status}")
# إعادة إرسال القائمة المحدثة
channels_list = "\n".join([f"• {ch}" for ch in SUBSCRIPTION_CHANNELS]) if SUBSCRIPTION_CHANNELS else "لا توجد قنوات"
markup = types.InlineKeyboardMarkup()
toggle_btn = types.InlineKeyboardButton(
"تعطيل الاشتراك ❌" if FORCE_SUBSCRIPTION else "تفعيل الاشتراك ✅",
callback_data='toggle_subscription'
)
add_channel_btn = types.InlineKeyboardButton("إضافة قناة ➕", callback_data='add_channel')
remove_channel_btn = types.InlineKeyboardButton("حذف قناة ➖", callback_data='remove_channel')
list_channels_btn = types.InlineKeyboardButton("عرض القنوات 📋", callback_data='list_channels')
markup.add(toggle_btn)
markup.add(add_channel_btn, remove_channel_btn)
markup.add(list_channels_btn)
try:
bot.edit_message_text(
f"🔧 **إدارة نظام الاشتراك الإجباري**\n\n"
f"الحالة: {status}\n"
f"عدد القنوات: {len(SUBSCRIPTION_CHANNELS)}\n\n"
f"**القنوات المضافة:**\n{channels_list}",
call.message.chat.id,
call.message.message_id,
reply_markup=markup,
parse_mode="Markdown"
)
except:
# إذا فشل التعديل، أرسل رسالة جديدة
bot.send_message(
call.message.chat.id,
f"🔧 **إدارة نظام الاشتراك الإجباري**\n\n"
f"الحالة: {status}\n"
f"عدد القنوات: {len(SUBSCRIPTION_CHANNELS)}\n\n"
f"**القنوات المضافة:**\n{channels_list}",
reply_markup=markup,
parse_mode="Markdown"
)
@bot.callback_query_handler(func=lambda call: call.data == 'add_channel')
def add_channel_request(call):
print(f"[DEBUG] add_channel button pressed by user {call.from_user.id}")
if str(call.from_user.id) != ADMIN_ID:
bot.answer_callback_query(call.id, "ليس لديك صلاحية!")
return
bot.answer_callback_query(call.id, "جاري فتح نافذة إضافة القناة...")
bot.send_message(call.message.chat.id, "📝 أرسل معرف القناة أو الرابط (مثال: @channel_name أو https://t.me/channel_name):")
bot.register_next_step_handler(call.message, add_channel_handler)
def add_channel_handler(message):
if str(message.from_user.id) != ADMIN_ID:
return
channel = message.text.strip()
if channel.startswith('https://t.me/'):
channel = '@' + channel.split('/')[-1]
elif not channel.startswith('@'):
channel = '@' + channel
global SUBSCRIPTION_CHANNELS
if channel not in SUBSCRIPTION_CHANNELS:
SUBSCRIPTION_CHANNELS.append(channel)
save_subscription_channels() # حفظ التغييرات في الملف
bot.reply_to(message, f"✅ تم إضافة القناة: {channel}")
else:
bot.reply_to(message, f"⚠️ القناة {channel} موجودة بالفعل!")
@bot.callback_query_handler(func=lambda call: call.data == 'remove_channel')
def remove_channel_request(call):
print(f"[DEBUG] remove_channel button pressed by user {call.from_user.id}")
if str(call.from_user.id) != ADMIN_ID:
bot.answer_callback_query(call.id, "ليس لديك صلاحية!")
return
if not SUBSCRIPTION_CHANNELS:
bot.answer_callback_query(call.id, "لا توجد قنوات لحذفها!")
bot.send_message(call.message.chat.id, "❌ لا توجد قنوات لحذفها!")
return
bot.answer_callback_query(call.id, "اختر القناة المراد حذفها...")
markup = types.InlineKeyboardMarkup()
for i, channel in enumerate(SUBSCRIPTION_CHANNELS):
btn = types.InlineKeyboardButton(f"حذف {channel}", callback_data=f'del_ch_{i}')
markup.add(btn)
bot.send_message(call.message.chat.id, "اختر القناة المراد حذفها:", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: call.data.startswith('del_ch_'))
def delete_channel(call):
if str(call.from_user.id) != ADMIN_ID:
bot.answer_callback_query(call.id, "ليس لديك صلاحية!")
return
try:
index = int(call.data.split('_')[2])
global SUBSCRIPTION_CHANNELS
if 0 <= index < len(SUBSCRIPTION_CHANNELS):
deleted_channel = SUBSCRIPTION_CHANNELS.pop(index)
save_subscription_channels() # حفظ التغييرات في الملف
bot.answer_callback_query(call.id, f"تم حذف {deleted_channel}")
bot.edit_message_text("✅ تم حذف القناة بنجاح!", call.message.chat.id, call.message.message_id)
else:
bot.answer_callback_query(call.id, "خطأ في الفهرس!")
except:
bot.answer_callback_query(call.id, "حدث خطأ!")
@bot.callback_query_handler(func=lambda call: call.data == 'list_channels')
def list_channels(call):
if str(call.from_user.id) != ADMIN_ID:
bot.answer_callback_query(call.id, "ليس لديك صلاحية!")
return
if not SUBSCRIPTION_CHANNELS:
markup = types.InlineKeyboardMarkup()
back_button = types.InlineKeyboardButton("� الرجوع لإدارة الاشتراك", callback_data='subscription_panel')
markup.add(back_button)
bot.send_message(call.message.chat.id, "📋 لا توجد قنوات مضافة حالياً.", reply_markup=markup)
return
channels_text = "📋 **قائمة القنوات:**\n\n"
for i, channel in enumerate(SUBSCRIPTION_CHANNELS, 1):
channels_text += f"{i}. {channel}\n"
markup = types.InlineKeyboardMarkup()
back_button = types.InlineKeyboardButton("🔙 الرجوع لإدارة الاشتراك", callback_data='subscription_panel')
markup.add(back_button)
bot.send_message(call.message.chat.id, channels_text, parse_mode="Markdown", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: call.data == 'check_subscription')
def check_subscription_callback(call):
if check_subscription(call.from_user.id):
bot.answer_callback_query(call.id, "✅ تم التحقق بنجاح!")
bot.edit_message_text(
"✅ تم التحقق من اشتراكك بنجاح! يمكنك الآن استخدام البوت.\n\nاكتب /start للبدء.",
call.message.chat.id,
call.message.message_id
)
else:
bot.answer_callback_query(call.id, "❌ لم تشترك في جميع القنوات المطلوبة!")
bot.send_message(call.message.chat.id, "❌ يرجى الاشتراك في جميع القنوات المطلوبة أولاً.")
@bot.callback_query_handler(func=lambda call: call.data == 'subscription_help')
def subscription_help(call):
help_text = """❓ **مساعدة الاشتراك**
🤔 **لماذا الاشتراك مطلوب؟**
• للحصول على آخر التحديثات
• دعم تطوير البوت
• الحصول على مميزات حصرية
📱 **كيفية الاشتراك:**
1️⃣ اضغط على أزرار القنوات أعلاه
2️⃣ اضغط "Join" أو "انضمام" في كل قناة
3️⃣ ارجع للبوت واضغط "✅ تحقق من الاشتراك"
⚠️ **مشاكل شائعة:**
• تأكد من الاشتراك في **جميع** القنوات
• انتظر بضع ثوان بعد الاشتراك
• تأكد من عدم كتم القنوات
💡 **نصيحة:** الاشتراك سريع ومجاني!"""
markup = types.InlineKeyboardMarkup()
back_button = types.InlineKeyboardButton("🔙 الرجوع", callback_data='back_to_main')
markup.add(back_button)
bot.send_message(call.message.chat.id, help_text, parse_mode="Markdown", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: call.data == 'admin_panel')
def admin_panel_callback(call):
print(f"[DEBUG] admin_panel button pressed by user {call.from_user.id}, ADMIN_ID: {ADMIN_ID}")
if str(call.from_user.id) != ADMIN_ID:
print(f"[DEBUG] Access denied for user {call.from_user.id}")
bot.answer_callback_query(call.id, "🚫 ليس لديك صلاحية!")
return
print(f"[DEBUG] Access granted for admin {call.from_user.id}")
# إنشاء لوحة الأدمن مباشرة
try:
markup = types.InlineKeyboardMarkup()
stats_button = types.InlineKeyboardButton("إحصائيات 📊", callback_data='stats')
ban_button = types.InlineKeyboardButton("حظر مستخدم 🚫", callback_data='ban_user')
uban_button = types.InlineKeyboardButton("فك حظر مستخدم ✅", callback_data='unban_user')
rck_button = types.InlineKeyboardButton("إرسال رسالة للجميع 📢", callback_data='broadcast')
add_instructions_button = types.InlineKeyboardButton("إضافة تعليمات 📝", callback_data='add_instructions')
markup.add(stats_button)
markup.add(ban_button, uban_button)
markup.add(rck_button)
markup.add(add_instructions_button)
bot.send_message(call.message.chat.id, "🔧 لوحة تحكم الأدمن:", reply_markup=markup)
bot.answer_callback_query(call.id, "تم فتح لوحة الأدمن!")
print(f"[DEBUG] Admin panel sent successfully to {call.from_user.id}")
except Exception as e:
print(f"[DEBUG] Error in admin_panel_callback: {e}")
bot.answer_callback_query(call.id, "⚠️ حدث خطأ أثناء محاولة عرض لوحة التحكم.")
@bot.callback_query_handler(func=lambda call: call.data == 'subscription_panel')
def subscription_panel_callback(call):
if str(call.from_user.id) != ADMIN_ID:
bot.answer_callback_query(call.id, "🚫 ليس لديك صلاحية!")
return
# استدعاء لوحة إدارة الاشتراك مباشرة
global FORCE_SUBSCRIPTION
status = "مفعل ✅" if FORCE_SUBSCRIPTION else "معطل ❌"
channels_list = "\n".join([f"• {ch}" for ch in SUBSCRIPTION_CHANNELS]) if SUBSCRIPTION_CHANNELS else "لا توجد قنوات"
markup = types.InlineKeyboardMarkup()
toggle_btn = types.InlineKeyboardButton(
"تعطيل الاشتراك ❌" if FORCE_SUBSCRIPTION else "تفعيل الاشتراك ✅",
callback_data='toggle_subscription'
)
add_channel_btn = types.InlineKeyboardButton("إضافة قناة ➕", callback_data='add_channel')
remove_channel_btn = types.InlineKeyboardButton("حذف قناة ➖", callback_data='remove_channel')
list_channels_btn = types.InlineKeyboardButton("عرض القنوات 📋", callback_data='list_channels')
markup.add(toggle_btn)
markup.add(add_channel_btn, remove_channel_btn)
markup.add(list_channels_btn)
bot.send_message(
call.message.chat.id,
f"🔧 **إدارة نظام الاشتراك الإجباري**\n\n"
f"الحالة: {status}\n"
f"عدد القنوات: {len(SUBSCRIPTION_CHANNELS)}\n\n"
f"**القنوات المضافة:**\n{channels_list}",
reply_markup=markup,
parse_mode="Markdown"
)
############# احصائيالت
@bot.callback_query_handler(func=lambda call: call.data == 'stats')
def show_statistics(call):
try:
total_users = len(user_ids)
markup = types.InlineKeyboardMarkup()
back_button = types.InlineKeyboardButton("🔙 الرجوع للوحة الأدمن", callback_data='admin_panel')
markup.add(back_button)
bot.send_message(call.message.chat.id, f"(———————————)\n\nاحصائيات بوتك :\nعدد المستخدمين : {total_users}\n\n(———————————)", reply_markup=markup)
except Exception as e:
logging.error(f"Error in show_statistics: {e}")
bot.send_message(call.message.chat.id, "⚠️ حدث خطأ أثناء عرض الإحصائيات.")
#### تقدر تضيف اكتر بس الموضوع متعبت ولو انت مش محترف متلعبش ف حاجه
#### تعليمات البوت !
@bot.callback_query_handler(func=lambda call: call.data == 'instructions')
def process_instructions_callback(call):
bot.answer_callback_query(call.id)
instructions_text = """📋 دليل استخدام البوت الشامل
🎯 ما هو هذا البوت؟
بوت متعدد الوظائف لرفع وتشغيل ملفات Python مع أدوات مساعدة متنوعة
🔧 الوظائف الأساسية:
📤 رفع الملفات:
• ارفع ملف Python (.py) عبر زر "رفع ملف"
• ارفع ملف المكتبات (requirements.txt) عبر زر "رفع مكتبات"
• البوت يفحص الملف للحماية من الفيروسات
• يمكنك تشغيل/إيقاف/حذف الملف بالأزرار
🎲 الأدوات العشوائية (/cr):
• صنع ملفات (.txt, .py, .env)
• توليد كلمات مرور قوية
• إنشاء بطاقات فيزا وهمية للاختبار
• سحب قوالب HTML من المواقع
• حاسبة رياضية متقدمة
• إنشاء رموز QR
🤖 الذكاء الاصطناعي (/cmd):
• مساعد AI محلي للأسئلة البرمجية
• مساعد Gemini AI للمحادثات المفتوحة
• قياس سرعة البوت
• تحميل مكتبات Python
👑 للمالك فقط:
• لوحة تحكم الأدمن (/adm)
• إدارة نظام الاشتراك الإجباري (/subscription)
• حظر/فك حظر المستخدمين
• إرسال رسائل جماعية
• إحصائيات المستخدمين
🔒 الأمان:
• فحص الملفات بـ VirusTotal
• منع الأكواد الضارة
• حماية من الفيروسات
⚡ نصائح الاستخدام:
• استخدم /help لعرض جميع الأوامر
• ارفع ملف requirements.txt أولاً إذا كان البوت يحتاج مكتبات خاصة
• ارفع ملفات Python صغيرة للحصول على أفضل أداء
• تأكد من تثبيت المكتبات المطلوبة قبل تشغيل الملفات
🔗 الأوامر المهمة:
/start - بدء البوت
/help - المساعدة
/cr - الأدوات العشوائية
/cmd - لوحة الأوامر المتقدمة
💡 ملاحظة: البوت يدعم العربية والإنجليزية ويوفر واجهة سهلة الاستخدام للجميع.
تم تطوير البوت بواسطة: @P_X_24"""
markup = types.InlineKeyboardMarkup()
back_button = types.InlineKeyboardButton("🔙 الرجوع للقائمة الرئيسية", callback_data='back_to_main')
markup.add(back_button)
bot.send_message(call.message.chat.id, instructions_text, reply_markup=markup)
@bot.callback_query_handler(func=lambda call: call.data == 'add_instructions')
def request_instructions(call):
if str(call.from_user.id) != ADMIN_ID:
bot.send_message(call.message.chat.id, "🚫 ليس لديك صلاحية استخدام هذا الأمر.")
return
bot.send_message(call.message.chat.id, "📝 اكتب التعليمات التي تريد إضافتها:")
bot.register_next_step_handler(call.message, save_instructions)
def save_instructions(message):
global instructions_text
if str(message.from_user.id) != ADMIN_ID:
bot.send_message(message.chat.id, "🚫 ليس لديك صلاحية استخدام هذا الأمر.")
return
instructions_text = message.text.strip()
with open(instructions_file, 'w', encoding='utf-8') as file:
file.write(instructions_text)
bot.send_message(message.chat.id, "✅ تم حفظ التعليمات بنجاح.")
###### داله ارسال رساله لشخص
@bot.callback_query_handler(func=lambda call: call.data == 'send_private_message')
def request_user_id_for_message(call):