__main__.py 3.5 KB

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