mirror of https://github.com/coddrago/Heroku
Add GeekTG backward compatibility layer
parent
c0ba0951d1
commit
61ba4e4cb6
|
@ -7,10 +7,35 @@
|
||||||
#
|
#
|
||||||
# 🔒 Licensed under the GNU GPLv3
|
# 🔒 Licensed under the GNU GPLv3
|
||||||
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
|
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def compat(code: str) -> str:
|
def compat(code: str) -> str:
|
||||||
"""Reformats modules, built for GeekTG to work with Hikka"""
|
"""Reformats modules, built for GeekTG to work with Hikka"""
|
||||||
code = code.replace("GeekInlineQuery", "InlineQuery")
|
code = "\n".join(
|
||||||
|
[
|
||||||
|
re.sub(
|
||||||
|
r"^( *)from \.\.inline import (.+)$",
|
||||||
|
r"\1from ..inline.types import \2",
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
for line in code.splitlines()
|
||||||
|
]
|
||||||
|
)
|
||||||
return code
|
return code
|
||||||
|
|
|
@ -44,6 +44,7 @@ class Gallery(InlineUnit):
|
||||||
ttl: Union[int, bool] = False,
|
ttl: Union[int, bool] = False,
|
||||||
on_unload: Union[FunctionType, None] = None,
|
on_unload: Union[FunctionType, None] = None,
|
||||||
preload: Union[bool, int] = False,
|
preload: Union[bool, int] = False,
|
||||||
|
reattempt: bool = False,
|
||||||
) -> Union[bool, str]:
|
) -> Union[bool, str]:
|
||||||
"""
|
"""
|
||||||
Processes inline gallery
|
Processes inline gallery
|
||||||
|
@ -192,13 +193,17 @@ class Gallery(InlineUnit):
|
||||||
else None,
|
else None,
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
logger.exception("Error sending inline gallery")
|
||||||
|
|
||||||
|
del self._galleries[gallery_uid]
|
||||||
|
|
||||||
|
if reattempt:
|
||||||
msg = (
|
msg = (
|
||||||
"🚫 <b>A problem occurred with inline bot "
|
"🚫 <b>A problem occurred with inline bot "
|
||||||
"while processing query. Check logs for "
|
"while processing query. Check logs for "
|
||||||
"further info.</b>"
|
"further info.</b>"
|
||||||
)
|
)
|
||||||
|
|
||||||
del self._galleries[gallery_uid]
|
|
||||||
if isinstance(message, Message):
|
if isinstance(message, Message):
|
||||||
await (message.edit if message.out else message.respond)(msg)
|
await (message.edit if message.out else message.respond)(msg)
|
||||||
else:
|
else:
|
||||||
|
@ -206,6 +211,18 @@ class Gallery(InlineUnit):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
return await self.gallery(
|
||||||
|
caption,
|
||||||
|
message,
|
||||||
|
next_handler,
|
||||||
|
force_me,
|
||||||
|
always_allow,
|
||||||
|
ttl,
|
||||||
|
on_unload,
|
||||||
|
preload,
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
|
||||||
self._galleries[gallery_uid]["chat"] = utils.get_chat_id(m)
|
self._galleries[gallery_uid]["chat"] = utils.get_chat_id(m)
|
||||||
self._galleries[gallery_uid]["message_id"] = m.id
|
self._galleries[gallery_uid]["message_id"] = m.id
|
||||||
|
|
||||||
|
@ -397,7 +414,7 @@ class Gallery(InlineUnit):
|
||||||
id=utils.rand(20),
|
id=utils.rand(20),
|
||||||
title="Processing inline gallery",
|
title="Processing inline gallery",
|
||||||
photo_url=gallery["photo_url"],
|
photo_url=gallery["photo_url"],
|
||||||
thumb_url=gallery["photo_url"],
|
thumb_url="https://img.icons8.com/fluency/344/loading.png",
|
||||||
caption=self._get_caption(gallery["uid"]),
|
caption=self._get_caption(gallery["uid"]),
|
||||||
description=self._get_caption(gallery["uid"]),
|
description=self._get_caption(gallery["uid"]),
|
||||||
reply_markup=self._gallery_markup(gallery["btn_call_data"]),
|
reply_markup=self._gallery_markup(gallery["btn_call_data"]),
|
||||||
|
|
Loading…
Reference in New Issue