geek.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # ©️ Dan Gazizullin, 2021-2023
  2. # This file is a part of Hikka Userbot
  3. # 🌐 https://github.com/hikariatama/Hikka
  4. # You can redistribute it and/or modify it under the terms of the GNU AGPLv3
  5. # 🔑 https://www.gnu.org/licenses/agpl-3.0.html
  6. import re
  7. def compat(code: str) -> str:
  8. """
  9. Reformats modules, built for GeekTG to work with Hikka
  10. :param code: code to reformat
  11. :return: reformatted code
  12. """
  13. return "\n".join(
  14. [
  15. re.sub(
  16. r"^( *)from \.\.inline import (.+)$",
  17. r"\1from ..inline.types import \2",
  18. re.sub(
  19. r"^( *)from \.\.inline import rand[^,]*$",
  20. "\1from ..utils import rand",
  21. re.sub(
  22. r"^( *)from \.\.inline import rand, ?(.+)$",
  23. r"\1from ..inline.types import \2\n\1from ..utils import rand",
  24. re.sub(
  25. r"^( *)from \.\.inline import (.+), ?rand[^,]*$",
  26. r"\1from ..inline.types import \2\n\1from ..utils import"
  27. r" rand",
  28. re.sub(
  29. r"^( *)from \.\.inline import (.+), ?rand, ?(.+)$",
  30. r"\1from ..inline.types import \2, \3\n\1from ..utils"
  31. r" import rand",
  32. line.replace("GeekInlineQuery", "InlineQuery").replace(
  33. "self.inline._bot",
  34. "self.inline.bot",
  35. ),
  36. flags=re.M,
  37. ),
  38. flags=re.M,
  39. ),
  40. flags=re.M,
  41. ),
  42. flags=re.M,
  43. ),
  44. flags=re.M,
  45. )
  46. for line in code.splitlines()
  47. ]
  48. )