diff --git a/main/__init__.py b/main/__init__.py index c0180d7c..9a037a6e 100644 --- a/main/__init__.py +++ b/main/__init__.py @@ -10,13 +10,7 @@ # check which packages are installed -installed_python_libs = [] - -for package in metadata.distributions(): - installed_python_libs.append(package.metadata["Name"].lower()) - - - +installed_python_libs_file = "../installed_requirements.txt" class Config: """This class generates the configs """ @@ -25,7 +19,7 @@ class Config: def isLocalHost(): """Check if it is localhost""" - return os.path.exists("config.txt") + return os.path.exists("../config.txt") class Tools: @@ -38,110 +32,14 @@ class Tools: def clear_screen(self): os.system("clear" if self.is_linux else "cls") - def check_command(self, args: list): - return (subprocess.run( - args, - stdout=subprocess.PIPE, - shell=True, - check=True - )).stdout.decode() - - - def requirements(self): - with open("requirements.txt", "r", encoding="UTF-8") as f: - return [x.lower().strip() for x in f.read().split("\n") if x not in ("\n", "")] - - - def check_requirements(self): - if self.is_windows: - self.install_scoop() - - self.install_ffmpeg() - - print("Checking Packages:\n\n") - for pkg in self.requirements(): - try: - if pkg == "numpy": - self.install_numpy() - elif pkg == "lxml": - self.install_lxml() - elif pkg == "psycopg2": - self.install_psycopg2() - elif pkg == "pillow": - self. install_pillow() - else: - os.system(f"python3 -m pip install {pkg}") - - except Exception as e: - print(f"\n{Colors.red}Error installing {pkg}: {str(e)}") - - - - def install_numpy(self): - print("\nInstalling numpy . . .\n") - os.system('MATHLIB="m" pkg install python-numpy') - - - def install_lxml(self): - if self.is_windows: - os.system("scoop install libxml2") - os.system("scoop install libxslt") - else: - os.system("apt install libxml2 libxslt") - print("\nInstalling lxml . . .\n") - os.system("CFLAGS='-O0' python3 -m pip install lxml") - - def install_psycopg2(self): - if self.is_windows: - os.system("scoop install postgresql python make clang") - else: - os.system("apt install postgresql python make clang") - print("\nInstalling psycopg2 . . .\n") - os.system("python3 -m pip install psycopg2") - - def install_scoop(self): - os.system("winget install scoop --accept-package-agreements") - - - def install_pillow(self): - if self.is_windows: - os.system("scoop install libjpeg-turbo") - os.system('./configure CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"') - else: - os.system("apt install libjpeg-turbo") - os.system('LDFLAGS="-L/system/lib/" CFLAGS="-I/data/data/com.termux/files/usr/include/"') - print("\nInstalling pillow . . .") - os.system("python3 -m pip install pillow") - - def install_ffmpeg(self): - if tools.is_windows: - # install ffmpeg - # permission needed in windows - os.system('Set-ExecutionPolicy RemoteSigned -Scope CurrentUser') - # install scoop for installing scoop & other packages - os.system('Invoke-Expression "& {$(Invoke-RestMethod get.scoop.sh)} -RunAsAdmin"') - # install ffmpeg through scoop - os.system('scoop install ffmpeg') - - elif tools.is_linux: - # install ffmpeg - os.system('apt install ffmpeg') - else: - print('\nUnknown device, Existing . . .') - exit(0) - def setup_config(self): count = 1 self.clear_screen - # check requirements & install - self.check_requirements() - self.clear_screen - # check if the user config file exists if os.path.exists("config.txt"): print("config.txt file exists: Yes\n\n") - with open("config.txt") as f: + with open("config.txt", "r", encoding="UTF-8") as f: content = [x for x in f.read().split("\n") if x not in ("\n", "")] # set text file config values @@ -176,12 +74,11 @@ def setup_config(self): -tools = Tools() - -if(isLocalHost()): +if isLocalHost(): + tools = Tools() tools.setup_config() else: - print("Setting the Non-LocalHost setup ... !") + print("It looks like you deployed this using Docker, Thats why Setting the Non-LocalHost setup ... !") for attr in dir(Configuration): value = getattr(Configuration, attr, None) if attr.isupper() and not hasattr(Config, attr): diff --git a/requirements.txt b/requirements.txt index 96f4b9b8..50e55cb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ git-python hachoir heroku3 moviepy -numpy +numpy==2.0.0 pillow psycopg2 pySmartDL diff --git a/termux.sh b/termux.sh index 6814cf5a..1eb28e7b 100644 --- a/termux.sh +++ b/termux.sh @@ -34,6 +34,30 @@ install_python() { fi } +install_numpy() { + MATHLIB="m" pkg install python-numpy +} + +install_xml() { + apt install libxml2 libxslt + CFLAGS='-O0' python3 -m pip install lxml +} + +install_psycopg2() { + apt install postgresql python make clang + python3 -m pip install psycopg2 +} + +install_pillow() { + apt install libjpeg-turbo + LDFLAGS="-L/system/lib/" CFLAGS="-I/data/data/com.termux/files/usr/include/" + python3 -m pip install pillow +} + +install_ffmpeg() { + apt install ffmpeg +} + install_userbot_dependencies() { # Check if the requirements file exists if [ ! -f "$REQUIREMENTS_FILE" ]; then diff --git a/windows.bat b/windows.bat index 8c9b9fcb..9cfaf907 100644 --- a/windows.bat +++ b/windows.bat @@ -2,27 +2,59 @@ setlocal :: File containing the list of required packages -set REQUIREMENTS_FILE=requirements.txt -set INSTALLED_FILE=installed_dependencies.txt +set "REQUIREMENTS_FILE=requirements.txt" +set "INSTALLED_FILE=installed_dependencies.txt" :: Main function :main :: Show message echo Running script, please be patient ... +:: Check if winget is available +where winget >nul 2>nul +if %ERRORLEVEL% NEQ 0 ( + echo winget is not installed. Please install it first. + exit /b 1 +) + +:: Check if Scoop is already installed +echo Checking for Scoop installation... +winget list scoop >nul 2>&1 +if %ERRORLEVEL% EQU 0 ( + echo Scoop is already installed. +) else ( + :: Install Scoop using winget + echo Installing Scoop... + Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser + Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression + + :: Check if Scoop was installed successfully + if %ERRORLEVEL% NEQ 0 ( + echo There was an issue installing Scoop. + exit /b 1 + ) +) + +:: Install ffmpeg using Scoop +echo Installing ffmpeg ... +scoop install ffmpeg +if %ERRORLEVEL% NEQ 0 ( + echo There was an issue installing ffmpeg. + exit /b 1 +) + :: Check Python 3 installation echo Checking python installation ... where python3 >nul 2>&1 if %ERRORLEVEL% NEQ 0 ( - echo Python3 is not installed. Trying to install Python3 ... - echo Please install Python3 manually from the Python website or using a package manager. + echo Python3 is not installed. Please install Python3 manually from the Python website or using a package manager. echo Exiting script with error. exit /b 1 ) :: Check and install userbot dependencies if not exist "%REQUIREMENTS_FILE%" ( - echo REQUIREMENTS_FILE file not found, Exiting script with error. + echo %REQUIREMENTS_FILE% file not found, Exiting script with error. exit /b 1 ) @@ -36,7 +68,21 @@ for /f "usebackq tokens=* delims=" %%i in ("%REQUIREMENTS_FILE%") do ( pip show %%i >nul 2>&1 if %ERRORLEVEL% NEQ 0 ( echo %%i is not installed, trying to install ... - pip install %%i + + :: Handle special cases for certain packages + if "%%i"=="lxml" ( + scoop install libxml2 + scoop install libxslt + pip install lxml + ) else if "%%i"=="psycopg2" ( + scoop install postgresql python make clang + pip install psycopg2 + ) else if "%%i"=="pillow" ( + scoop install libjpeg-turbo + pip install pillow + ) else ( + pip install %%i + ) ) else ( echo %%i >> "%INSTALLED_FILE%" ) @@ -44,10 +90,13 @@ for /f "usebackq tokens=* delims=" %%i in ("%REQUIREMENTS_FILE%") do ( :: Run userbot cls +echo Running userbot... python3 -m main -echo Configuring Userbot, wait .... if %ERRORLEVEL% NEQ 0 ( echo Failed to run userbot. Exiting script with error. exit /b 1 ) + +echo Userbot configured successfully. endlocal +exit /b 0