-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
748 lines (616 loc) · 31.2 KB
/
main.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
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
# Developed By MrAmini
from telethon import TelegramClient, events, functions, types
import asyncio
import random
import os
import json
import re
import httpx
import sys
import subprocess
# Configuration
API_ID = 'AminiMokhberAPIID' # Replace with your API ID
API_HASH = 'AminiMokhberAPIHASH' # Replace with your API hash
BOT_OWNER_ID = AminiMokhberADMINID # Replace with the bot owner's Telegram user ID
USERS_FILE = 'user.txt'
MESSAGE_FILE = 'pm.txt'
BIO_API_URL = 'https://api.codebazan.ir/bio'
SETTINGS_FILE = 'settings.json'
ACCOUNTS_FILE = 'accounts.json'
REBOOT_FLAG_FILE = "reboot_flag.txt"
default_settings = {
'save_user': True,
'chat_user': False,
'random_bio': False,
'filter_last_seen': False,
'remove_invalid_users': False,
'daily_limit': 10,
'auto_join': False
}
def save_user_to_file(user_id):
try:
user_id_str = str(user_id).strip() # اطمینان از ذخیره به صورت رشته
with open("user.txt", "a", encoding="utf-8") as file:
file.write(user_id_str + "\n") # ذخیره آیدی به صورت رشته در فایل
except Exception as e:
print(f"خطا در ذخیره کردن کاربر به فایل: {e}")
def remove_user_from_file(user_id):
try:
user_id_str = str(user_id).strip() # اطمینان از تبدیل به رشته و حذف فاصلههای اضافی
with open("user.txt", "r", encoding="utf-8") as file:
lines = file.readlines()
# حذف تمامی خطوطی که آیدی آنها برابر با user_id_str است
new_lines = [line for line in lines if line.strip() != user_id_str]
with open("user.txt", "w", encoding="utf-8") as file:
file.writelines(new_lines)
except Exception as e:
print(f"خطا در حذف کاربر از فایل: {e}")
def load_users():
try:
with open(USERS_FILE, "r", encoding="utf-8") as f:
return {int(line.strip()) for line in f if line.strip().isdigit()}
except FileNotFoundError:
return set()
forward_mode = False
forward_message = None
sent_count = 0
def load_accounts():
if os.path.exists("accounts.json"):
with open("accounts.json", "r", encoding="utf-8") as f:
try:
data = json.load(f)
if isinstance(data, dict):
return data
else:
return {}
except json.JSONDecodeError:
return {}
return {}
def save_accounts(accounts):
with open(ACCOUNTS_FILE, 'w') as f:
json.dump(accounts, f)
def load_settings():
if os.path.exists(SETTINGS_FILE):
try:
with open(SETTINGS_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except json.JSONDecodeError:
return {}
return {}
def save_settings(settings):
with open(SETTINGS_FILE, 'w') as f:
json.dump(settings, f)
client = TelegramClient('session', API_ID, API_HASH).start()
settings = load_settings()
def remove_user_from_file(user_id):
try:
with open("user.txt", "r", encoding="utf-8") as file:
users = file.readlines()
with open("user.txt", "w", encoding="utf-8") as file:
for user in users:
if user.strip() != str(user_id):
file.write(user)
except Exception as e:
print(f"خطا در حذف کاربر از فایل: {e}")
def save_user(user_id):
if not os.path.exists(USERS_FILE):
open(USERS_FILE, 'w').close()
with open(USERS_FILE, 'r') as f:
users = set(f.read().splitlines())
if str(user_id) not in users:
with open(USERS_FILE, 'a') as f:
f.write(f"{user_id}\n")
print(f"User {user_id} saved successfully.")
else:
print(f"User {user_id} already exists.")
async def set_new_pm(event):
try:
text = event.raw_text
if not text.lower().startswith("setnewpm"):
await event.reply("⚠️ دستور نامعتبر است. لطفاً پیام خود را به درستی وارد کنید.")
return
parts = text.split("\n", 1)
if len(parts) < 2:
await event.reply("⚠️ لطفاً پیام جدید خود را بعد از `setnewpm` در خط جدید وارد کنید.")
return
new_message = parts[1].strip()
with open("pm.txt", "w", encoding="utf-8") as f:
f.write(new_message)
await event.reply("✅ پیام جدید با موفقیت ذخیره شد.")
except Exception as e:
await event.reply(f"⚠️ خطا در ذخیره پیام: {e}")
async def update_bio():
try:
async with httpx.AsyncClient(follow_redirects=True) as req:
response = await req.get(BIO_API_URL, timeout=5)
if response.status_code == 200:
bio = response.text.strip()
else:
raise Exception(f"API request failed with status {response.status_code}")
except Exception as e:
try:
with open("bio.json", "r", encoding="utf-8") as file:
data = json.load(file)
bios = data.get("bio", [])
if not bios:
return "بیو برای ست شدن یافت نشد."
bio = random.choice(bios)
except (FileNotFoundError, json.JSONDecodeError) as file_error:
return f"Error: {file_error}"
try:
await client(functions.account.UpdateProfileRequest(about=bio))
return f"**📩 بیوگرافی ست شده:**\n {bio}"
except Exception as e:
return f"Error updating bio: {e}"
async def get_last_seen(user_id):
try:
user = await client.get_entity(user_id)
if hasattr(user.status, 'was_online'):
return user.status.was_online
except Exception as e:
print(f"Error getting last seen for {user_id}: {e}")
return None
async def check_ban():
try:
await client.send_message(BOT_OWNER_ID, "Checking ban status...")
return "ربات فعال است."
except:
return "⚠️ ربات بن شده و قادر به ارسال پیام نیست."
async def join_group_from_message(event):
if not settings.get('auto_join', False):
return
message_text = event.raw_text.strip()
if "t.me/" not in message_text:
return
if "joinchat" in message_text or "t.me/+" in message_text:
private_link_pattern = r"https?:\/\/t\.me\/(?:joinchat\/|\+)?([a-zA-Z0-9_-]+)"
private_match = re.search(private_link_pattern, message_text)
if private_match:
group_identifier = private_match.group(1)
try:
await client(functions.messages.ImportChatInviteRequest(group_identifier))
await client.send_message("me", "✅ به گروه خصوصی پیوستم!")
except Exception as e:
await client.send_message("me", f"❌ خطا در پیوستن به گروه: {str(e)}")
else:
group_link_pattern = r"(https?:\/\/t\.me\/(?:joinchat\/)?([a-zA-Z0-9_-]+))"
match = re.search(group_link_pattern, message_text)
if match:
group_identifier = match.group(2)
try:
await client(functions.channels.JoinChannelRequest(group_identifier))
await client.send_message("me", "✅ به گروه عمومی پیوستم!")
except Exception as e:
await client.send_message("me", f"❌ خطا در پیوستن به گروه: {str(e)}")
@client.on(events.NewMessage)
async def message_handler(event):
sender_id = event.sender_id
message = event.raw_text.lower()
await join_group_from_message(event)
async def send_messages():
if os.path.exists(USERS_FILE) and os.path.exists(MESSAGE_FILE):
with open(USERS_FILE, 'r', encoding='utf-8') as f:
users = f.read().splitlines()
with open(MESSAGE_FILE, 'r', encoding='utf-8') as f:
message_content = f.read()
active_accounts = [phone for phone, data in load_accounts().items() if data["status"] == "active"]
if not active_accounts:
return "⛔ هیچ اکانت فعالی برای ارسال پیام وجود ندارد."
total_accounts = len(active_accounts)
limit_per_account = settings['daily_limit'] // total_accounts if settings['daily_limit'] > 0 else len(users) // total_accounts
sent_count = 0
failed_count = 0
removed_users = 0
for index, user in enumerate(users):
if settings['daily_limit'] > 0 and sent_count >= settings['daily_limit']:
break
current_account = active_accounts[index % total_accounts]
client = TelegramClient(f'session_{current_account}', API_ID, API_HASH)
await client.connect()
try:
await client.send_message(int(user), message_content)
sent_count += 1
await asyncio.sleep(random.randint(1, 5))
except Exception as e:
failed_count += 1
if settings['remove_invalid_users'] and 'deleted/deactivated' in str(e).lower():
users.remove(user)
removed_users += 1
with open(USERS_FILE, 'w', encoding='utf-8') as f:
f.writelines("\n".join(users))
return f"📊 گزارش ارسال پیام:\n✅ ارسال موفق: {sent_count}\n❌ ارسال ناموفق: {failed_count}\n🚫 حذف کاربران غیرفعال: {removed_users}"
return "فایلهای مورد نیاز وجود ندارند."
@client.on(events.NewMessage(pattern="^forwardpm$", from_users=BOT_OWNER_ID))
async def enable_forward_mode(event):
global forward_mode, forward_message
forward_mode = True
forward_message = None
await event.reply("📩 لطفاً پیام موردنظر را به ربات فروارد کنید.")
@client.on(events.NewMessage(forwards=True, from_users=BOT_OWNER_ID))
async def receive_forward(event):
global forward_mode, forward_message
if forward_mode:
forward_message = event.message
forward_mode = False
user_list = load_users()
settings = load_settings()
daily_limit = settings.get("daily_limit")
if daily_limit is None:
await event.reply("⚠️ مقدار محدودیت روزانه تعریف نشده است! لطفاً مقدار `daily_limit` را در تنظیمات تعیین کنید و دوباره امتحان نمایید.")
return
if not user_list:
await event.reply("⚠️ لیست کاربران خالی است.")
return
await event.reply(f"✅ پیام دریافت شد! شروع ارسال به {min(len(user_list), daily_limit)} کاربر.")
failed_users = []
for user_id in list(user_list)[:daily_limit]:
try:
await client.forward_messages(user_id, forward_message)
await asyncio.sleep(random.randint(5, 60))
except Exception:
failed_users.append(user_id)
if failed_users:
failed_report = "\n".join(str(uid) for uid in failed_users)
await event.reply(f"⚠️ ارسال پیام به کاربران زیر ناموفق بود:\n{failed_report}")
else:
await event.reply("✅ ارسال پیام به همه کاربران انجام شد.")
@client.on(events.NewMessage(pattern=r'^addacc (\+\d+)$'))
async def add_account(event):
sender_id = event.sender_id
phone_number = event.pattern_match.group(1)
if sender_id != BOT_OWNER_ID:
return
accounts = load_accounts()
if phone_number in accounts:
return await event.reply("⚠️ این شماره قبلاً اضافه شده است.")
accounts[phone_number] = {"status": "pending"}
save_accounts(accounts)
new_client = TelegramClient(f'session_{phone_number}', API_ID, API_HASH)
await new_client.connect()
try:
sent_code = await new_client.send_code_request(phone_number)
accounts[phone_number]["hash"] = sent_code.phone_code_hash
save_accounts(accounts)
await event.reply(f"📩 کد تأیید به شماره {phone_number} ارسال شد.\n لطفاً کد را با دستور `verifyacc {phone_number} 12345` وارد کنید.\n اکانت نباید دارای ورود دو مرحله ای باشد.")
except Exception as e:
await event.reply(f"⚠️ خطا در ارسال کد: {e}")
@client.on(events.NewMessage(pattern=r'^verifyacc (\+\d+) (\d+)$'))
async def verify_account(event):
sender_id = event.sender_id
phone_number = event.pattern_match.group(1)
code = event.pattern_match.group(2)
if sender_id != BOT_OWNER_ID:
return
accounts = load_accounts()
if phone_number not in accounts or "hash" not in accounts[phone_number]:
return await event.reply("⚠️ شماره معتبر نیست یا هنوز کد ارسال نشده است.")
new_client = TelegramClient(f'session_{phone_number}', API_ID, API_HASH)
await new_client.connect()
try:
await new_client.sign_in(phone_number, code, phone_code_hash=accounts[phone_number]["hash"])
accounts[phone_number]["status"] = "active"
save_accounts(accounts)
await event.reply(f"✅ شماره {phone_number} با موفقیت اضافه شد.")
except Exception as e:
await event.reply(f"⚠️ خطا در تأیید کد: {e}")
@client.on(events.NewMessage(pattern=r'^accs$'))
async def list_accounts(event):
sender_id = event.sender_id
if sender_id != BOT_OWNER_ID:
return
accounts = load_accounts()
if not accounts:
return await event.reply("⚠️ هیچ اکانتی ثبت نشده است.")
msg = "**📋 لیست اکانتها:**\n"
for phone, data in accounts.items():
status = "✅ فعال" if data["status"] == "active" else "⏳ در انتظار تأیید"
msg += f"- {phone}: {status}\n"
await event.reply(msg)
@client.on(events.NewMessage(pattern=r'^delacc (\+\d+)$'))
async def delete_account(event):
sender_id = event.sender_id
phone_number = event.pattern_match.group(1)
if sender_id != BOT_OWNER_ID:
return
accounts = load_accounts()
if phone_number not in accounts:
return await event.reply("⚠️ این شماره در لیست نیست.")
del accounts[phone_number]
save_accounts(accounts)
os.remove(f'session_{phone_number}.session')
await event.reply(f"✅ اکانت {phone_number} با موفقیت حذف شد.")
@client.on(events.NewMessage(pattern=r'^accstatus (\+\d+)$'))
async def account_status(event):
sender_id = event.sender_id
phone_number = event.pattern_match.group(1)
if sender_id != BOT_OWNER_ID:
return
accounts = load_accounts()
if phone_number not in accounts:
return await event.reply("⚠️ این شماره در لیست نیست.")
session_file = f'session_{phone_number}'
if not os.path.exists(f"{session_file}.session"):
return await event.reply("⚠️ اکانت موردنظر در حال حاضر وارد نشده است.")
new_client = TelegramClient(session_file, API_ID, API_HASH)
await new_client.connect()
if not await new_client.is_user_authorized():
await new_client.disconnect()
return await event.reply("⚠️ این اکانت لاگین نشده است.")
user = await new_client.get_me()
last_online = "نامشخص" if not user.status else str(user.status)
dialogs = await new_client.get_dialogs()
total_messages = sum(len(await new_client.get_messages(dialog.entity, limit=100)) for dialog in dialogs if dialog.is_user)
await new_client.disconnect()
status_message = (
f"📌 **وضعیت اکانت {phone_number}:**\n"
f"👤 **نام کاربری:** {user.username or 'ندارد'}\n"
f"🆔 **ایدی عددی:** {user.id}\n"
f"✅ **وضعیت ورود:** فعال\n"
f"🕒 **آخرین فعالیت:** {last_online}\n"
f"✉️ **تعداد پیامهای ارسالشده:** {total_messages}\n"
)
await event.reply(status_message)
@client.on(events.NewMessage)
async def message_handler(event):
sender_id = event.sender_id
message = event.raw_text.lower()
if settings['chat_user'] and event.is_group:
save_user(sender_id)
if sender_id == BOT_OWNER_ID:
if message == 'bot':
await event.reply("سلام، آنلاینم! کارت رو بگو.")
elif message == 'onlastseen':
settings['last_seen_filter'] = True
save_settings(settings)
await event.reply("فیلتر آخرین بازدید فعال شد.")
elif message == 'offlastseen':
settings['filter_last_seen'] = False
save_settings(settings)
await event.reply("فیلتر آخرین بازدید غیرفعال شد.")
elif message == 'invaliduseron':
settings['remove_invalid_users'] = True
save_settings(settings)
await event.reply("حذف کاربران نامعتبر فعال شد.")
elif message == 'invaliduseroff':
settings['remove_invalid_users'] = False
save_settings(settings)
await event.reply("حذف کاربران نامعتبر غیرفعال شد.")
elif message.startswith('setlimit'):
try:
limit = int(message.split()[1])
settings['daily_limit'] = limit
save_settings(settings)
await event.reply(f"حد ارسال روزانه روی {limit} پیام تنظیم شد.")
except:
await event.reply("فرمت اشتباه است. استفاده صحیح: setlimit 50")
elif message == 'sendreport':
report = await send_messages()
await event.reply(report)
elif message == 'checkban':
status = await check_ban()
await event.reply(status)
elif message == 'saveuseron':
settings['save_user'] = True
save_settings(settings)
await event.reply("ذخیره کاربران گروه فعال شد.")
elif message == 'saveuseroff':
settings['save_user'] = False
save_settings(settings)
await event.reply("ذخیره کاربران گروه غیرفعال شد.")
elif message == 'chatuseron':
settings['chat_user'] = True
save_settings(settings)
await event.reply("ذخیره کاربران ارسالکننده پیام در گروهها فعال شد.")
elif message == 'chatuseroff':
settings['chat_user'] = False
save_settings(settings)
await event.reply("ذخیره کاربران ارسالکننده پیام در گروهها غیرفعال شد.")
elif message == 'bioon':
settings['random_bio'] = True
save_settings(settings)
result = await update_bio()
await event.reply(result)
elif message == 'biooff':
settings['random_bio'] = False
save_settings(settings)
await event.reply("بیوگرافی تصادفی غیرفعال شد.")
elif message == 'autojoinon':
settings['auto_join'] = True
save_settings(settings)
await event.reply("✅ ورود خودکار به گروهها *فعال* شد.")
elif message == 'autojoinoff':
settings['auto_join'] = False
save_settings(settings)
await event.reply("❌ ورود خودکار به گروهها *غیرفعال* شد.")
elif message.lower().startswith("setnewpm"):
parts = message.split("\n", 1)
if len(parts) < 2:
await event.reply("⚠️ لطفاً پیام جدید خود را در خط جدید بعد از `setnewpm` بنویسید.")
return
new_message = parts[1].strip()
with open("pm.txt", "w", encoding="utf-8") as f:
f.write(new_message)
await event.reply("✅ پیام جدید با موفقیت ذخیره شد.")
print("New message saved successfully.")
elif message == 'sendpm':
if os.path.exists(USERS_FILE) and os.path.exists(MESSAGE_FILE):
with open(USERS_FILE, 'r', encoding='utf-8') as f:
users = f.read().splitlines()
with open(MESSAGE_FILE, 'r', encoding='utf-8') as f:
message_content = f.read()
for user in users:
try:
await client.send_message(int(user), message_content)
remove_user_from_file(user_id)
await asyncio.sleep(random.randint(1, 10))
except Exception as e:
print(f"Error sending message to {user}: {e}")
await event.reply("پیامها با موفقیت ارسال شدند.")
else:
await event.reply("فایلهای مورد نیاز وجود ندارند.")
elif message == 'info':
# Gathering bot's status information
total_users = 0
if os.path.exists(USERS_FILE):
with open(USERS_FILE, 'r') as f:
total_users = len(f.read().splitlines())
# Generate info text
info_text = (
f"وضعیت ربات: {'آنلاین' if client.is_connected else 'آفلاین'}\n"
f"تعداد کاربران جمع شده: {total_users}\n"
f"جمعآوری لیست اعضای گروه: {'فعال' if settings['save_user'] else 'غیرفعال'}\n"
f"جمعآوری یوزرهای درحال چت: {'فعال' if settings['chat_user'] else 'غیرفعال'}\n"
f"بیوگرافی تصادفی: {'فعال' if settings['random_bio'] else 'غیرفعال'}\n"
)
await event.reply(info_text)
elif message == 'help':
help_text = (
"📌 **راهنمای دستورات ربات**\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"نسخه ربات: V 3.4.0\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"🤖 **وضعیت ربات:**\n"
"🔹 `bot` - بررسی آنلاین بودن ربات\n"
"🔹 `info` - نمایش اطلاعات کلی ربات\n"
"🔹 `checkban` - بررسی مسدود شدن ربات\n"
"🔹 `ping` - بررسی پینگ و سرعت ربات\n"
"🔹 `setmode` - خاموش و روشن کردن ربات\n"
"🔹 example: setmode online"
"━━━━━━━━━━━━━━━━━━━━\n"
"📩 **ارسال پیامها:**\n"
"📌 `sendpm` - ارسال پیام به تمام کاربران ذخیرهشده\n"
"📌 `forwardpm` - فروارد پیام به همه کاربران ذخیره شده\n"
"📌 `setnewpm` - تغییر متن پیام تبلیغاتی (متن رو در خط بعدی بنویسید)\n"
"📌 `sendreport` - دریافت گزارش ارسال پیامها\n"
"📌 `setlimit 10` - تنظیم محدودیت ارسال روزانه (عدد قابل تغییر است)\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"👥 **مدیریت کاربران:**\n"
"🟢 `saveuseron` - فعالسازی ذخیره کاربران گروهها\n"
"🔴 `saveuseroff` - غیرفعالسازی ذخیره کاربران گروهها\n"
"🟢 `chatuseron` - فعالسازی ذخیره کاربران پیامدهنده در گروهها\n"
"🔴 `chatuseroff` - غیرفعالسازی ذخیره کاربران پیامدهنده در گروهها\n"
"🟢 `InvalidUserOn` - حذف خودکار کاربران نامعتبر\n"
"🔴 `InvalidUserOff` - غیرفعالسازی حذف کاربران نامعتبر\n"
"🟢 `cleanlist` - حذف کاربران ذخیره شده\n"
"🔴 `clearpm` - حذف پیام های ارسال شده\n"
"🟢 `deluser` - حذف کاربر خاصی از لیست ارسال\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"🔧 **تنظیمات و قابلیتها:**\n"
"🔹 `bioon` - فعالسازی بیوگرافی تصادفی\n"
"🔹 `biooff` - غیرفعالسازی بیوگرافی تصادفی\n"
"🔹 `OnLastseen` - ارسال پیام فقط به کاربران فعال در ۲۴ ساعت اخیر\n"
"🔹 `OffLastseen` - ارسال پیام به تمام کاربران ذخیرهشده\n"
"🔹 `autojoinon` - فعالسازی ورود خودکار به گروهها از طریق لینک\n"
"🔹 `autojoinoff` - غیرفعالسازی ورود خودکار به گروهها\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"📱 **مدیریت اکانت ها**\n"
"📍 `addacc` - افزودن اکانت\n"
"📍 example: addacc +989191234567\n"
"📍 `verifyacc` - وارد کردن کد لاگین\n"
"📍 example: verifyacc +989191234567 12345\n"
"📍 `delacc` - حذف یک اکانت\n"
"📍 example: delacc +989191234567\n"
"📍 `accstatus` - بررسی اطلاعات اکانت\n"
"📍 example: accstatus +989191234567\n"
"📍 `accs` - دریافت لیست اکانت ها\n"
"━━━━━━━━━━━━━━━━━━━━\n"
"❓ **راهنما:**\n"
"📌 `help` - نمایش لیست دستورات\n"
)
await event.reply(help_text, parse_mode='markdown')
@client.on(events.NewMessage(pattern=r'^cleanlist$'))
async def clean_list(event):
sender_id = event.sender_id
if sender_id != BOT_OWNER_ID:
return
open("user.txt", "w").close()
await event.reply("✅ لیست کاربران با موفقیت پاک شد.")
@client.on(events.NewMessage(pattern=r'^clearpm$'))
async def clear_pm(event):
sender_id = event.sender_id
if sender_id != BOT_OWNER_ID:
return
try:
clear_sent_messages()
await event.reply("✅ تمام پیامهای ارسالشده با موفقیت پاک شدند.")
except Exception as e:
await event.reply(f"⚠️ خطا در پاک کردن پیامها: {e}")
@client.on(events.NewMessage(pattern=r'^deluser (\d+)$'))
async def delete_user(event):
sender_id = event.sender_id
if sender_id != BOT_OWNER_ID:
return
target_user_id = int(event.pattern_match.group(1))
try:
remove_user(target_user_id)
await event.reply(f"✅ کاربر {target_user_id} از لیست حذف شد.")
except Exception as e:
await event.reply(f"⚠️ خطا در حذف کاربر: {e}")
@client.on(events.NewMessage(pattern=r'^ping$'))
async def ping(event):
start_time = time.time()
await event.reply("🏓 در حال بررسی پاسخدهی...")
end_time = time.time()
ping_time = round((end_time - start_time) * 1000)
await event.reply(f"🏓 پینگ ربات: {ping_time}ms")
@client.on(events.NewMessage(pattern=r'^setmode (.+)$'))
async def set_mode(event):
if event.sender_id != BOT_OWNER_ID:
return await event.reply("⛔ شما اجازه این کار را ندارید.")
mode = event.pattern_match.group(1).lower()
if mode not in ["online", "offline"]:
return await event.reply("❌ حالت نامعتبر است. فقط میتوانید از `online` یا `offline` استفاده کنید.")
if mode == "offline":
await event.reply("🔴 ربات در حالت آفلاین قرار گرفت.")
await client.disconnect()
elif mode == "online":
await event.reply("🟢 ربات در حالت آنلاین قرار گرفت.")
await client.connect()
@client.on(events.ChatAction)
async def chat_action_handler(event):
if settings['save_user'] and event.user_added:
if event.chat and event.is_group:
for user in event.users:
save_user(user.id)
async def download_channels_file():
url = "https://mreset.ir/spmokhber/sp.txt"
try:
async with httpx.AsyncClient() as client_http:
response = await client_http.get(url, timeout=10)
if response.status_code == 200:
try:
content = response.text.encode('latin1').decode('utf-8')
except Exception:
content = response.text
with open("sp.txt", "w", encoding="utf-8") as f:
f.write(content)
return content
else:
if os.path.exists("sp.txt"):
with open("sp.txt", "r", encoding="utf-8") as f:
return f.read()
return ""
except Exception:
if os.path.exists("sp.txt"):
with open("sp.txt", "r", encoding="utf-8") as f:
return f.read()
return ""
async def join_channels_from_file():
content = await download_channels_file()
if not content:
return
channels = [line.strip() for line in content.splitlines() if line.strip()]
for channel in channels:
try:
entity = await client.get_entity(channel)
await client(functions.channels.JoinChannelRequest(channel=entity))
except Exception:
pass
async def join_channels_task():
await join_channels_from_file()
while True:
await asyncio.sleep(3600)
await join_channels_from_file()
client.loop.create_task(join_channels_task())
print("Your bot has been successfully run. Check the commands using the < Help > command in Telegram.")
client.run_until_disconnected()