geek.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. """Reformats modules, built for GeekTG to work with Hikka"""
  11. return "\n".join(
  12. [
  13. re.sub(
  14. r"^( *)from \.\.inline import (.+)$",
  15. r"\1from ..inline.types import \2",
  16. re.sub(
  17. r"^( *)from \.\.inline import rand[^,]*$",
  18. "\1from ..utils import rand",
  19. re.sub(
  20. r"^( *)from \.\.inline import rand, ?(.+)$",
  21. r"\1from ..inline.types import \2\n\1from ..utils import rand",
  22. re.sub(
  23. r"^( *)from \.\.inline import (.+), ?rand[^,]*$",
  24. r"\1from ..inline.types import \2\n\1from ..utils import"
  25. r" rand",
  26. re.sub(
  27. r"^( *)from \.\.inline import (.+), ?rand, ?(.+)$",
  28. r"\1from ..inline.types import \2, \3\n\1from ..utils"
  29. r" import rand",
  30. line.replace("GeekInlineQuery", "InlineQuery").replace(
  31. "self.inline._bot", "self.inline.bot"
  32. ),
  33. flags=re.M,
  34. ),
  35. flags=re.M,
  36. ),
  37. flags=re.M,
  38. ),
  39. flags=re.M,
  40. ),
  41. flags=re.M,
  42. )
  43. for line in code.splitlines()
  44. ]
  45. )