From 0b3a19fe90e4469995e6a247c4e4fde6ff5b7b9f Mon Sep 17 00:00:00 2001 From: "hikari.ftg" Date: Thu, 24 Mar 2022 18:22:20 +0000 Subject: [PATCH] Fix initial setup (pass auth) --- hikka/loader.py | 7 ++----- hikka/main.py | 3 +-- hikka/web/root.py | 37 +++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/hikka/loader.py b/hikka/loader.py index dcca87f..098d2c7 100755 --- a/hikka/loader.py +++ b/hikka/loader.py @@ -215,7 +215,7 @@ def get_callback_handlers(mod): class Modules: """Stores all registered modules""" - def __init__(self, use_inline=True): + def __init__(self): self.commands = {} self.aliases = {} self.modules = [] # skipcq: PTC-W0052 @@ -225,7 +225,6 @@ class Modules: self.client = None self._initial_registration = True self.added_modules = None - self.use_inline = use_inline def register_all(self, mods=None): """Load all modules in the module directory""" @@ -420,9 +419,7 @@ class Modules: # can access its `init_complete` inline_manager = inline.InlineManager(client, db, self) - # Register only if it is not disabled - if self.use_inline: - await inline_manager._register_manager() + await inline_manager._register_manager() # We save it to `Modules` attribute, so not to re-init # it everytime module is loaded. Then we can just diff --git a/hikka/main.py b/hikka/main.py index b313b6f..b7014d1 100755 --- a/hikka/main.py +++ b/hikka/main.py @@ -143,7 +143,6 @@ def parse_arguments(): parser.add_argument("--phone", "-p", action="append") parser.add_argument("--token", "-t", action="append", dest="tokens") parser.add_argument("--no-nickname", "-nn", dest="no_nickname", action="store_true") - parser.add_argument("--no-inline", dest="use_inline", action="store_false") parser.add_argument("--hosting", "-lh", dest="hosting", action="store_true") parser.add_argument("--web-only", dest="web_only", action="store_true") parser.add_argument("--no-web", dest="web", action="store_false") @@ -510,7 +509,7 @@ class Hikka: async def _handle_setup(self, client, db) -> None: await db.init() - modules = loader.Modules(self.arguments.use_inline) + modules = loader.Modules() babelfish = Translator([], [], self.arguments.data_root) await babelfish.init(client) diff --git a/hikka/web/root.py b/hikka/web/root.py index e751e05..637f03e 100644 --- a/hikka/web/root.py +++ b/hikka/web/root.py @@ -206,18 +206,29 @@ class Web: ops = [] for user in self.client_data.values(): - bot = user[0].inline.bot - msg = await bot.send_message( - (await user[1].get_me()).id, - ( - "👩‍🎤🔐 Click button below to confirm web application ops\n\n" - "If you did not request any codes, simply ignore this message" - ), - parse_mode="HTML", - disable_web_page_preview=True, - reply_markup=markup, - ) - ops += [bot.delete_message(msg.chat.id, msg.message_id)] + try: + bot = user[0].inline.bot + msg = await bot.send_message( + (await user[1].get_me()).id, + ( + "👩‍🎤🔐 Click button below to confirm web application ops\n\n" + "If you did not request any codes, simply ignore this message" + ), + parse_mode="HTML", + disable_web_page_preview=True, + reply_markup=markup, + ) + ops += [bot.delete_message(msg.chat.id, msg.message_id)] + except Exception: + pass + + session = f"hikka_{rand(16)}" + + if not ops: + # If no auth message was sent, just leave it empty + # probably, request was a bug and user doesn't have + # inline bot or did not authorize any sessions + return web.Response(body=session) if not await main.hikka.wait_for_web_auth(token): return web.Response(body="TIMEOUT") @@ -225,8 +236,6 @@ class Web: for op in ops: await op - session = f"hikka_{rand(16)}" - self._sessions += [session] return web.Response(body=session)