-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
689 lines (590 loc) · 28.9 KB
/
app.py
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
import os
if not os.path.isdir('dbs'):
os.mkdir('dbs')
try:
import telebot, json, os, time, re, threading, schedule
from telebot import TeleBot
from kvsqlite.sync import Client as uu
from telebot.types import InlineKeyboardButton as btn, InlineKeyboardMarkup as mk
import asyncio
from apis import *
import time
import datetime
except:
os.system('python3 -m pip install telebot pyrogram tgcrypto kvsqlite pyromod==1.4 schedule')
import telebot, json, os, time, schedule
from telebot import TeleBot
from kvsqlite.sync import Client as uu
from kvsqlite.sync import Client as uu
from telebot.types import InlineKeyboardButton as btn, InlineKeyboardMarkup as mk
import asyncio
import datetime
import requests
pass
from keep_alive import keep_alive
keep_alive()
db = uu('dbs/hameeed.ss', 'rshq')\
print(db)
bot = TeleBot(token="7536129194:AAH7xiyzsadwEKvNXskin3Oo1Yjycq4JNNA")
MAX_MESSAGES_PER_DAY = 1
admin = 6698161283
bk = mk(row_width=1).add(btn('رجوع', callback_data='back'))
with open('messages.json', 'r', encoding='utf-8') as f:
messages = json.load(f)
def extract_freepik_id(url):
match = re.search(r'_(\d+)\.htm', url)
if match:
return match.group(1)
return None
# إذا لم يتم العثور على رقم
stypes = ['member', 'administrator', 'creator']
if not db.get('accounts'):
db.set('accounts', [])
pass
if not db.get("admins"):
db.set('admins', [admin, ])
if not db.get('badguys'):
db.set('badguys', [])
if not db.get('force'):
db.set('force', [])
if not db.get('subscription'):
db.set('subscription', [])
if not db.get('token_table'):
db.set('token_table', [])
def force(channel, userid):
try:
x = bot.get_chat_member(channel, userid)
print(x)
except:
return True
if str(x.status) in stypes:
print(x)
return True
else:
print(x)
return False
def addord():
if not db.get('orders'):
db.set('orders', 1)
return True
else:
d = db.get('orders')
d+=1
db.set('orders', d)
return True
@bot.message_handler(regexp='^/start$')
def start_message(message):
user_id = message.from_user.id
keys = mk(row_width=2)
if user_id in db.get("admins") :
keys_ = mk()
btn01 = btn('🤍الاحصائيات', callback_data='stats')
btn02 = btn("⚠️اذاعة", callback_data='cast')
btn05, btn06 = btn('➖حظر شخص', callback_data='banone'), btn('فك حظر', callback_data='unbanone')
btna = btn('➕تفعيل ViP', callback_data='addsubscription')
btnl = btn('➖الغاء ViP', callback_data='delsubscription')
leave = btn('➖ معرفه المتبقي من الاشتراك ', callback_data='checksubscription')
keys_.add(btn01, btn02)
keys_.add(btn05, btn06)
btn11 = btn('تعيين قنوات الاشتراك', callback_data='setforce')
btn03 = btn('➕اضافة ادمن', callback_data='addadmin')
btn04 = btn('➖مسح ادمن', callback_data='deladmin')
btn012 = btn('⚠️الادمنية ', callback_data='admins')
btn013 = btn(' المشتركين', callback_data='subscription')
btn014 = btn(' التوكن', callback_data='token_function')
btn015 = btn(' التوكن الموجود', callback_data='show_all_tokens')
keys_.add(btn03, btn04)
keys_.add(btn012, btn11)
keys_.add(btna, btnl)
keys_.add(btn013)
keys_.add(leave)
keys_.add(btn014,btn015)
bot.reply_to(message, messages['admin_panel_message'], reply_markup=keys_)
if user_id in db.get('badguys'): return
if not db.get(f'user_{user_id}'):
do = db.get('force')
if do != None:
for channel in do:
x = bot.get_chat_member(chat_id="@"+channel, user_id=user_id)
if str(x.status) in stypes:
pass
else:
channel_button = btn(messages['channel_button_text'], url=f'https://t.me/{channel}')
check_button = btn(messages['check_subscription_button_text'], callback_data='check_subscription')
keyboard = mk().add(channel_button).add(check_button)
bot.reply_to(message, messages['subscribe_channel_message'], reply_markup=keyboard)
return
data = {'id': user_id, 'users': [], 'coins': 0, 'premium': False}
set_user(user_id, data)
good = 0
users = db.keys('user_%')
for ix in users:
try:
d = db.get(ix[0])['id']
good+=1
except: continue
return bot.reply_to(message, messages['welcome_message'])
do = db.get('force')
if do is not None:
for channel in do:
x = bot.get_chat_member(chat_id="@"+channel, user_id=user_id)
if str(x.status) in stypes:
pass
else:
channel_button = btn(messages['channel_button_text'], url=f'https://t.me/{channel}')
check_button = btn(messages['check_subscription_button_text'], callback_data='check_subscription')
keyboard = mk().add(channel_button).add(check_button)
bot.reply_to(message, messages['subscribe_channel_message'], reply_markup=keyboard)
return
return bot.reply_to(message,messages['welcome_message'])
@bot.message_handler(func=lambda message: True)
def handle_message(message):
user_id = message.from_user.id
do = db.get('force')
if do is not None:
for channel in do:
x = bot.get_chat_member(chat_id="@" + channel, user_id=user_id)
if str(x.status) in stypes:
pass
else:
channel_button = btn(messages['channel_button_text'], url=f'https://t.me/{channel}')
check_button = btn(messages['check_subscription_button_text'], callback_data='check_subscription')
keyboard = mk().add(channel_button).add(check_button)
bot.reply_to(message, messages['subscribe_channel_message'], reply_markup=keyboard)
return
# جلب بيانات الاشتراك من القائمة
subscriptions = db.get('subscriptions') or []
sub_data = None
for sub in subscriptions:
if sub['user_id'] == user_id:
sub_data = sub
break
if sub_data:
# تحويل تاريخ انتهاء الاشتراك إلى كائن `datetime.date`
end_date = datetime.datetime.strptime(sub_data["end_date"], "%Y-%m-%d").date()
today = datetime.date.today()
# التحقق مما إذا كان الاشتراك لا يزال نشطًا
if today > end_date:
bot.reply_to(message, messages['subscription_expired_message'])
return
# جلب عدد التحميلات اليومية
user_messages = db.get(f"{user_id}_messages") or {}
messages_today = user_messages.get(str(today), 0)
# التحقق من الحد اليومي
max_downloads = sub_data.get("max_downloads_per_day", MAX_MESSAGES_PER_DAY)
if messages_today >= max_downloads:
bot.reply_to(message, f"🚫 لقد بلغت الحد الأقصى لعدد التحميلات اليومية ({max_downloads}).\n"
f"حاول مرة أخرى غدًا.")
return
# استخراج ID المورد من الرابط
resource_id = extract_freepik_id(message.text)
if resource_id is None:
bot.reply_to(message, messages['invalid_link_message'])
return
# تنزيل المورد
bot.reply_to(message, "📂 يرجى الانتظار... جارٍ تحميل الملف وإرساله.")
if download_resource(resource_id, message, user_id,message.text):
user_messages[str(today)] = messages_today + 1
db.set(f"{user_id}_messages", user_messages)
remaining_downloads = max_downloads - messages_today - 1
bot.reply_to(message, f"📂 ملفك أصبح جاهز ✅ المتبقي لديك لتحميل ({max(0, remaining_downloads)}) لهذا اليوم.")
return
else:
bot.reply_to(message, messages['registration_success_message'])
return
else:
# بدون اشتراك
user_messages = db.get(f"{user_id}_messages") or {}
today = datetime.date.today()
messages_today = user_messages.get(str(today), 0)
# التحقق من الحد اليومي للمستخدمين العاديين
if messages_today >= MAX_MESSAGES_PER_DAY:
tomorrow = today + datetime.timedelta(days=1)
formatted_date = tomorrow.strftime("%d/%m/%Y")
channel_button = btn("اشترك هنا", url=f'https://t.me/freepikprem1')
keyboard = mk().add(channel_button)
bot.reply_to(
message,
f"🚫 نعتذر، لقد بلغت الحد الأقصى لعدد التحميلات اليومية ({MAX_MESSAGES_PER_DAY}).\n"
f"سيتم إعادة ضبط التحميلات في {formatted_date} الساعة 13:31.\n\n"
"للاشتراك والحصول على المزيد من التحميلات، يمكنك الضغط هنا.",
parse_mode="HTML", reply_markup=keyboard
)
channel_button = btn("قم بإرسال صورة الإيداع إلى هنا", url=f'https://t.me/eitabbbb')
keyboard = mk().add(channel_button)
message_text = """
<blockquote> الدفع عبر مصرف الكريمي </blockquote>
👤 باسم: عصماء علي
💳 الحسابات المتاحة:
- حساب يمني: <b><code>3066613975</code></b>
- حساب سعودي: <b><code>3073514826</code></b>
- حساب دولار: <b><code>3120895458</code></b>
📤 بعد الإيداع:
قم بإرسال صورة الإيداع إلى ⇇ @eitabbbb
"""
bot.reply_to(message, message_text, parse_mode="HTML",reply_markup=keyboard)
return
# استخراج ID المورد من الرابط
resource_id = extract_freepik_id(message.text)
if resource_id is None:
bot.reply_to(message, messages['invalid_link_message'])
return
# تنزيل المورد
bot.reply_to(message, "📂 يرجى الانتظار... جارٍ تحميل الملف وإرساله.")
if download_resource(resource_id, message, user_id,message.text):
user_messages[str(today)] = messages_today + 1
db.set(f"{user_id}_messages", user_messages)
remaining_downloads = MAX_MESSAGES_PER_DAY - messages_today - 1
bot.reply_to(message, f"📂 ملفك أصبح جاهز ✅ المتبقي لديك لتحميل ({max(0, remaining_downloads)}) لهذا اليوم.")
return
else:
bot.reply_to(message, messages['registration_success_message'])
return
def download_resource(resource_id, message_id, user_id,link):
token_data = db.get('token_table')
tokens_string = ", ".join(map(str, token_data))
url = f"https://api.freepik.com/v1/resources/{resource_id}/download"
headers = {"x-freepik-api-key": tokens_string}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
data_dict = json.loads(response.text)
info = data_dict.get('data', {})
filename = info.get('filename')
file_url = info.get('url')
if not filename or not file_url:
print("❌ فشل في جلب بيانات الملف.")
return False
print(f"🔗 رابط الملف: {file_url}")
file_response = requests.get(file_url, stream=True)
file_response.raise_for_status()
with open(filename, "wb") as file:
for chunk in file_response.iter_content(1024):
file.write(chunk)
print(f"✅ تم تحميل الملف: {filename}")
with open(filename, "rb") as file:
bot.send_document(user_id, file,caption="هذا هو الملف المطلوب")
print(f"📤 تم إرسال الملف إلى المستخدم {user_id}")
os.remove(filename)
return True
except requests.exceptions.RequestException as e:
print(f"❌ خطأ أثناء التحميل: {e}")
return False
except Exception as e:
print(f"⚠️ خطأ غير متوقع: {e}")
return False
@bot.callback_query_handler(func=lambda c: True)
def c_rs(call):
user_id = call.from_user.id
cid, data, mid = call.from_user.id, call.data, call.message.id
count_ord = db.get('orders') if db.get('orders') else 1
if data == 'deladmin':
type = 'delete'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو المراد ازالته من الادمن',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, adminss, type)
if data == 'addadmin':
type = 'add'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو المراد اضافته ادمن بالبوت ',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, adminss, type)
if data == 'token_function':
type = 'add'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو المراد اضافته ادمن بالبوت ',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, token_function, type)
if data == 'delsubscription':
type = 'delete'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو المراد ازالته من اشتراك',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, subscription, type)
if data == 'addsubscription':
type = 'add'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو المراد اضافته اشتراك بالبوت ',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, subscription, type)
if data == 'checksubscription':
type = 'check'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو المراد معرفه اشتراك بالبوت ',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, subscription, type)
if data == 'show_all_tokens':
token_data = db.get('token_table') # جلب جميع التوكنات
if not token_data or token_data == []:
bot.edit_message_text(chat_id=cid, message_id=mid, text=txt)
return
else:
bot.edit_message_text(chat_id=cid, message_id=mid, text=token_data)
return
# تنسيق القائمة
if data == 'admins':
get_admins = db.get('admins')
if get_admins:
if len(get_admins) >=1:
txt = 'الادمنية : \n'
for ran, admin in enumerate(get_admins, 1):
try:
info = bot.get_chat(admin)
username = f'{ran} @'+str(info.username)+' | {admin}\n' if info.username else f'{ran} {admin} .\n'
txt+=username
except:
txt+=f'{ran} {admin}\n'
bot.edit_message_text(chat_id=cid, message_id=mid, text=txt)
return
else:
bot.edit_message_text(chat_id=cid, message_id=mid, text=f'لا يوجد ادمنية بالبوت')
return
else:
bot.edit_message_text(chat_id=cid, message_id=mid, text='لا يوجد ادمنية بالبوت')
return
if data == 'subscription':
# جلب قائمة المشتركين من قاعدة البيانات
subscriptions = db.get('subscriptions') or []
if not subscriptions:
bot.edit_message_text(chat_id=cid, message_id=mid, text="لا يوجد مشتركين بالبوت.")
return
# إعداد النص الذي سيعرض جميع المشتركين
txt = "المشتركين:\n"
today = datetime.date.today()
for idx, sub in enumerate(subscriptions, 1):
user_id = sub['user_id']
end_date = sub['end_date']
max_downloads = sub.get("max_downloads_per_day", "غير محدد")
try:
# محاولة الحصول على معلومات المستخدم (اسم المستخدم أو الاسم الأول)
user_info = bot.get_chat(user_id)
username = f"@{user_info.username}" if user_info.username else user_info.first_name
except:
username = f"ID: {user_id}"
# جلب عدد التحميلات اليومية
user_messages = db.get(f"{user_id}_messages") or {}
messages_today = user_messages.get(str(today), 0)
remaining_downloads = max_downloads - messages_today if max_downloads != "غير محدد" else "غير محدد"
txt += f"{idx}. {username} - حتى {end_date} (عدد التحميلات اليومية: {max_downloads}, المتبقي: {remaining_downloads})\n"
# عرض النص النهائي
bot.edit_message_text(chat_id=cid, message_id=mid, text=txt)
if data == 'check_subscription':
do = db.get('force')
if do is not None:
for channel in do:
x = bot.get_chat_member(chat_id="@" + channel, user_id=user_id)
if str(x.status) not in stypes:
bot.answer_callback_query(call.id, '❌ لا تزال غير مشترك، يرجى الاشتراك ثم إعادة المحاولة.')
return
bot.answer_callback_query(call.id, '✅ تم التحقق من اشتراكك بنجاح!')
bot.edit_message_text(' اهلاً بك في بوت التحميل من Freepik يرجى إرسال رابط الملف لتحميل✅ تم التحقق من اشتراكك، يمكنك الآن استخدام البوت.', chat_id=cid, message_id=mid)
if data == 'banone':
if cid in db.get("admins") :
type = 'ban'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو لمراد حظرة من استخدام البوت',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, banned, type)
if data == 'unbanone':
if cid in db.get("admins") :
type = 'unban'
x = bot.edit_message_text(text=f'• ارسل ايدي العضو المراد الغاء حظره من استخدام البوت ',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, banned, type)
if data == 'cast':
if cid in db.get("admins") :
x = bot.edit_message_text(text=f'ارسل الاذاعة لتريد ترسلها... صورة، فيد، ملصق، نص، متحركة ..',chat_id=cid, message_id=mid)
bot.register_next_step_handler(x, casting)
if data == 'stats':
good = 0
users = db.keys('user_%')
for ix in users:
try:
d = db.get(ix[0])['id']
good+=1
except: continue
bot.edit_message_text(text=f'• عدد اعضاء البوت : {good}', chat_id=cid, message_id=mid)
return
if data == 'setforce':
x = bot.edit_message_text(text='• قم بارسال معرفات القنوات هكذا \n@uf3_8 @uf3_8',reply_markup=bk,chat_id=cid,message_id=mid)
bot.register_next_step_handler(x, setfo)
def set_user(id, data):
db.set(f'user_{id}', data)
return True
def setfo(message):
if "@" not in message.text:
bot.reply_to(message, f'• رجاء ارسل القناة بشكل صحيح')
return
elif message.text == "/start":
start_message(message)
return
users = message.text.replace('https://t.me/', '').replace('@', '').split(' ')
db.set('force', users)
bot.reply_to(message, 'تمت بنجاح')
return
def banned(message, type):
admins = db.get('admins')
if type == 'ban':
try:
id = int(message.text)
except:
bot.reply_to(message, f'ارسل الايدي بشكل صحيح')
return
d = db.get('badguys')
if id in d:
bot.reply_to(message, f'• هذا العضو محظور من قبل ')
return
else:
d.append(id)
db.set('badguys', d)
bot.reply_to(message, f'• تم حظر العضو من استخدام البوت')
return
if type == 'unban':
try:
id = int(message.text)
except:
bot.reply_to(message, f'• ارسل الايدي بشكل صحيح')
return
d = db.get('badguys')
if id not in d:
bot.reply_to(message, f'• هذا العضو غير محظور ')
return
else:
d.remove(id)
db.set('badguys', d)
bot.reply_to(message, f'• تم الغاء حظر العضو بنجاح ✅')
return
def subscription(message, action):
try:
user_id = int(message.text)
except ValueError:
bot.reply_to(message, "⚠️ يرجى إرسال **ID** المستخدم بشكل صحيح!")
return
if action == 'add':
# طلب عدد الأيام من المسؤول
msg = bot.reply_to(message, "يرجى إدخال عدد الأيام للاشتراك:")
bot.register_next_step_handler(msg, process_days, user_id)
elif action == 'delete':
subscriptions = db.get('subscriptions') or []
found = False
# البحث عن المستخدم وإزالته من القائمة
for sub in subscriptions:
if sub['user_id'] == user_id:
subscriptions.remove(sub)
found = True
break
if found:
db.set('subscriptions', subscriptions)
bot.reply_to(message, f"❌ تم إلغاء اشتراك المستخدم **{user_id}** بنجاح.")
bot.send_message('@freepikprem3', f"❌ تم إلغاء اشتراك المستخدم **{user_id}** بنجاح.")
else:
bot.reply_to(message, f"⚠️ لا يوجد اشتراك لهذا المستخدم.")
elif action == 'check':
subscriptions = db.get('subscriptions') or []
found = False
# البحث عن بيانات الاشتراك للمستخدم
for sub in subscriptions:
if sub['user_id'] == user_id:
max_downloads = sub.get("max_downloads_per_day", "غير محدد")
bot.reply_to(message, f"📅 اشتراك المستخدم **{user_id}** نشط حتى {sub['end_date']}.\n"
f"عدد التحميلات اليومية: {max_downloads}.")
found = True
break
if not found:
bot.reply_to(message, f"⏳ لا يوجد اشتراك نشط لهذا المستخدم.")
def process_days(message, user_id):
try:
days = int(message.text)
if days <= 0:
raise ValueError
except ValueError:
bot.reply_to(message, "⚠️ يرجى إدخال عدد صحيح أكبر من صفر!")
return
# تحديد تاريخ البداية والنهاية بناءً على عدد الأيام
start_date = datetime.date.today()
end_date = start_date + datetime.timedelta(days=days)
# طلب عدد التحميلات اليومية من المسؤول
msg = bot.reply_to(message, "يرجى إدخال عدد التحميلات اليومية لهذا المشترك:")
bot.register_next_step_handler(msg, process_max_downloads, user_id, start_date, end_date)
def process_max_downloads(message, user_id, start_date, end_date):
try:
max_downloads = int(message.text)
if max_downloads <= 0:
raise ValueError
except ValueError:
bot.reply_to(message, "⚠️ يرجى إدخال عدد صحيح أكبر من صفر!")
return
# جلب قائمة المشتركين الحالية أو إنشاء قائمة جديدة إذا كانت فارغة
subscriptions = db.get('subscriptions') or []
# إضافة بيانات الاشتراك الجديدة إلى القائمة
subscriptions.append({
"user_id": user_id,
"start_date": start_date.isoformat(),
"end_date": end_date.isoformat(),
"max_downloads_per_day": max_downloads
})
# حفظ القائمة المحدثة في قاعدة البيانات
db.set('subscriptions', subscriptions)
bot.reply_to(message, f"✅ تم تفعيل الاشتراك للمستخدم **{user_id}** حتى {end_date}.\n"
f"عدد التحميلات اليومية: {max_downloads}.")
try:
bot.send_message('@freepikprem3', f"✅ تم تفعيل الاشتراك للمستخدم **{user_id}** حتى {end_date}.\n"
f"عدد التحميلات اليومية: {max_downloads}.")
bot.send_message(user_id, f"🎉 تهانينا! تم تفعيل اشتراكك حتى {end_date}.\n"
f"يمكنك الآن تحميل {max_downloads} ملفات يوميًا. ✅")
except Exception as e:
print(f"⚠️ فشل إرسال الرسالة للمستخدم {user_id}: {e}")
def adminss(message, type):
admins = db.get('admins')
if type == 'add':
try:
id = int(message.text)
except:
bot.reply_to(message, f'• ارسل الايدي بشكل صحيح')
return
d = db.get('admins')
if id in d:
bot.reply_to(message, f'• هذا العضو ادمن بالفعل')
return
else:
d.append(id)
db.set('admins', d)
bot.reply_to(message, f'• تم اضافته بنجاح ✅')
return
if type == 'delete':
try:
id = int(message.text)
except:
bot.reply_to(message, f'• ارسل الايدي بشكل صحيح')
return
d = db.get('admins')
if id not in d:
bot.reply_to(message, f'• هذا العضو ليس من الادمنية بالبوت')
return
else:
d.remove(id)
db.set('admins', d)
bot.reply_to(message, f'• تم اذالة العضو من الادمنية بنجاح ✅')
return
def token_function(message, type):
user_id = message.text # السماح بأي نص وإزالة المسافات الزائدة
if type == 'add':
db.set('token_table', [user_id]) # استبدال التوكن الحالي بالتوكن الجديد
bot.reply_to(message, f'• تم تعيين التوكن الجديد بنجاح ✅\n• التوكن: {user_id}')
elif type == 'delete':
token_data = db.get('token_table') or [] # جلب التوكن الحالي
if user_id not in token_data:
bot.reply_to(message, '• هذا التوكن غير موجود')
else:
db.set('token_table', []) # إزالة التوكن
bot.reply_to(message, '• تم ازالة التوكن بنجاح ✅')
def casting(message):
if message.text == "/start":
start_message(message)
return
admins = db.get('admins')
idm = message.message_id
d = db.keys('user_%')
good = 0
bad = 0
bot.reply_to(message, f'• جاري الاذاعة الي مستخدمين البوت الخاص بك ')
for user in d:
try:
id = db.get(user[0])['id']
bot.copy_message(chat_id=id, from_chat_id=message.from_user.id, message_id=idm)
good+=1
except:
bad+=1
continue
bot.reply_to(message, f'• اكتملت الاذاعة بنجاح ✅\n• تم ارسال الى : {good}\n• لم يتم ارسال الي : {bad} ')
return
try:
bot.infinity_polling()
except:
pass