1- # Developed By MrAmini
1+ # Developed By MrAmini5
22
33from telethon import TelegramClient , events , functions , types
44import asyncio
77import json
88import re
99import httpx
10+ import sys
11+ import subprocess
1012
1113# Configuration
12- API_ID = '2040 ' # Replace with your API ID
13- API_HASH = 'b18441a1ff607e10a989891a5462e627 ' # Replace with your API hash
14- BOT_OWNER_ID = 7541383912 # Replace with the bot owner's Telegram user ID
14+ API_ID = 'AminiMokhberAPIID ' # Replace with your API ID
15+ API_HASH = 'AminiMokhberAPIHASH ' # Replace with your API hash
16+ BOT_OWNER_ID = AminiMokhberADMINID # Replace with the bot owner's Telegram user ID
1517USERS_FILE = 'user.txt'
1618MESSAGE_FILE = 'pm.txt'
1719BIO_API_URL = 'https://api.codebazan.ir/bio'
1820SETTINGS_FILE = 'settings.json'
1921ACCOUNTS_FILE = 'accounts.json'
20-
22+ REBOOT_FLAG_FILE = "reboot_flag.txt"
2123
2224default_settings = {
2325 'save_user' : True ,
2931 'auto_join' : False
3032}
3133
34+
35+ def save_user_to_file (user_id ):
36+ try :
37+ user_id_str = str (user_id ).strip () # اطمینان از ذخیره به صورت رشته
38+ with open ("user.txt" , "a" , encoding = "utf-8" ) as file :
39+ file .write (user_id_str + "\n " ) # ذخیره آیدی به صورت رشته در فایل
40+ except Exception as e :
41+ print (f"خطا در ذخیره کردن کاربر به فایل: { e } " )
42+
43+ def remove_user_from_file (user_id ):
44+ try :
45+ user_id_str = str (user_id ).strip () # اطمینان از تبدیل به رشته و حذف فاصلههای اضافی
46+ with open ("user.txt" , "r" , encoding = "utf-8" ) as file :
47+ lines = file .readlines ()
48+
49+ # حذف تمامی خطوطی که آیدی آنها برابر با user_id_str است
50+ new_lines = [line for line in lines if line .strip () != user_id_str ]
51+
52+ with open ("user.txt" , "w" , encoding = "utf-8" ) as file :
53+ file .writelines (new_lines )
54+
55+ except Exception as e :
56+ print (f"خطا در حذف کاربر از فایل: { e } " )
57+
58+
3259def load_users ():
3360 try :
3461 with open (USERS_FILE , "r" , encoding = "utf-8" ) as f :
@@ -75,6 +102,18 @@ def save_settings(settings):
75102
76103settings = load_settings ()
77104
105+ def remove_user_from_file (user_id ):
106+ try :
107+ with open ("user.txt" , "r" , encoding = "utf-8" ) as file :
108+ users = file .readlines ()
109+
110+ with open ("user.txt" , "w" , encoding = "utf-8" ) as file :
111+ for user in users :
112+ if user .strip () != str (user_id ):
113+ file .write (user )
114+ except Exception as e :
115+ print (f"خطا در حذف کاربر از فایل: { e } " )
116+
78117def save_user (user_id ):
79118 if not os .path .exists (USERS_FILE ):
80119 open (USERS_FILE , 'w' ).close ()
@@ -103,7 +142,7 @@ async def set_new_pm(event):
103142 await event .reply ("⚠️ لطفاً پیام جدید خود را بعد از `setnewpm` در خط جدید وارد کنید." )
104143 return
105144
106- new_message = parts [1 ].strip () # حذف فاصلههای اضافی
145+ new_message = parts [1 ].strip ()
107146
108147 with open ("pm.txt" , "w" , encoding = "utf-8" ) as f :
109148 f .write (new_message )
@@ -409,6 +448,7 @@ async def account_status(event):
409448
410449 await event .reply (status_message )
411450
451+
412452@client .on (events .NewMessage )
413453async def message_handler (event ):
414454 sender_id = event .sender_id
@@ -510,6 +550,7 @@ async def message_handler(event):
510550 for user in users :
511551 try :
512552 await client .send_message (int (user ), message_content )
553+ remove_user_from_file (user_id )
513554 await asyncio .sleep (random .randint (1 , 10 ))
514555 except Exception as e :
515556 print (f"Error sending message to { user } : { e } " )
@@ -556,6 +597,7 @@ async def message_handler(event):
556597 "🔴 `chatuseroff` - غیرفعالسازی ذخیره کاربران پیامدهنده در گروهها\n "
557598 "🟢 `InvalidUserOn` - حذف خودکار کاربران نامعتبر\n "
558599 "🔴 `InvalidUserOff` - غیرفعالسازی حذف کاربران نامعتبر\n "
600+ "🟢 `cleanlist` - حذف کاربران ذخیره شده\n "
559601 "━━━━━━━━━━━━━━━━━━━━\n "
560602 "🔧 **تنظیمات و قابلیتها:**\n "
561603 "🔹 `bioon` - فعالسازی بیوگرافی تصادفی\n "
@@ -582,6 +624,14 @@ async def message_handler(event):
582624 await event .reply (help_text , parse_mode = 'markdown' )
583625
584626
627+ @client .on (events .NewMessage (pattern = r'^cleanlist$' ))
628+ async def clean_list (event ):
629+ sender_id = event .sender_id
630+ if sender_id != BOT_OWNER_ID :
631+ return
632+
633+ open ("user.txt" , "w" ).close ()
634+ await event .reply ("✅ لیست کاربران با موفقیت پاک شد." )
585635
586636
587637@client .on (events .ChatAction )
0 commit comments