__main__.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """Entry point. Checks for user and starts main script"""
  2. # ©️ Dan Gazizullin, 2021-2023
  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. def deps():
  27. subprocess.run(
  28. [
  29. sys.executable,
  30. "-m",
  31. "pip",
  32. "install",
  33. "--upgrade",
  34. "-q",
  35. "--disable-pip-version-check",
  36. "--no-warn-script-location",
  37. "-r",
  38. "requirements.txt",
  39. ],
  40. check=True,
  41. )
  42. if sys.version_info < (3, 8, 0):
  43. print("🚫 Error: you must use at least Python version 3.8.0")
  44. elif __package__ != "hikka": # In case they did python __main__.py
  45. print("🚫 Error: you cannot run this as a script; you must execute as a package")
  46. else:
  47. try:
  48. import hikkatl
  49. except Exception:
  50. pass
  51. else:
  52. try:
  53. import hikkatl # noqa: F811
  54. if tuple(map(int, hikkatl.__version__.split("."))) < (2, 0, 4):
  55. raise ImportError
  56. import hikkapyro
  57. if tuple(map(int, hikkapyro.__version__.split("."))) < (2, 0, 103):
  58. raise ImportError
  59. except ImportError:
  60. print("🔄 Installing dependencies...")
  61. deps()
  62. restart()
  63. try:
  64. from . import log
  65. log.init()
  66. from . import main
  67. except ImportError as e:
  68. print(f"{str(e)}\n🔄 Attempting dependencies installation... Just wait ⏱")
  69. deps()
  70. restart()
  71. if "HIKKA_DO_NOT_RESTART" in os.environ:
  72. del os.environ["HIKKA_DO_NOT_RESTART"]
  73. main.hikka.main() # Execute main function