__main__.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. """Entry point. Checks for user and starts main script"""
  2. # ©️ Dan Gazizullin, 2021-2022
  3. # This file is a part of Hikka Userbot
  4. # 🌐 https://github.com/hikariatama/Hikka
  5. # You can redistribute it and/or modify it under the terms of the GNU AGPLv3
  6. # 🔑 https://www.gnu.org/licenses/agpl-3.0.html
  7. import getpass
  8. import os
  9. import subprocess
  10. import sys
  11. from ._internal import restart
  12. if (
  13. getpass.getuser() == "root"
  14. and "--root" not in " ".join(sys.argv)
  15. and all(trigger not in os.environ for trigger in {"DOCKER", "GOORM"})
  16. ):
  17. print("🚫" * 15)
  18. print("You attempted to run Hikka on behalf of root user")
  19. print("Please, create a new user and restart script")
  20. print("If this action was intentional, pass --root argument instead")
  21. print("🚫" * 15)
  22. print()
  23. print("Type force_insecure to ignore this warning")
  24. if input("> ").lower() != "force_insecure":
  25. sys.exit(1)
  26. if sys.version_info < (3, 8, 0):
  27. print("🚫 Error: you must use at least Python version 3.8.0")
  28. elif __package__ != "hikka": # In case they did python __main__.py
  29. print("🚫 Error: you cannot run this as a script; you must execute as a package")
  30. else:
  31. try:
  32. # If telethon is not installed, just skip to a part of main startup
  33. # then main.py will through an error and re-install all deps
  34. import telethon
  35. except Exception:
  36. pass
  37. else:
  38. try:
  39. import telethon
  40. if tuple(map(int, telethon.__version__.split("."))) < (1, 24, 14):
  41. raise ImportError
  42. except ImportError:
  43. print("🔄 Installing Hikka-TL...")
  44. subprocess.run(
  45. [
  46. sys.executable,
  47. "-m",
  48. "pip",
  49. "install",
  50. "--force-reinstall",
  51. "-q",
  52. "--disable-pip-version-check",
  53. "--no-warn-script-location",
  54. "hikka-tl",
  55. ],
  56. check=True,
  57. )
  58. restart()
  59. try:
  60. import pyrogram
  61. if tuple(map(int, pyrogram.__version__.split("."))) < (2, 0, 66):
  62. raise ImportError
  63. except ImportError:
  64. print("🔄 Installing Hikka-Pyro...")
  65. subprocess.run(
  66. [
  67. sys.executable,
  68. "-m",
  69. "pip",
  70. "install",
  71. "--force-reinstall",
  72. "-q",
  73. "--disable-pip-version-check",
  74. "--no-warn-script-location",
  75. "hikka-pyro",
  76. ],
  77. check=True,
  78. )
  79. restart()
  80. try:
  81. from . import log
  82. log.init()
  83. from . import main
  84. except ImportError as e:
  85. print(f"{str(e)}\n🔄 Attempting dependencies installation... Just wait ⏱")
  86. subprocess.run(
  87. [
  88. sys.executable,
  89. "-m",
  90. "pip",
  91. "install",
  92. "--upgrade",
  93. "-q",
  94. "--disable-pip-version-check",
  95. "--no-warn-script-location",
  96. "-r",
  97. "requirements.txt",
  98. ],
  99. check=True,
  100. )
  101. restart()
  102. if __name__ == "__main__":
  103. if "HIKKA_DO_NOT_RESTART" in os.environ:
  104. del os.environ["HIKKA_DO_NOT_RESTART"]
  105. main.hikka.main() # Execute main function