Add telethon check in order to avoid errors due to classic telethon installation

pull/1/head
Hikari 2022-04-13 18:42:33 +00:00
parent 21d9133d30
commit 4b730c40d2
No known key found for this signature in database
GPG Key ID: 5FA52ACBB2AD964D
1 changed files with 46 additions and 12 deletions

View File

@ -36,11 +36,11 @@ if (
and "--root" not in " ".join(sys.argv) and "--root" not in " ".join(sys.argv)
and "OKTETO" not in os.environ and "OKTETO" not in os.environ
): ):
print("!" * 30) print("🚫" * 30)
print("NEVER EVER RUN USERBOT FROM ROOT") print("NEVER EVER RUN USERBOT FROM ROOT")
print("THIS IS THE THREAD FOR NOT ONLY YOUR DATA, ") print("THIS IS THE THREAD FOR NOT ONLY YOUR DATA, ")
print("BUT ALSO FOR YOUR DEVICE ITSELF!") print("BUT ALSO FOR YOUR DEVICE ITSELF!")
print("!" * 30) print("🚫" * 30)
print() print()
print("TYPE force_insecure TO IGNORE THIS WARNING") print("TYPE force_insecure TO IGNORE THIS WARNING")
print("TYPE ANYTHING ELSE TO EXIT:") print("TYPE ANYTHING ELSE TO EXIT:")
@ -50,9 +50,9 @@ if (
def deps(e): def deps(e):
print( print(
"Error: you have not installed all dependencies correctly.\n" "🚫 Error: you have not installed all dependencies correctly.\n"
f"{str(e)}\n" f"{str(e)}\n"
"Attempting dependencies installation... Just wait." "🔄 Attempting dependencies installation... Just wait ⏱"
) )
subprocess.run( subprocess.run(
@ -72,12 +72,46 @@ def deps(e):
if sys.version_info < (3, 8, 0): if sys.version_info < (3, 8, 0):
print("Error: you must use at least Python version 3.8.0") # pragma: no cover print("🚫 Error: you must use at least Python version 3.8.0")
elif __package__ != "hikka": # In case they did python __main__.py elif __package__ != "hikka": # In case they did python __main__.py
print( print("🚫 Error: you cannot run this as a script; you must execute as a package") # fmt: skip
"Error: you cannot run this as a script; you must execute as a package"
) # pragma: no cover
else: else:
try:
import telethon # noqa: F401
except Exception:
pass
else:
try:
from telethon.tl.functions.messages import SendReactionRequest # noqa: F401
except ImportError:
print("⚠️ Warning: Default telethon is used as main one. This can cause errors and enables DAR. Attempting to reinstall telethon-mod...") # fmt: skip
subprocess.run(
[
sys.executable,
"-m",
"pip",
"uninstall",
"-y",
"telethon",
]
)
subprocess.run(
[
sys.executable,
"-m",
"pip",
"install",
"-U",
"-q",
"--disable-pip-version-check",
"--no-warn-script-location",
"telethon-mod",
]
)
print("🔄 Restart this script for changes to take effect!")
try: try:
from . import log from . import log
@ -90,9 +124,9 @@ else:
log.init() log.init()
except ModuleNotFoundError as e2: except ModuleNotFoundError as e2:
print( print(
"Error while installing dependencies. Please, do this manually!\n" "🚫 Error while installing dependencies. Please, do this manually!\n"
f"{str(e2)}\n" f"{str(e2)}\n"
"pip3 install -r requirements.txt" "Run: pip3 install -r requirements.txt"
) )
sys.exit(1) sys.exit(1)
@ -105,9 +139,9 @@ else:
from . import main from . import main
except ModuleNotFoundError as e2: except ModuleNotFoundError as e2:
print( print(
"Error while installing dependencies. Please, do this manually!\n" "🚫 Error while installing dependencies. Please, do this manually!\n"
f"{str(e2)}\n" f"{str(e2)}\n"
"pip3 install -r requirements.txt" "Run: pip3 install -r requirements.txt"
) )
sys.exit(1) sys.exit(1)