From 61ba4e4cb63483afee9c80b9fe30b130740eb7c8 Mon Sep 17 00:00:00 2001 From: "hikari.ftg" Date: Mon, 28 Mar 2022 15:50:22 +0000 Subject: [PATCH] Add GeekTG backward compatibility layer --- hikka/compat/geek.py | 29 +++++++++++++++++++++++++++-- hikka/inline/gallery.py | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/hikka/compat/geek.py b/hikka/compat/geek.py index cfb69c2..08af21c 100644 --- a/hikka/compat/geek.py +++ b/hikka/compat/geek.py @@ -7,10 +7,35 @@ # # 🔒 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 = 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 diff --git a/hikka/inline/gallery.py b/hikka/inline/gallery.py index 0c07865..d61a098 100644 --- a/hikka/inline/gallery.py +++ b/hikka/inline/gallery.py @@ -44,6 +44,7 @@ class Gallery(InlineUnit): ttl: Union[int, bool] = False, on_unload: Union[FunctionType, None] = None, preload: Union[bool, int] = False, + reattempt: bool = False, ) -> Union[bool, str]: """ Processes inline gallery @@ -192,19 +193,35 @@ class Gallery(InlineUnit): else None, ) except Exception: - msg = ( - "🚫 A problem occurred with inline bot " - "while processing query. Check logs for " - "further info." - ) + logger.exception("Error sending inline gallery") del self._galleries[gallery_uid] - if isinstance(message, Message): - await (message.edit if message.out else message.respond)(msg) - else: - await self._client.send_message(message, msg) - return False + if reattempt: + msg = ( + "🚫 A problem occurred with inline bot " + "while processing query. Check logs for " + "further info." + ) + + if isinstance(message, Message): + await (message.edit if message.out else message.respond)(msg) + else: + await self._client.send_message(message, msg) + + 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]["message_id"] = m.id @@ -397,7 +414,7 @@ class Gallery(InlineUnit): id=utils.rand(20), title="Processing inline gallery", 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"]), description=self._get_caption(gallery["uid"]), reply_markup=self._gallery_markup(gallery["btn_call_data"]),