geek.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
  2. # █▀█ █ █ █ █▀█ █▀▄ █
  3. # © Copyright 2022
  4. # https://t.me/hikariatama
  5. #
  6. # 🔒 Licensed under the GNU AGPLv3
  7. # 🌐 https://www.gnu.org/licenses/agpl-3.0.html
  8. import re
  9. def compat(code: str) -> str:
  10. """
  11. Reformats modules, built for GeekTG to work with Hikka
  12. :param code: code to reformat
  13. :return: reformatted code
  14. """
  15. return "\n".join(
  16. [
  17. re.sub(
  18. r"^( *)from \.\.inline import (.+)$",
  19. r"\1from ..inline.types import \2",
  20. re.sub(
  21. r"^( *)from \.\.inline import rand[^,]*$",
  22. "\1from ..utils import rand",
  23. re.sub(
  24. r"^( *)from \.\.inline import rand, ?(.+)$",
  25. r"\1from ..inline.types import \2\n\1from ..utils import rand",
  26. re.sub(
  27. r"^( *)from \.\.inline import (.+), ?rand[^,]*$",
  28. r"\1from ..inline.types import \2\n\1from ..utils import"
  29. r" rand",
  30. re.sub(
  31. r"^( *)from \.\.inline import (.+), ?rand, ?(.+)$",
  32. r"\1from ..inline.types import \2, \3\n\1from ..utils"
  33. r" import rand",
  34. line.replace("GeekInlineQuery", "InlineQuery").replace(
  35. "self.inline._bot",
  36. "self.inline.bot",
  37. ),
  38. flags=re.M,
  39. ),
  40. flags=re.M,
  41. ),
  42. flags=re.M,
  43. ),
  44. flags=re.M,
  45. ),
  46. flags=re.M,
  47. )
  48. for line in code.splitlines()
  49. ]
  50. )