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()

[((7, 0, 7, 6), 'colorama.init', 'init', ({}, {}), '()', False, 'from colorama import init, Fore\n'), ((21, 4, 21, 37), 'os.system', 'os.system', ({(21, 14, 21, 36): '"""pip install requests"""'}, {}), "('pip install requests')", False, 'import pickle, os\n'), ((41, 8, 41, 24), 'os.system', 'os.system', ({(41, 18, 41, 23): '"""cls"""'}, {}), "('cls')", False, 'import pickle, os\n'), ((43, 8, 43, 26), 'os.system', 'os.system', ({(43, 18, 43, 25): '"""clear"""'}, {}), "('clear')", False, 'import pickle, os\n'), ((61, 16, 61, 47), 'pickle.dump', 'pickle.dump', ({(61, 28, 61, 43): '[parsed_number]', (61, 45, 61, 46): 'g'}, {}), '([parsed_number], g)', False, 'import pickle, os\n'), ((67, 20, 67, 102), 'telethon.sync.TelegramClient', 'TelegramClient', ({(67, 35, 67, 55): 'f"""sessions/{number}"""', (67, 57, 67, 64): '3910389', (67, 67, 67, 101): '"""86f861352f0ab76a251866059a6adbd6"""'}, {}), "(f'sessions/{number}', 3910389,\n    '86f861352f0ab76a251866059a6adbd6')", False, 'from telethon.sync import TelegramClient\n'), ((86, 12, 86, 20), 'time.sleep', 'sleep', ({(86, 18, 86, 19): '(3)'}, {}), '(3)', False, 'from time import sleep\n'), ((35, 17, 35, 38), 'random.choice', 'random.choice', ({(35, 31, 35, 37): 'colors'}, {}), '(colors)', False, 'import random\n'), ((90, 25, 90, 106), 'telethon.sync.TelegramClient', 'TelegramClient', ({(90, 40, 90, 59): 'f"""sessions/{phone}"""', (90, 61, 90, 68): '3910389', (90, 71, 90, 105): '"""86f861352f0ab76a251866059a6adbd6"""'}, {}), "(f'sessions/{phone}', 3910389, '86f861352f0ab76a251866059a6adbd6'\n    )", False, 'from telethon.sync import TelegramClient\n'), ((132, 12, 132, 54), 'os.system', 'os.system', ({(132, 22, 132, 53): 'f"""del sessions\\\\{session_file}"""'}, {}), "(f'del sessions\\\\{session_file}')", False, 'import pickle, os\n'), ((134, 12, 134, 52), 'os.system', 'os.system', ({(134, 22, 134, 51): 'f"""rm sessions/{session_file}"""'}, {}), "(f'rm sessions/{session_file}')", False, 'import pickle, os\n'), ((138, 12, 138, 35), 'pickle.dump', 'pickle.dump', ({(138, 24, 138, 31): 'account', (138, 33, 138, 34): 'f'}, {}), '(account, f)', False, 'import pickle, os\n'), ((80, 32, 80, 46), 'pickle.load', 'pickle.load', ({(80, 44, 80, 45): 'h'}, {}), '(h)', False, 'import pickle, os\n'), ((147, 22, 147, 108), 'requests.get', 'requests.get', ({(147, 35, 147, 107): '"""https://raw.githubusercontent.com/Cryptonian007/Astra/main/version.txt"""'}, {}), "(\n    'https://raw.githubusercontent.com/Cryptonian007/Astra/main/version.txt')", False, 'import requests\n'), ((109, 24, 109, 47), 'pickle.dump', 'pickle.dump', ({(109, 36, 109, 43): '[Phone]', (109, 45, 109, 46): 'k'}, {}), '([Phone], k)', False, 'import pickle, os\n'), ((119, 28, 119, 42), 'pickle.load', 'pickle.load', ({(119, 40, 119, 41): 'f'}, {}), '(f)', False, 'import pickle, os\n'), ((163, 16, 163, 105), 'os.system', 'os.system', ({(163, 26, 163, 104): '"""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    )", False, 'import pickle, os\n'), ((164, 16, 164, 109), 'os.system', 'os.system', ({(164, 26, 164, 108): '"""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    )", False, 'import pickle, os\n'), ((157, 20, 157, 43), 'os.system', 'os.system', ({(157, 30, 157, 42): '"""del add.py"""'}, {}), "('del add.py')", False, 'import pickle, os\n'), ((158, 20, 158, 47), 'os.system', 'os.system', ({(158, 30, 158, 46): '"""del manager.py"""'}, {}), "('del manager.py')", False, 'import pickle, os\n'), ((160, 20, 160, 42), 'os.system', 'os.system', ({(160, 30, 160, 41): '"""rm add.py"""'}, {}), "('rm add.py')", False, 'import pickle, os\n'), ((161, 20, 161, 46), 'os.system', 'os.system', ({(161, 30, 161, 45): '"""rm manager.py"""'}, {}), "('rm manager.py')", False, 'import pickle, os\n')]