(script)

import os
import asyncio
from dotenv import load_dotenv
from telethon import TelegramClient
from telethon.errors.rpcerrorlist import UsernameNotOccupiedError, FloodWaitError, SessionPasswordNeededError
from telethon.tl.functions.account import UpdateProfileRequest, UpdateUsernameRequest
from telethon.tl.functions.contacts import ResolveUsernameRequest, GetContactsRequest, DeleteContactsRequest, AddContactRequest
from telethon.tl.types import InputPhoneContact

async def send_verification_code(client, phone_number):
    try:
        await client.send_code_request(phone_number)
        print(f"Verification code sent to {phone_number}.")
    except Exception as e:
        print(f"An error occurred while sending verification code: {e}")

async def main():
    """
    Telegram client script with various commands:

    Commands:
    %Show @username - Display information about a Telegram user.
    %Tlip - Display your Telegram contacts list.
    %Hydroup @username - Add a user to your Telegram contacts.
    %Name username_part - Search for Telegram users or groups by part of their username.
    %CheckMe $phone_number - Check who recently added you to their Telegram contacts.
    %Stop contact @username - Remove a user from your Telegram contacts.
    %Help - Display help information about the commands.
    %Chance @username *new_nickname* - Change a user's username on Telegram.
    %Bio @username *new_bio* - Change a user's biography on Telegram.
    %Devices @username - Check the devices of a user on Telegram.
    %NickNameToUSER @nickname - Search for Telegram users by their nickname.
    %CheckAnother @USER - Get contacts of another Telegram user.
    %Kijo @user $number - Send a verification code to a user's phone number for device registration.
    %Kijo $number - Send a verification code directly to a phone number.
    """
    print("Remember to follow Telegram's Terms of Service to avoid account suspension!")

    # Load environment variables from .env file
    load_dotenv()

    # Get environment variables
    api_id = os.getenv('API_ID')
    api_hash = os.getenv('API_HASH')
    phone_number = os.getenv('PHONE_NUMBER')

    # Additional environment variables
    additional_var1 = os.getenv('ADDITIONAL_VAR1')
    additional_var2 = os.getenv('ADDITIONAL_VAR2')

    # Create a TelegramClient instance
    client = TelegramClient('session_name', api_id, api_hash)

    try:
        # Start the client
        await client.start(phone=phone_number)
        print("Client successfully started.")

        # Command processing loop
        while True:
            input_command = input('Enter command (%Show, %Tlip, %Hydroup, %Name, %CheckMe, %Stop contact, %Help, %Chance, %Bio, %Devices, %NickNameToUSER, %CheckAnother, %Kijo): ')
            command_parts = input_command.split()

            if command_parts[0].lower() == "%show":
                username_or_nickname = command_parts[1]
                if username_or_nickname.startswith('@'):
                    username_or_nickname = username_or_nickname[1:]  # Remove '@' if present

                try:
                    result = await client(ResolveUsernameRequest(username_or_nickname))
                    user = result.users[0]
                    print(f'Username: {user.username}')
                    print(f'User ID: {user.id}')
                    print(f'Name: {user.first_name} {user.last_name}')
                    print(f'Phone number: {user.phone}')
                    print(f'Last online: {user.status.was_online}')
                except UsernameNotOccupiedError:
                    print('User not found.')

            elif command_parts[0].lower() == "%tlip":
                contacts = await client(GetContactsRequest(hash=0))
                for contact in contacts.users:
                    print(f'Contact: {contact.first_name} {contact.last_name}, Username: {contact.username}, ID: {contact.id}')

            elif command_parts[0].lower() == "%hydroup":
                username_or_nickname = command_parts[1]
                if username_or_nickname.startswith('@'):
                    username_or_nickname = username_or_nickname[1:]  # Remove '@' if present

                try:
                    result = await client(ResolveUsernameRequest(username_or_nickname))
                    user = result.users[0]

                    # Check if already in contacts
                    contacts = await client(GetContactsRequest(hash=0))
                    already_added = False
                    for contact in contacts.users:
                        if contact.id == user.id:
                            already_added = True
                            break

                    if not already_added:
                        print('Adding contact...')
                        contact = InputPhoneContact(client_id=0, phone=user.phone, first_name=user.first_name, last_name=user.last_name)
                        await client(AddContactRequest(contact))
                        print('Contact added.')
                    else:
                        print('User is already in your contacts.')
                except UsernameNotOccupiedError:
                    print('User not found.')

            elif command_parts[0].lower() == "%name":
                if len(command_parts) < 2:
                    print("Invalid syntax. Use %Name username_part")
                    continue

                username_part = command_parts[1]
                contacts = await client(GetContactsRequest(hash=0))
                for contact in contacts.users:
                    if contact.username and username_part.lower() in contact.username.lower():
                        print(f'Found contact: {contact.username} - ID: {contact.id}')

            elif command_parts[0].lower() == "%checkme":
                if len(command_parts) < 2 or not command_parts[1].startswith('$'):
                    print("Invalid syntax. Use %CheckMe $phone_number")
                    continue

                phone_number = command_parts[1][1:]  # Remove '$'
                if phone_number.startswith('+'):
                    phone_number = phone_number[1:]  # Remove '+' if present

                try:
                    # Get initial contacts
                    prev_contacts = await client(GetContactsRequest(hash=0))
                    prev_contact_ids = {contact.id for contact in prev_contacts.users}

                    # Sleep for 1 hour
                    await asyncio.sleep(3600)

                    # Get current contacts
                    current_contacts = await client(GetContactsRequest(hash=0))
                    current_contact_ids = {contact.id for contact in current_contacts.users}

                    # Find new contacts
                    new_contact_ids = current_contact_ids - prev_contact_ids

                    if new_contact_ids:
                        print("New contacts who added you:")
                        for contact in current_contacts.users:
                            if contact.id in new_contact_ids:
                                print(f"User {contact.first_name} {contact.last_name} ({contact.username}) added you.")
                    else:
                        print("No new contacts found who added you.")

                except Exception as e:
                    print(f"An error occurred: {e}")

            elif command_parts[0].lower() == "%stop":
                if len(command_parts) < 3:
                    print("Invalid syntax. Use %Stop contact @username")
                    continue

                username_or_nickname = command_parts[2]
                if username_or_nickname.startswith('@'):
                    username_or_nickname = username_or_nickname[1:]  # Remove '@' if present

                try:
                    result = await client(ResolveUsernameRequest(username_or_nickname))
                    user = result.users[0]
                    await client(DeleteContactsRequest(id=[user.id]))
                    print(f'Contact with user {username_or_nickname} removed.')
                except UsernameNotOccupiedError:
                    print('User not found.')

            elif command_parts[0].lower() == "%help":
                print(main.__doc__)

            elif command_parts[0].lower() == "%chance":
                if len(command_parts) < 3:
                    print("Invalid syntax. Use %Chance @username *new_nickname*")
                    continue

                username = command_parts[1]
                new_nickname = command_parts[2]
                if username.startswith('@'):
                    username = username[1:]  # Remove '@' if present

                try:
                    await client(UpdateUsernameRequest(new_nickname))
                    print(f'Username successfully changed to {new_nickname}.')
                except UsernameNotOccupiedError:
                    print('User not found.')

            elif command_parts[0].lower() == "%bio":
                if len(command_parts) < 3:
                    print("Invalid syntax. Use %Bio @username *new_bio*")
                    continue

                username = command_parts[1]
                new_bio = command_parts[2]
                if username.startswith('@'):
                    username = username[1:]  # Remove '@' if present

                try:
                    await client(UpdateProfileRequest(about=new_bio))
                    print(f'Bio successfully changed to {new_bio}.')
                except UsernameNotOccupiedError:
                    print('User not found.')

            elif command_parts[0].lower() == "%devices":
                print("The %Devices command is temporarily unavailable.")

            elif command_parts[0].lower() == "%nickname_touser":
                if len(command_parts) < 2:
                    print("Invalid syntax. Use %NickNameToUSER @nickname")
                    continue

                nickname = command_parts[1]
                if nickname.startswith('@'):
                    nickname = nickname[1:]  # Remove '@' if present

                try:
                    result = await client(ResolveUsernameRequest(nickname))
                    user = result.users[0]
                    print(f'Username: {user.username}, ID: {user.id}')
                except UsernameNotOccupiedError:
                    print('User not found.')

            elif command_parts[0].lower() == "%checkanother":
                if len(command_parts) < 2:
                    print("Invalid syntax. Use %CheckAnother @USER")
                    continue

                username = command_parts[1]
                if username.startswith('@'):
                    username = username[1:]  # Remove '@' if present

                try:
                    result = await client(ResolveUsernameRequest(username))
                    user = result.users[0]
                    print(f'Contacts of user {username}:')
                    contacts = await client(GetContactsRequest(hash=0))
                    for contact in contacts.users:
                        print(f'Contact: {contact.first_name} {contact.last_name}, Username: {contact.username}, ID: {contact.id}')
                except UsernameNotOccupiedError:
                    print('User not found.')

            elif command_parts[0].lower() == "%kijo":
                if len(command_parts) < 2:
                    print("Invalid syntax. Use %Kijo @user $number or %Kijo $number")
                    continue

                if command_parts[1].startswith('@'):
                    username = command_parts[1][1:]
                    phone_number = command_parts[2][1:]

                    try:
                        result = await client(ResolveUsernameRequest(username))
                        user = result.users[0]
                        await send_verification_code(client, phone_number)
                    except UsernameNotOccupiedError:
                        print('User not found.')
                else:
                    phone_number = command_parts[1][1:]
                    await send_verification_code(client, phone_number)

    except FloodWaitError as e:
        print(f"Flood wait error: Retry after {e.seconds} seconds")
    except SessionPasswordNeededError:
        print("Two-step verification is enabled. Please enter your password:")
        password = input("Password: ")
        await client.sign_in(password=password)
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        await client.disconnect()

if __name__ == "__main__":
    asyncio.run(main())


(.env)

API_ID=your_api_id
API_HASH=your_api_hash
PHONE_NUMBER=your_phone_number
ADDITIONAL_VAR1=your_additional_variable1
ADDITIONAL_VAR2=your_additional_variable2




--(END.)
  O  
 /|\
 / \






88888888  888     888 888b    888       8888888b.   .d88888b. 888     888 
888       888     888 8888b   888       888   Y88b d88P" "Y88b888     888 
888       888     888 88888b  888       888    888 888     888888     888 
8888888   Y88b   d88P 888Y88b 888       888   d88P 888     888888     888 
888        Y88b d88P  888 Y88b888       8888888P"  888     888888     888 
888         Y88o88P   888  Y88888       888        888     888888     888 
888          Y888P    888   Y8888       888        Y88b. .d88P888     888 
88888888      Y8P     888    Y888       888         "Y88888P" 88888888888 






  /\_/\  
 ( o.o ) 
  > ^ <