import subprocess
import sys
import os
import asyncio
import re
import json
import uuid
import random
import string
import base64
import webbrowser
import time
import threading
import logging
import hashlib
import queue
from datetime import datetime
from pathlib import Path
from time import sleep
import aiohttp
import httpx
import requests
import discord
import whois
import instaloader
from discord.ext import commands
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
from faker import Faker
from colorama import Fore, Style, init
from pystyle import Colors, Colorate, Write
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from telethon.sync import TelegramClient
from ipwhois import IPWhois
from pyfiglet import Figlet
from cfonts import render as cfont_render
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from requests_cache import CachedSession
from ratelimit import limits, sleep_and_retry

init(autoreset=True)
ua = UserAgent()

def libc():
    gerekliler = [
        'aiohttp', 'httpx', 'requests', 'beautifulsoup4', 'fake-useragent', 
        'faker', 'colorama', 'pystyle', 'discord.py', 'selenium', 
        'webdriver-manager', 'telethon', 'ipwhois', 'python-whois', 
        'instaloader', 'requests-cache', 'ratelimit', 'pyfiglet', 'python-cfonts'
    ]
    for lib in gerekliler:
        try:
            modul_adi = lib.replace('-', '_').replace('.py', '')
            __import__(modul_adi)
        except ImportError:
            subprocess.check_call([sys.executable, '-m', 'pip', 'install', lib])

class EizonXSession(requests.Session):
    def __init__(self, retries=3, backoff_factor=0.3, timeout=10):
        super().__init__()
        self.timeout = timeout
        retry = Retry(total=retries, backoff_factor=backoff_factor, status_forcelist=[429, 500, 502, 503, 504])
        adapter = HTTPAdapter(max_retries=retry)
        self.mount('http://', adapter)
        self.mount('https://', adapter)
        self.headers.update({'User-Agent': ua.random})
    def request(self, method, url, **kwargs):
        if 'timeout' not in kwargs:
            kwargs['timeout'] = self.timeout
        return super().request(method, url, **kwargs)

def random_user_agent():
    return ua.random

def colored_print(text, color='green'):
    colors = {'green': Fore.GREEN, 'red': Fore.RED, 'blue': Fore.BLUE, 'yellow': Fore.YELLOW, 'cyan': Fore.CYAN, 'white': Fore.WHITE}
    print(colors.get(color, Fore.WHITE) + text + Style.RESET_ALL)

def setup_logging(level=logging.INFO):
    logging.basicConfig(level=level, format='%(asctime)s - %(levelname)s - %(message)s')

def random_string(length=16, chars=None):
    if chars is None:
        chars = string.ascii_letters + string.digits
    return ''.join(random.choice(chars) for _ in range(length))

def generate_uuid():
    return str(uuid.uuid4())