from telethon.sync import TelegramClient
from telethon.errors.rpcerrorlist import PhoneNumberBannedError
import pickle, os
from colorama import init, Fore
from time import sleep

init()

n = Fore.RESET
lg = Fore.LIGHTGREEN_EX
r = Fore.RED
w = Fore.WHITE
cy = Fore.CYAN
ye = Fore.YELLOW
colors = [lg, r, w, cy, ye]

try:
    import requests
except ImportError:
    print(f'{lg}[i] Installing module - requests...{n}')
    os.system('pip install requests')

def banner():
    import random
    # fancy logo
    b = [
    '   _____             __',
    '  /  _  \    _______/  |_____________',
    ' /  /_\  \  /  ___/\   __\_  __ \__  \\',
    '/    |    \ \___ \  |  |  |  | \// __ \_',
    '\____|__  /____  >  |__|  |__|  (____   /',
    '        \/     \/                     \/'
    ]
    for char in b:
        print(f'{random.choice(colors)}{char}{n}')
    #print('=============SON OF GENISYS==============')
    print(f'   Version: 1.2 | Author: Cryptonian{n}\n')

def clr():
    if os.name == 'nt':
        os.system('cls')
    else:
        os.system('clear')

while True:
    clr()
    banner()
    print(lg+'[1] Add new accounts'+n)
    print(lg+'[2] Filter all banned accounts'+n)
    print(lg+'[3] Delete specific accounts'+n)
    print(lg+'[4] Update your Astra'+n)
    print(lg+'[5] Quit'+n)
    a = int(input('\nEnter your choice: '))
    if a == 1:
        new_accs = []
        with open('vars.txt', 'ab') as g:
            number_to_add = int(input(f'\n{lg} [~] Enter number of accounts to add: {r}'))
            for i in range(number_to_add):
                phone_number = str(input(f'\n{lg} [~] Enter Phone Number: {r}'))
                parsed_number = ''.join(phone_number.split())
                pickle.dump([parsed_number], g)
                new_accs.append(parsed_number)
            print(f'\n{lg} [i] Saved all accounts in vars.txt')
            clr()
            print(f'\n{lg} [*] Logging in from new accounts\n')
            for number in new_accs:
                c = TelegramClient(f'sessions/{number}', 3910389 , '86f861352f0ab76a251866059a6adbd6')
                c.start(number)
                print(f'{lg}[+] Login successful')
                c.disconnect()
            input(f'\n Press enter to goto main menu...')

        g.close()
    elif a == 2:
        accounts = []
        banned_accs = []
        h = open('vars.txt', 'rb')
        while True:
            try:
                accounts.append(pickle.load(h))
            except EOFError:
                break
        h.close()
        if len(accounts) == 0:
            print(r+'[!] There are no accounts! Please add some and retry')
            sleep(3)
        else:
            for account in accounts:
                phone = str(account[0])
                client = TelegramClient(f'sessions/{phone}', 3910389 , '86f861352f0ab76a251866059a6adbd6')
                client.connect()
                if not client.is_user_authorized():
                    try:
                        client.send_code_request(phone)
                        #client.sign_in(phone, input('[+] Enter the code: '))
                        print(f'{lg}[+] {phone} is not banned{n}')
                    except PhoneNumberBannedError:
                        print(r+str(phone) + ' is banned!'+n)
                        banned_accs.append(account)
            if len(banned_accs) == 0:
                print(lg+'Congrats! No banned accounts')
                input('\nPress enter to goto main menu...')
            else:
                for m in banned_accs:
                    accounts.remove(m)
                with open('vars.txt', 'wb') as k:
                    for a in accounts:
                        Phone = a[0]
                        pickle.dump([Phone], k)
                k.close()
                print(lg+'[i] All banned accounts removed'+n)
                input('\nPress enter to goto main menu...')

    elif a == 3:
        accs = []
        f = open('vars.txt', 'rb')
        while True:
            try:
                accs.append(pickle.load(f))
            except EOFError:
                break
        f.close()
        i = 0
        print(f'{lg}[i] Choose an account to delete\n')
        for acc in accs:
            print(f'{lg}[{i}] {acc[0]}{n}')
            i += 1
        index = int(input(f'\n{lg}[+] Enter a choice: {n}'))
        phone = str(accs[index][0])
        session_file = phone + '.session'
        if os.name == 'nt':
            os.system(f'del sessions\\{session_file}')
        else:
            os.system(f'rm sessions/{session_file}')
        del accs[index]
        f = open('vars.txt', 'wb')
        for account in accs:
            pickle.dump(account, f)
        print(f'\n{lg}[+] Account Deleted{n}')
        input(f'\nPress enter to goto main menu...')
        f.close()
    elif a == 4:
        # thanks to github.com/th3unkn0n for the snippet below
        print(f'\n{lg}[i] Checking for updates...')
        try:
            # https://raw.githubusercontent.com/Cryptonian007/Astra/main/version.txt
            version = requests.get('https://raw.githubusercontent.com/Cryptonian007/Astra/main/version.txt')
        except:
            print(f'{r} You are not connected to the internet')
            print(f'{r} Please connect to the internet and retry')
            exit()
        if float(version.text) > 1.1:
            prompt = str(input(f'{lg}[~] Update available[Version {version.text}]. Download?[y/n]: {r}'))
            if prompt == 'y' or prompt == 'yes' or prompt == 'Y':
                print(f'{lg}[i] Downloading updates...')
                if os.name == 'nt':
                    os.system('del add.py')
                    os.system('del manager.py')
                else:
                    os.system('rm add.py')
                    os.system('rm manager.py')
                #os.system('del scraper.py')
                os.system('curl -l -O https://raw.githubusercontent.com/Cryptonian007/Astra/main/add.py')
                os.system('curl -l -O https://raw.githubusercontent.com/Cryptonian007/Astra/main/manager.py')
                print(f'{lg}[*] Updated to version: {version.text}')
                input('Press enter to exit...')
                exit()
            else:
                print(f'{lg}[!] Update aborted.')
                input('Press enter to goto main menu...')
        else:
            print(f'{lg}[i] Your Astra is already up to date')
            input('Press enter to goto main menu...')
    elif a == 5:
        clr()
        banner()
        exit()

[((179, 185), 'colorama.init', 'init', ([], {}), '()\n', (183, 185), False, 'from colorama import init, Fore\n'), ((421, 454), 'os.system', 'os.system', (['"""pip install requests"""'], {}), "('pip install requests')\n", (430, 454), False, 'import pickle, os\n'), ((1014, 1030), 'os.system', 'os.system', (['"""cls"""'], {}), "('cls')\n", (1023, 1030), False, 'import pickle, os\n'), ((1049, 1067), 'os.system', 'os.system', (['"""clear"""'], {}), "('clear')\n", (1058, 1067), False, 'import pickle, os\n'), ((1722, 1753), 'pickle.dump', 'pickle.dump', (['[parsed_number]', 'g'], {}), '([parsed_number], g)\n', (1733, 1753), False, 'import pickle, os\n'), ((2003, 2088), 'telethon.sync.TelegramClient', 'TelegramClient', (['f"""sessions/{number}"""', '(3910389)', '"""86f861352f0ab76a251866059a6adbd6"""'], {}), "(f'sessions/{number}', 3910389,\n    '86f861352f0ab76a251866059a6adbd6')\n", (2017, 2088), False, 'from telethon.sync import TelegramClient\n'), ((2649, 2657), 'time.sleep', 'sleep', (['(3)'], {}), '(3)\n', (2654, 2657), False, 'from time import sleep\n'), ((824, 845), 'random.choice', 'random.choice', (['colors'], {}), '(colors)\n', (837, 845), False, 'import random\n'), ((2774, 2859), 'telethon.sync.TelegramClient', 'TelegramClient', (['f"""sessions/{phone}"""', '(3910389)', '"""86f861352f0ab76a251866059a6adbd6"""'], {}), "(f'sessions/{phone}', 3910389, '86f861352f0ab76a251866059a6adbd6'\n    )\n", (2788, 2859), False, 'from telethon.sync import TelegramClient\n'), ((4462, 4504), 'os.system', 'os.system', (['f"""del sessions\\\\{session_file}"""'], {}), "(f'del sessions\\\\{session_file}')\n", (4471, 4504), False, 'import pickle, os\n'), ((4531, 4571), 'os.system', 'os.system', (['f"""rm sessions/{session_file}"""'], {}), "(f'rm sessions/{session_file}')\n", (4540, 4571), False, 'import pickle, os\n'), ((4672, 4695), 'pickle.dump', 'pickle.dump', (['account', 'f'], {}), '(account, f)\n', (4683, 4695), False, 'import pickle, os\n'), ((2445, 2459), 'pickle.load', 'pickle.load', (['h'], {}), '(h)\n', (2456, 2459), False, 'import pickle, os\n'), ((5066, 5157), 'requests.get', 'requests.get', (['"""https://raw.githubusercontent.com/Cryptonian007/Astra/main/version.txt"""'], {}), "(\n    'https://raw.githubusercontent.com/Cryptonian007/Astra/main/version.txt')\n", (5078, 5157), False, 'import requests\n'), ((3732, 3755), 'pickle.dump', 'pickle.dump', (['[Phone]', 'k'], {}), '([Phone], k)\n', (3743, 3755), False, 'import pickle, os\n'), ((4040, 4054), 'pickle.load', 'pickle.load', (['f'], {}), '(f)\n', (4051, 4054), False, 'import pickle, os\n'), ((5887, 5986), 'os.system', 'os.system', (['"""curl -l -O https://raw.githubusercontent.com/Cryptonian007/Astra/main/add.py"""'], {}), "(\n    'curl -l -O https://raw.githubusercontent.com/Cryptonian007/Astra/main/add.py'\n    )\n", (5896, 5986), False, 'import pickle, os\n'), ((5993, 6096), 'os.system', 'os.system', (['"""curl -l -O https://raw.githubusercontent.com/Cryptonian007/Astra/main/manager.py"""'], {}), "(\n    'curl -l -O https://raw.githubusercontent.com/Cryptonian007/Astra/main/manager.py'\n    )\n", (6002, 6096), False, 'import pickle, os\n'), ((5642, 5665), 'os.system', 'os.system', (['"""del add.py"""'], {}), "('del add.py')\n", (5651, 5665), False, 'import pickle, os\n'), ((5686, 5713), 'os.system', 'os.system', (['"""del manager.py"""'], {}), "('del manager.py')\n", (5695, 5713), False, 'import pickle, os\n'), ((5756, 5778), 'os.system', 'os.system', (['"""rm add.py"""'], {}), "('rm add.py')\n", (5765, 5778), False, 'import pickle, os\n'), ((5799, 5825), 'os.system', 'os.system', (['"""rm manager.py"""'], {}), "('rm manager.py')\n", (5808, 5825), False, 'import pickle, os\n')]