Heroku/hikka/compat/geek.py

47 lines
1.8 KiB
Python

# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀ ▄▀█ ▀█▀ ▄▀█ █▀▄▀█ ▄▀█
# █▀█ █ █ █ █▀█ █▀▄ █ ▄ █▀█ █ █▀█ █ ▀ █ █▀█
#
# © Copyright 2022
#
# https://t.me/hikariatama
#
# 🔒 Licensed under the GNU GPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
import re
def compat(code: str) -> str:
"""Reformats modules, built for GeekTG to work with Hikka"""
code = "\n".join(
[
re.sub(
r"^( *)from \.\.inline import (.+)$",
r"\1from ..inline.types import \2",
re.sub(
r"^( *)from \.\.inline import rand[^,]*$",
"\1from ..utils import rand",
re.sub(
r"^( *)from \.\.inline import rand, ?(.+)$",
r"\1from ..inline.types import \2\n\1from ..utils import rand",
re.sub(
r"^( *)from \.\.inline import (.+), ?rand[^,]*$",
r"\1from ..inline.types import \2\n\1from ..utils import rand",
re.sub(
r"^( *)from \.\.inline import (.+), ?rand, ?(.+)$",
r"\1from ..inline.types import \2, \3\n\1from ..utils import rand",
line.replace("GeekInlineQuery", "InlineQuery"),
flags=re.M,
),
flags=re.M,
),
flags=re.M,
),
flags=re.M,
),
flags=re.M,
)
for line in code.splitlines()
]
)
return code